Forgive me if this question is a basic one, but can you please suggest how to get more information displayed in the UART messages about the POST and GET requests?
The IoT_Demo code currently prints "We have a POST request.", or "We have a GET request". It would be very useful for debugging if it would also print the parsed JSON data to help make sure the JSON commands in the POST / GET are being received and interpreted properly.
Scott.
Debug tool request
Re: Debug tool request
Postby Thorvald » Mon Mar 02, 2015 4:43 pm
hi Scott
I ran into the same problem, but solved it by adding some printstatement, where the JSON is parsed
Like in this statement
LOCAL struct jsontree_callback status_callback = JSONTREE_CALLBACK(status_get, status_set);
Where the first parameter is used when GETting your values and setting it into the JSON-variable, and the second is SETting your variables from values in the JSON-variable.
ANd then in the status-set function adding
/******************************************************************************
* FunctionName : status_set
* Description : parse the device status parmer as a JSON format
* Parameters : js_ctx -- A pointer to a JSON set up
* parser -- A pointer to a JSON parser state
* Returns : result
*******************************************************************************/
LOCAL int ICACHE_FLASH_ATTR
status_set(struct jsontree_context *js_ctx, struct jsonparse_state *parser)
{
int type;
while ((type = jsonparse_next(parser)) != 0) {
if (type == JSON_TYPE_PAIR_NAME) {
if (jsonparse_strcmp_value(parser, "status") == 0) {
uint8 status;
jsonparse_next(parser);
jsonparse_next(parser);
status = jsonparse_get_value_as_int(parser);
user_plug_set_status(status);
os_printf("status: %d\n", status);
}
}
}
return 0;
}
Best regards
Thorvald
I ran into the same problem, but solved it by adding some printstatement, where the JSON is parsed
Like in this statement
LOCAL struct jsontree_callback status_callback = JSONTREE_CALLBACK(status_get, status_set);
Where the first parameter is used when GETting your values and setting it into the JSON-variable, and the second is SETting your variables from values in the JSON-variable.
ANd then in the status-set function adding
/******************************************************************************
* FunctionName : status_set
* Description : parse the device status parmer as a JSON format
* Parameters : js_ctx -- A pointer to a JSON set up
* parser -- A pointer to a JSON parser state
* Returns : result
*******************************************************************************/
LOCAL int ICACHE_FLASH_ATTR
status_set(struct jsontree_context *js_ctx, struct jsonparse_state *parser)
{
int type;
while ((type = jsonparse_next(parser)) != 0) {
if (type == JSON_TYPE_PAIR_NAME) {
if (jsonparse_strcmp_value(parser, "status") == 0) {
uint8 status;
jsonparse_next(parser);
jsonparse_next(parser);
status = jsonparse_get_value_as_int(parser);
user_plug_set_status(status);
os_printf("status: %d\n", status);
}
}
}
return 0;
}
Best regards
Thorvald
Who is online
Users browsing this forum: No registered users and 185 guests
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.