diff -r 71e06f6d80fd -r 7639cfa6aec0 main/task_http.c --- a/main/task_http.c Sat May 04 11:41:16 2019 +0200 +++ b/main/task_http.c Sat May 04 21:18:51 2019 +0200 @@ -6,6 +6,7 @@ #include "config.h" #include "mbedtls/base64.h" #include "mbedtls/sha1.h" +#include "cJSON.h" static const char *TAG = "task_http"; @@ -14,6 +15,8 @@ static TaskHandle_t xTaskHTTP = NULL; static TaskHandle_t xTaskQueue = NULL; +cJSON *root = NULL; +cJSON *touch = NULL; /** @@ -21,8 +24,9 @@ * @param buf The buffer * @param buflen Length of the buffer */ +#if 0 void dump_buf(char *buf, uint16_t buflen); - +#endif /** @@ -214,6 +218,8 @@ */ void websock_callback(uint8_t num, WEBSOCKET_TYPE_t type, char* msg, uint64_t len) { + char jbuf[128]; + switch(type) { case WEBSOCKET_CONNECT: ESP_LOGI(TAG,"Websocket client %i connected!",num); @@ -232,13 +238,32 @@ break; case WEBSOCKET_TEXT: + /* + * Handle json actions from the web clients, like button presses. + */ + if (len < 128) { // Safety, messages are small. + memcpy(jbuf, msg, len); + jbuf[len] = '\0'; + if ((root = cJSON_Parse(jbuf))) { + if ((touch = cJSON_GetObjectItem(root,"touch"))) { + int x = cJSON_GetObjectItem(touch, "x")->valueint; + int y = cJSON_GetObjectItem(touch, "y")->valueint; + WS_touched(x, y); + break; + } else { + ESP_LOGI(TAG,"not json touch"); + } + cJSON_Delete(root); + } else { + ESP_LOGI(TAG,"not json"); + } + } + // Log if the message in not processed. ESP_LOGI(TAG,"Websocket client %i sent text message of size %i:\n%s",num,(uint32_t)len,msg); - dump_buf(msg, len); break; case WEBSOCKET_BIN: ESP_LOGI(TAG,"Websocket client %i sent bin message of size %i:\n",num,(uint32_t)len); - dump_buf(msg, len); break; case WEBSOCKET_PING: @@ -253,6 +278,7 @@ +#if 0 void dump_buf(char *buf, uint16_t buflen) { int i = 0, l = 1; @@ -277,6 +303,7 @@ } printf("\n"); } +#endif @@ -398,7 +425,9 @@ return; } +#if 0 dump_buf(buf, buflen); +#endif if (strstr(buf, "GET /")) { ESP_LOGI(TAG, "%s request: %s", ipstr, buf);