nodemcu-firmware-origin
nodemcu-firmware-origin copied to clipboard
cjson library
Hello, As It seems to complex while working with cjson library. What I need is json like below and after so many attempt I couldn't succeed yet. { "event": "openData.weatherStats", "user_id": "ec159ad1561c5d326007a64970c271a5", "time": 1482555353, "eventData": { "deviceId": "c81c4f278bcbeee529c3bade90383280", "temperature": 27, "humidity": 17, "light": 884, "airQuality": 294 } }
I do it from arduino easiest way but I want to do it from lua. Arduino code for above json structure is below so is there any way to do that please inform me or suggest me a way to do that via lua script:
//Json DynamicJsonBuffer jsonBuffer; JsonObject& root = jsonBuffer.createObject();
// Creating JSON root["event"] = "openData.weatherStats"; root["user_id"] = "ec159ad1561c5d326007a64970c271a4"; root["time"] = prevDisplay; JsonObject& root2 = root.createNestedObject("eventData"); root2["deviceId"] = "c81c4f278bcbeee529c3bade90383280"; root2["temperature"] = avg_temp; root2["humidity"] = avg_humidity; root2["light"] = avg_light; root2["airQuality"] = avg_airQuality;
// Printing JSON Serial.println("----------------------------------------------"); Serial.println("Json Data:"); root.prettyPrintTo(Serial); Serial.println("----------------------------------------------");
Please guide me for lua ... Thanks