diff --git a/examples/arduino/EspLinkSample/EspLink.cpp b/examples/arduino/EspLinkSample/EspLink.cpp index 7b1a21d..0e2972a 100644 --- a/examples/arduino/EspLinkSample/EspLink.cpp +++ b/examples/arduino/EspLinkSample/EspLink.cpp @@ -71,7 +71,7 @@ void EspLink::sendPacketArg(uint16_t len, uint8_t * data) writeBuf((uint8_t*)&len, 2); writeBuf(data, len); - uint16_t pad = (4-((len+2)&3))&3; // get to multiple of 4 + uint16_t pad = ((len+3)&~3) - len; // get to multiple of 4 if (pad > 0) { uint32_t temp = 0; writeBuf((uint8_t*)&temp, pad); diff --git a/examples/arduino/EspLinkSample/EspLinkSample.ino b/examples/arduino/EspLinkSample/EspLinkSample.ino index b1b199f..81d721c 100644 --- a/examples/arduino/EspLinkSample/EspLinkSample.ino +++ b/examples/arduino/EspLinkSample/EspLinkSample.ino @@ -52,6 +52,14 @@ void packetReceived(CmdRequest *req) } break; } + + char * json = "{'last_name': 'helloka'}"; + + espLink.sendPacketStart(CMD_WEB_JSON_DATA, 100, 3); + espLink.sendPacketArg(4, ip); + espLink.sendPacketArg(2, (uint8_t *)&port); + espLink.sendPacketArg(strlen(json), (uint8_t *)json); + espLink.sendPacketEnd(); } diff --git a/web-server/web-server.c b/web-server/web-server.c index 67b1fd8..5ce1de8 100644 --- a/web-server/web-server.c +++ b/web-server/web-server.c @@ -177,10 +177,33 @@ int ICACHE_FLASH_ATTR WEB_CgiJsonHook(HttpdConnData *connData) connData->cgiData = (void *)1; } - // TODO return HTTPD_CGI_MORE; } void ICACHE_FLASH_ATTR WEB_JsonData(CmdPacket *cmd) { -} \ No newline at end of file + CmdRequest req; + cmdRequest(&req, cmd); + + os_printf("JSON data\n"); // TODO + + if (cmdGetArgc(&req) != 3) return; + + uint8_t ip[4]; + cmdPopArg(&req, ip, 4); + os_printf("IP:%d.%d.%d.%d\n", ip[0], ip[1], ip[2], ip[3]); // TODO + + uint16_t port; + cmdPopArg(&req, &port, 2); + os_printf("Port:%d\n", port); // TODO + + int16_t len = cmdArgLen(&req); + os_printf("Len:%d\n", len); // TODO + uint8_t json[len+1]; + json[len] = 0; + cmdPopArg(&req, json, len); + + os_printf("%s\n", json); // TODO + + // TODO +}