I am trying to receive json data from http server on ESP32, but I get core panic every time I try to access data inside my json. POST request is done using simple html form:
<form method="post" enctype='text/plain'>
<fieldset>
<legend>Fermentation:</legend>
<input name="type" type="radio" value="Ale" /> Ale <br />
<input checked="checked" name="type" type="radio" value="Lager" /> Lager <br />
<label for="primary-duration">Duration of primary</label><br />
<input name="primary-duration" type="text" value="5" /> <br />
<input type="submit" value="Submit"><br />
</fieldset>
</form>
char *buf
contains data from POST like this: type=Lager primary-duration=5\0
After reading the data into buf I am parsing it using cJSON
cJSON *root = cJSON_Parse(buf);
and extracting "type" object
const cJSON *typeJSON = cJSON_GetObjectItemCaseSensitive(root, "type");
after getting my cJSON object it is properly recognized as a string by _IsString(), but I get "LoadProhibited" panic when trying to access it.
if (cJSON_IsString(typeJSON) && (typeJSON->valuestring != NULL))
{
printf("%s", typeJSON->valuestring);
}else if(cJSON_IsString(typeJSON))
{
ESP_LOGE(SERVER_HANDLER_TAG, "String error: Not a string");
}else
{
ESP_LOGE(SERVER_HANDLER_TAG, "String error: empty string"); //I am always here, trying to print string (typeJSON->valuestring) results in kernel panic
}
I would be vary thankful for any advice.