Last active
March 30, 2017 03:48
-
-
Save efatsi/879839d7d537552d5356c176f02505a2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String json = String("{\"count\":" + String(count) + "}"); | |
int stringLength; | |
if (count < 10) { | |
stringLength = 13; | |
} else if (count < 100) { | |
stringLength = 14; | |
} else if (count < 1000) { | |
stringLength = 15; | |
} else { | |
stringLength = 16; | |
} | |
char input[stringLength]; | |
json.toCharArray(input, stringLength); | |
int inputLen = sizeof(input); | |
int encodedLen = base64_enc_len(inputLen); | |
char encoded[encodedLen]; | |
base64_encode(encoded, input, inputLen); | |
String encodedString = String(encoded); | |
if (count < 10) { | |
String morphed = encodedString.substring(0, encodedString.length() - 5) + String("="); | |
Particle.publish("magnetPass", morphed); | |
} else if (count < 100) { | |
String morphed = encodedString.substring(0, encodedString.length() - 4); | |
Particle.publish("magnetPass", morphed); | |
} else if (count < 1000) { | |
String morphed = encodedString.substring(0, encodedString.length() - 2) + String("=="); | |
Particle.publish("magnetPass", morphed); | |
} else { | |
String morphed = encodedString.substring(0, encodedString.length() - 5) + String("="); | |
Particle.publish("magnetPass", morphed); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment