Skip to content

Commit

Permalink
Add date and SHA1 for daily new deviceid
Browse files Browse the repository at this point in the history
  • Loading branch information
britiger committed Jan 10, 2020
1 parent 9e8ea17 commit 029962b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
23 changes: 22 additions & 1 deletion CriticalMapsAPIBarrel.mc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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");
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Monkey C Barrel for CriticalMaps API
====================================

TODO: Description
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.

0 comments on commit 029962b

Please sign in to comment.