From 029962becc9b42e8bc8262e0b59cc35321c2a00e Mon Sep 17 00:00:00 2001 From: Christopher Lorenz Date: Fri, 10 Jan 2020 22:33:39 +0100 Subject: [PATCH] Add date and SHA1 for daily new deviceid --- CriticalMapsAPIBarrel.mc | 23 ++++++++++++++++++++++- README.md | 3 ++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/CriticalMapsAPIBarrel.mc b/CriticalMapsAPIBarrel.mc index 6e1da99..63f1f40 100644 --- a/CriticalMapsAPIBarrel.mc +++ b/CriticalMapsAPIBarrel.mc @@ -2,9 +2,11 @@ using Toybox.Application; using Toybox.System; using Toybox.Position; using Toybox.Time; +using Toybox.Cryptography; using Toybox.Communications; using Toybox.Math; using Toybox.Lang; +using Toybox.StringUtil; (:background) module CriticalMapsAPIBarrel { @@ -18,8 +20,27 @@ module CriticalMapsAPIBarrel { var nearestCM = 0; var countCM10 = 0; var chatText = ""; - + var deviceIdHash = ""; + function getDeviceId() { + if (!deviceIdHash.equals("")) { + return deviceIdHash; + } + var hashValue = new Cryptography.Hash({:algorithm => Cryptography.HASH_MD5}); + var deviceId = getDeviceIdRaw() + Time.today().value(); + var byteA = StringUtil.convertEncodedString(deviceId, { + :fromRepresentation => StringUtil.REPRESENTATION_STRING_PLAIN_TEXT, + :toRepresentation => StringUtil.REPRESENTATION_BYTE_ARRAY }); + + hashValue.update(byteA); + deviceIdHash = StringUtil.convertEncodedString(hashValue.digest(), { + :fromRepresentation => StringUtil.REPRESENTATION_BYTE_ARRAY, + :toRepresentation => StringUtil.REPRESENTATION_STRING_HEX }); + return deviceIdHash; + } + + function getDeviceIdRaw() { + // Get non hashed deviceId var propDeviceId = ""; try { propDeviceId = Application.Properties.getValue("deviceId"); diff --git a/README.md b/README.md index 0ad6be0..cac80a4 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,5 @@ Monkey C Barrel for CriticalMaps API ==================================== -TODO: Description \ No newline at end of file +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