properly escape values in json payload

This commit is contained in:
Peli de Halleux 2016-08-10 09:28:22 -07:00
parent a6b4c9645a
commit ffd4d96539

View File

@ -114,19 +114,19 @@ namespace radio {
uBit.serial.send("{"); uBit.serial.send("{");
if (length >= 4) { if (length >= 4) {
memcpy(&value, bytes, 4); memcpy(&value, bytes, 4);
uBit.serial.send("v:"); uBit.serial.send(value); uBit.serial.send("\"v\":"); uBit.serial.send(value);
if(length >= 8) { if(length >= 8) {
memcpy(&value, bytes + 4, 4); memcpy(&value, bytes + 4, 4);
uBit.serial.send(",t:"); uBit.serial.send(value); uBit.serial.send(",\"t\":"); uBit.serial.send(value);
if (length >= 12) { if (length >= 12) {
memcpy(&value, bytes + 8, 4); memcpy(&value, bytes + 8, 4);
uBit.serial.send(",s:"); uBit.serial.send(value); uBit.serial.send(",\"s\":"); uBit.serial.send(value);
if (length >= 13) { if (length >= 13) {
char name[MAX_FIELD_NAME_LENGTH+1]; char name[MAX_FIELD_NAME_LENGTH+1];
uint8_t len = min(MAX_FIELD_NAME_LENGTH, bytes[12]); uint8_t len = min(MAX_FIELD_NAME_LENGTH, bytes[12]);
memcpy(name, bytes + 13, len); memcpy(name, bytes + 13, len);
name[len] = 0; name[len] = 0;
uBit.serial.send(",n:\""); uBit.serial.send(name); uBit.serial.send("\""); uBit.serial.send(",\"n\":\""); uBit.serial.send(name); uBit.serial.send("\"");
} }
} }
} }