Skip to content

Instantly share code, notes, and snippets.

@gguuss
Last active July 10, 2018 23:57
Show Gist options
  • Save gguuss/aceaf380a7f3045570bcefb2248373cc to your computer and use it in GitHub Desktop.
Save gguuss/aceaf380a7f3045570bcefb2248373cc to your computer and use it in GitHub Desktop.
int getHexConfig () {
WiFiClientSecure client;
doRequest(&client, true, "");
int toReturn = -1;
while (client.available()) {
String line = client.readStringUntil('\n');
Serial.println(line);
// NOTE: This method and the following are character length sensitive
if (line.indexOf("version\": \"") > 0) {
int ver = line.substring(line.indexOf(": \"") + 3, line.lastIndexOf("\"")).toInt();
Serial.println(String(ver));
Serial.println(String(lastSeen));
if (ver != lastSeen) { // Careful, this triggers long running operations
configChange = true;
lastSeen = ver;
}
}
if (line.indexOf("binaryData") > 0) {
String val =
line.substring(line.indexOf(": ") + 3,line.indexOf("\","));
// TODO: Enum
if (val == "MA==") {
toReturn = 0; // SCAN
} else if (val == "MQ==") {
toReturn = 1; // Forward
} else if (val == "Mg==") {
toReturn = 2; // Right
} else if (val == "Mw==") {
toReturn = 3; // Back
} else if (val == "NA==") {
toReturn = 4; // Left
} else if (val == "NQ==") {
toReturn = 5; // Seek
} else {
Serial.println("Unknown command: " + val);
toReturn -1;
}
}
}
client.stop();
return toReturn;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment