MQTTデバイスのサブスクライブとパブリッシュ双方のデータを全てJSONフォーマットに統一。
フロントエンドであるHome Assistantの照明インターフェイスもJSONフォーマットに対応しているため、調光機能付LED照明の調光レベルとON/OFFコマンドもJSONフォーマットで統一した。
ex)
char* json[50] = "{"brightness":50, "state":"ON"}"
Example
Create an object and serialize it
// allocate the memory for the document
const size_t CAPACITY = JSON_OBJECT_SIZE(1);
StaticJsonDocument<CAPACITY> doc;
// create an object
JsonObject object = doc.to<JsonObject>();
object["hello"] = "world";
// serialize the object and send the result to Serial
serializeJson(doc, Serial);
Deserialize a object
// allocate the memory for the document
const size_t CAPACITY = JSON_OBJECT_SIZE(1);
StaticJsonDocument<CAPACITY> doc;
// deserialize the object
char json[] = "{\"hello\":\"world\"}";
deserializeJson(doc, json);
// extract the data
JsonObject object = doc.as<JsonObject>();
const char* world = object["hello"];