Sming framework is a C++ framework for developing applications for ESP8266 and ESP32 microcontrollers. To encode and decode JSON data in Sming, you can use the JsonObjectStream library that is included in the framework.

 

Here's an example of encoding JSON data in Sming:

 

#include <JsonObjectStream.h>
#include <Wire.h>

void setup() {
  Serial.begin(115200);
  DynamicJsonDocument doc(1024);
  JsonObject data = doc.to<JsonObject>();
  data["device"] = "ESP8266";
  data["value"] = 42;
  String json;
  serializeJson(doc, json);
  Serial.println(json);
}

void loop() {
}

 

And here's an example of decoding JSON data in Sming:

#include <JsonObjectStream.h>
#include <Wire.h>

void setup() {
  Serial.begin(115200);
  String json = "{\"device\":\"ESP8266\",\"value\":42}";
  DynamicJsonDocument doc(1024);
  DeserializationError error = deserializeJson(doc, json);
  if (error) {
    Serial.println("Deserialization failed: " + error.c_str());
    return;
  }
  JsonObject data = doc.as<JsonObject>();
  Serial.println("device: " + data["device"].as<String>());
  Serial.println("value: " + data["value"].as<int>());
}

void loop() {
}

'Embeded' 카테고리의 다른 글

ESP8266 websocket (HTML 내장)  (0) 2023.10.28
Websocket with JSON  (0) 2023.10.26
Unix Timestamp 변환하기  (0) 2023.10.18
Posted by 마인드파워
,