From 8867c8e9b666003439a0c89bdd810d3a0b235852 Mon Sep 17 00:00:00 2001 From: Thorsten von Eicken Date: Sat, 7 Nov 2015 23:41:24 -0800 Subject: [PATCH] fix cgiWifi --- esp-link/cgiwifi.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/esp-link/cgiwifi.c b/esp-link/cgiwifi.c index 28861e9..821328a 100644 --- a/esp-link/cgiwifi.c +++ b/esp-link/cgiwifi.c @@ -227,18 +227,22 @@ static int ICACHE_FLASH_ATTR cgiWiFiGetScan(HttpdConnData *connData) { const int chunk = 1460/64; // ssid is up to 32 chars int len = 0; + os_printf("GET scan: cgiData=%d noAps=%d\n", (int)connData->cgiData, cgiWifiAps.noAps); + // handle continuation call, connData->cgiData-1 is the position in the scan results where we // we need to continue sending from (using -1 'cause 0 means it's the first call) if (connData->cgiData) { int next = (int)connData->cgiData-1; int pos = next; while (pos < cgiWifiAps.noAps && pos < next+chunk) { - len += os_sprintf(buff+len, "{\"essid\": \"%s\", \"rssi\": %d, \"enc\": \"%d\"},\n", - cgiWifiAps.apData[pos]->ssid, cgiWifiAps.apData[pos]->rssi, cgiWifiAps.apData[pos]->enc); + len += os_sprintf(buff+len, "{\"essid\": \"%s\", \"rssi\": %d, \"enc\": \"%d\"}%c\n", + cgiWifiAps.apData[pos]->ssid, cgiWifiAps.apData[pos]->rssi, cgiWifiAps.apData[pos]->enc, + (pos+1 == cgiWifiAps.noAps) ? ' ' : ','); + pos++; } // done or more? if (pos == cgiWifiAps.noAps) { - len += os_sprintf(buff+len-1, "]}}\n"); + len += os_sprintf(buff+len, "]}}\n"); httpdSend(connData, buff, len); return HTTPD_CGI_DONE; } else {