Skip to content

Commit

Permalink
Check Crypto on device, more readme, closes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
britiger committed Jan 22, 2020
1 parent 029962b commit b103419
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
10 changes: 10 additions & 0 deletions CriticalMapsAPIBarrel.mc
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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.
- 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)
2 changes: 1 addition & 1 deletion manifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!-- This is a generated file. It is highly recommended that you DO NOT edit this file. --><iq:manifest xmlns:iq="http://www.garmin.com/xml/connectiq" version="3">
<iq:barrel id="3f84178e-ba97-4605-b316-04eacfcf94e4" minSdkVersion="2.4.0" module="CriticalMapsAPIBarrel" version="0.1.0">
<iq:barrel id="3f84178eba974605b31604eacfcf94e4" minSdkVersion="2.4.0" module="CriticalMapsAPIBarrel" version="0.2.0">
<iq:products>
<iq:product id="edge1030"/>
<iq:product id="edge1030bontrager"/>
Expand Down

0 comments on commit b103419

Please sign in to comment.