From b103419def50e746ac6a942c173821260e2fb58d Mon Sep 17 00:00:00 2001 From: Christopher Lorenz Date: Wed, 22 Jan 2020 20:55:36 +0100 Subject: [PATCH] Check Crypto on device, more readme, closes #2 --- CriticalMapsAPIBarrel.mc | 10 ++++++++++ Makefile | 1 + README.md | 11 ++++++++++- manifest.xml | 2 +- 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/CriticalMapsAPIBarrel.mc b/CriticalMapsAPIBarrel.mc index 63f1f40..b56c5a1 100644 --- a/CriticalMapsAPIBarrel.mc +++ b/CriticalMapsAPIBarrel.mc @@ -26,6 +26,16 @@ module CriticalMapsAPIBarrel { if (!deviceIdHash.equals("")) { return deviceIdHash; } + if(Toybox has :Cryptography) { + System.println("Device have Cryptography."); + } else { + // Compatibilty mode for old devices + // Use same deviceId every day + System.println("Device have no Cryptography! Use DeviceId only."); + deviceIdHash = getDeviceIdRaw(); + return deviceIdHash; + } + var hashValue = new Cryptography.Hash({:algorithm => Cryptography.HASH_MD5}); var deviceId = getDeviceIdRaw() + Time.today().value(); var byteA = StringUtil.convertEncodedString(deviceId, { diff --git a/Makefile b/Makefile index 4da2e8b..06662a1 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ appName = `grep module manifest.xml | sed 's/.*module="\([^"]*\).*/\1/'` JAVA_OPTIONS = JDK_JAVA_OPTIONS="--add-modules=java.xml.bind" build: + rm -f bin/* $(SDK_HOME)/bin/barrelbuild \ --jungle-files ./monkey.jungle \ --output bin/$(appName).barrel \ diff --git a/README.md b/README.md index cac80a4..c65cf26 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,14 @@ Monkey C Barrel for CriticalMaps API ==================================== +This barrel give you some function to communicate with the API [CriticalMaps](https://www.criticalmaps.net/) and is build for Garmin Edge devices. After sending your position + +If you use the barrel as a background service for a DataField you will only be able to send a position every 5 minutes. This limitation is for saving battery of the devices. If you use this barrel for a widget you don't have this limitation. The suggested interval for sending the position is about 30 seconds. When using more than one DataField or Widget on same device at same time, pay attention that every application have an own unique id and you will get a different hash and you will get 2 positions on the map. See the implementations how to reuse one of unique ids for the other application using the Properties which you can change in the Connect App if you app installed via the official store (non-public beta should be also work). + +The following applications using the barrel: + - DataField: [PauseTimer](https://github.com/britiger/PauseTimer-connectiq-cm) with background service, you don't see anything of CriticalMaps + - Widget: [CriticalMaps Widget](https://github.com/britiger/criticalmaps-garmin-widget) show next + Restrictions: - - Due to limitations of memory within the devices, you'll get a `responseCode` of `-402` if there are more than 100 positions. In this case your position was send correctly to CriticalMaps. \ No newline at end of file + - Due to limitations of memory within the devices, you'll get a `responseCode` of `-402` if there are more than 100 positions. In this case your position was send correctly to CriticalMaps. + - If you use this Barrel with an device only support SDK version older than 3.0.0 you always have the same hash (deviceId) every day. E.g. Edge 1000 (supports only up to 2.4.0) \ No newline at end of file diff --git a/manifest.xml b/manifest.xml index 62d0c2d..dd2711e 100644 --- a/manifest.xml +++ b/manifest.xml @@ -1,5 +1,5 @@ - +