Enum value not serialized as number
Created by: loewekordel
platform: esp8266 ide: vscode + pio ArduinoJson version: 6.14.1 Espressif 8266 version: 2.3.2 Arduino core version: 2.6.3
For error logging purposes, I created an enum and tried to serialize it, but the the enum number is not serialized. Instead true or false are written to the serialized buffer?
enum:
typedef enum errorMap_e {
ERRC_OK = 0, // No Error
ERRC_1 = 1, // ERROR 1
ERRC_2 = 2, // ERROR 2
ERRC_3 = 3, // ERROR 3
ERRC_4 = 4, // ERROR 4
ERRC_5 = 5, // ERROR 5
ERRC_6 = 6, // ERROR 6
ERRC_7 = 7, // ERROR 7
ERRC_8 = 8, // ERROR 8
ERRC_9 = 9, // ERROR 9
ERRC_10 = 10, // ERROR 10
ERRC_100 = 100 // ERROR 100
} errorMap_t;
ArduinoJson definitions:
StaticJsonDocument<150> jsonBuffer;
DeserializationError err;
char sendbuffer[256];
Serialization:
Serial.print("time: ");
Serial.print(errList[i].time);
Serial.print(" err: ");
Serial.println(errList[i].err);
// create json
jsonBuffer["cmd"] = "log";
jsonBuffer["time"] = errList[i].time;
jsonBuffer["err"] = errList[i].err;
// Send data only, if clients are connected
if (webSocket.connectedClients()) {
size_t len = serializeJson(jsonBuffer, sendbuffer);
if (len == 0) {
Serial.println("Failed to serialize json");
}
DEBUGMSG(sendbuffer);
// send data
Serial.printf("Client updated %d - log\n", num);
webSocket.sendTXT(num, sendbuffer, len);
}
Serial output (sendBuffer): {"cmd":"log","time":1582671207,"err":true} I hope the explanation is good enough.
I appreciate your effort and would be very thankful for a hint.