Has anyone using the ESP8266 with the SDK had a go at using the JSON routines yet? I ask because I need to pass several MQTT messages to the board in a string. I can of course do this the hard way, comma delimiter or similar, but it would be nice to try to use the JSON routines already in there. Anyone up for a simple example of use with 3 or 4 values passed to a string?
12 thoughts on “ESP8266 and JSON”
Comments are closed.
hey guys, still no JSON sdk demos?
I want to encode a json and send it via post request to my server.
Hi there Jan – this looks like a useful addition to what’s out there… what does the code do to handle lost MQTT and lost WIFI?
I’ve built a power strip that currently exchange json data with an MQTT broker. It parses and constructs json using the json functions in the EspressIf SDK. I don’t think the source of the firmware for this power strip firmware is very complicated to comprehend. If you’re interested, please have a look at the source code on https://github.com/jpenninkhof/esp_mqtt_switch.
Hi Jan, Thanks for sharing your code. I will take a look at it when i’m back from holiday. At the moment I use a simple sprintf to format a JSON string and JasmineJSON to parse a JSON string, but I want to use the SDK JSON. This is a nice start
Got it working thanks to assist from Jan. Now working on getting a cheap Chinese Power Meter wireless. https://www.domoticz.com/forum/viewtopic.php?f=38&t=7325&hilit=+cheap
Did you guys ever manage to work with JSON? I tried simplifying the code in IoT but haven’t got any success as yet. Here’s what I have been doing so far (as understood from IoT Demo):
1) In user init, start a tcp connection and start receiving.
2) Parse incoming data in web server receive and call json_send.
3) Call json_ws_send, this in turn calls the JSON callback function which has set and get methods as defined below:
LOCAL struct jsontree_callback wifi_connect_ap_callback = JSONTREE_CALLBACK(connect_ap_get, connect_ap_set);
JSONTREE_OBJECT(ap_setting, JSONTREE_PAIR(“ssid”, &wifi_connect_ap_callback), JSONTREE_PAIR(“password”, &wifi_connect_ap_callback));
JSONTREE_OBJECT(wifi_tree, JSONTREE_PAIR(“ap_details”, &ap_setting));
But my problem is that json tree callback never calls the connect_ap_set ( which supposedly extracts the values from json tree to variable) and then I am just printing them out.
This is where I have run out of luck and dont seem to make any further headway.
This is code from the SDK IoT example, but it’s very complicated (for me at least) to understand what is done there. If you can explain, please do
Maybe this can help you get going:
http://www.codeforge.com/read/249732/user_webserver.c__html
Does anybody have some sample code of using the JSON from the SDK? I have a hard time to understand how you have to use the SDK JSON library. The IoT demo example is webserver based, but I use TuanPMT’s MQTT code and like to exchange JSON messages between my ESP devices and my central system.
Join the club Sweetpants – I’ve looked at the SDK several times and when it comes to the JSON implementation it has me completely lost. We could do with some simple starter examples…
You probably have this in your list of sources ? ………..
http://esp8266.ru/download/esp8266-doc/ESP8266_IoT_SDK_Programming%20Guide_v0.9.1.pdf
gives some Jason api’s for instance.
Food for thought.
Dave
Thanks for that – actually when you download the SDK now, under DOCS most of the documents are there in English… the current manual is 1.3.0 (0.9.1 is very old now).