// This cgi uses the routines above to connect to a specific access point with the // given ESSID using the given password. int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) { char essid[128]; char passwd[128]; if (connData->conn==NULL) return HTTPD_CGI_DONE; int el = httpdFindArg(connData->getArgs, "essid", essid, sizeof(essid)); int pl = httpdFindArg(connData->getArgs, "passwd", passwd, sizeof(passwd)); if (el > 0 && pl >= 0) { //Set to 0 if you want to disable the actual reconnecting bit os_strncpy((char*)stconf.ssid, essid, 32); os_strncpy((char*)stconf.password, passwd, 64); DBG("Wifi try to connect to AP %s pw %s\n", essid, passwd); //Schedule disconnect/connect os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, reassTimerCb, NULL); os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it jsonHeader(connData, 200); } else { jsonHeader(connData, 400); httpdSend(connData, "Cannot parse ssid or password", -1); } return HTTPD_CGI_DONE; }
// Change special settings int ICACHE_FLASH_ATTR cgiRadioSpecial(HttpdConnData *connData) { char dhcp[8]; char hostname[32]; char staticip[20]; char netmask[20]; char gateway[20]; if (connData->conn==NULL) return HTTPD_CGI_DONE; // get args and their string lengths int dl = httpdFindArg(connData->getArgs, "dhcp", dhcp, sizeof(dhcp)); int hl = httpdFindArg(connData->getArgs, "hostname", hostname, sizeof(hostname)); int sl = httpdFindArg(connData->getArgs, "staticip", staticip, sizeof(staticip)); int nl = httpdFindArg(connData->getArgs, "netmask", netmask, sizeof(netmask)); int gl = httpdFindArg(connData->getArgs, "gateway", gateway, sizeof(gateway)); if (!(dl > 0 && hl >= 0 && sl >= 0 && nl >= 0 && gl >= 0)) { jsonHeader(connData, 400); httpdSend(connData, "Request is missing fields", -1); return HTTPD_CGI_DONE; } char url[64]; // redirect URL jsonHeader(connData, 200); httpdSend(connData, url, -1); return HTTPD_CGI_DONE; }
//This cgi changes the operating mode: STA / AP / STA+AP int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) { int len; char buff[1024]; if (connData->conn==NULL) { // Connection aborted. Clean up. return HTTPD_CGI_DONE; } len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff)); if (len!=0) { int m = atoi(buff); os_printf("Wifi switching to mode %d\n", m); #ifndef DEMO_MODE wifi_set_opmode(m&3); if (m == 1) { wifi_set_sleep_type(SLEEP_MODE); // STA-only mode, reset into STA+AP after a timeout os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); } jsonHeader(connData, 200); #endif } else { jsonHeader(connData, 400); } return HTTPD_CGI_DONE; }
// Change special settings int ICACHE_FLASH_ATTR cgiWiFiSpecial(HttpdConnData *connData) { char dhcp[8]; char staticip[20]; char netmask[20]; char gateway[20]; if (connData->conn==NULL) return HTTPD_CGI_DONE; // get args and their string lengths int dl = httpdFindArg(connData->getArgs, "dhcp", dhcp, sizeof(dhcp)); int sl = httpdFindArg(connData->getArgs, "staticip", staticip, sizeof(staticip)); int nl = httpdFindArg(connData->getArgs, "netmask", netmask, sizeof(netmask)); int gl = httpdFindArg(connData->getArgs, "gateway", gateway, sizeof(gateway)); if (!(dl > 0 && sl >= 0 && nl >= 0 && gl >= 0)) { jsonHeader(connData, 400); httpdSend(connData, "Request is missing fields", -1); return HTTPD_CGI_DONE; } char url[64]; // redirect URL if (os_strcmp(dhcp, "off") == 0) { // parse static IP params struct ip_info ipi; bool ok = parse_ip(staticip, &ipi.ip); if (nl > 0) ok = ok && parse_ip(netmask, &ipi.netmask); else IP4_ADDR(&ipi.netmask, 255, 255, 255, 0); if (gl > 0) ok = ok && parse_ip(gateway, &ipi.gw); else ipi.gw.addr = 0; if (!ok) { jsonHeader(connData, 400); httpdSend(connData, "Cannot parse static IP config", -1); return HTTPD_CGI_DONE; } // save the params in flash flashConfig.staticip = ipi.ip.addr; flashConfig.netmask = ipi.netmask.addr; flashConfig.gateway = ipi.gw.addr; // construct redirect URL os_sprintf(url, "{\"url\": \"http://%d.%d.%d.%d\"}", IP2STR(&ipi.ip)); } else { // dynamic IP flashConfig.staticip = 0; os_sprintf(url, "{\"url\": \"http://%s\"}", flashConfig.hostname); } configSave(); // ignore error... // schedule change-over os_timer_disarm(&reassTimer); os_timer_setfn(&reassTimer, configWifiIP, NULL); os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it // return redirect info jsonHeader(connData, 200); httpdSend(connData, url, -1); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR ajaxLogDbg(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. char buff[512]; int len, status = 400; len = httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff)); if (len > 0) { int8_t mode = -1; if (os_strcmp(buff, "auto") == 0) mode = LOG_MODE_AUTO; if (os_strcmp(buff, "off") == 0) mode = LOG_MODE_OFF; if (os_strcmp(buff, "on0") == 0) mode = LOG_MODE_ON0; if (os_strcmp(buff, "on1") == 0) mode = LOG_MODE_ON1; if (mode >= 0) { flashConfig.log_mode = mode; if (mode != LOG_MODE_AUTO) log_uart(mode >= LOG_MODE_ON0); status = configSave() ? 200 : 400; } } else if (connData->requestType == HTTPD_METHOD_GET) { status = 200; } jsonHeader(connData, status); os_sprintf(buff, "{\"mode\": \"%s\"}", dbg_mode[flashConfig.log_mode]); httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR ajaxConsoleReset(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. jsonHeader(connData, 200); console_rd = console_wr = console_pos = 0; serbridgeReset(); return HTTPD_CGI_DONE; }
// Get current Soft-AP settings int ICACHE_FLASH_ATTR cgiApSettingsInfo(HttpdConnData *connData) { char buff[1024]; if (connData->conn == NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. os_sprintf(buff, "{ " "\"ap_ssid\": \"%s\", " "\"ap_password\": \"%s\", " "\"ap_authmode\": %d, " "\"ap_maxconn\": %d, " "\"ap_beacon\": %d, " "\"ap_hidden\": \"%s\" " " }", apconf.ssid, apconf.password, apconf.authmode, apconf.max_connection, apconf.beacon_interval, apconf.ssid_hidden ? "enabled" : "disabled" ); jsonHeader(connData, 200); httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR ajaxConsoleFormat(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. char buff[16]; int len, status = 400; len = httpdFindArg(connData->getArgs, "fmt", buff, sizeof(buff)); if (len >= 3) { int c = buff[0]; if (c >= '5' && c <= '8') flashConfig.data_bits = c - '5' + FIVE_BITS; if (buff[1] == 'N') flashConfig.parity = NONE_BITS; if (buff[1] == 'E') flashConfig.parity = EVEN_BITS; if (buff[1] == 'O') flashConfig.parity = ODD_BITS; if (buff[2] == '1') flashConfig.stop_bits = ONE_STOP_BIT; if (buff[2] == '2') flashConfig.stop_bits = TWO_STOP_BIT; uart0_config(flashConfig.data_bits, flashConfig.parity, flashConfig.stop_bits); status = configSave() ? 200 : 400; } else if (connData->requestType == HTTPD_METHOD_GET) { status = 200; } jsonHeader(connData, status); os_sprintf(buff, "{\"fmt\": \"%c%c%c\"}", flashConfig.data_bits + '5', flashConfig.parity ? 'E' : 'N', flashConfig.stop_bits ? '2': '1'); httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) { char buff[1024]; int len; if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. jsonHeader(connData, 200); len = os_sprintf(buff, "{"); len += printWifiInfo(buff+len); len += os_sprintf(buff+len, ", "); if (wifiReason != 0) { len += os_sprintf(buff+len, "\"reason\": \"%s\", ", wifiGetReason()); } #if 0 // commented out 'cause often the client that requested the change can't get a request in to // find out that it succeeded. Better to just wait the std 15 seconds... int st=wifi_station_get_connect_status(); if (st == STATION_GOT_IP) { if (wifi_get_opmode() != 1) { // Reset into AP-only mode sooner. os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); os_timer_arm(&resetTimer, 1000, 0); } } #endif len += os_sprintf(buff+len, "\"x\":0}\n"); //DBG(" -> %s\n", buff); httpdSend(connData, buff, len); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR ajaxConsoleBaud(HttpdConnData *connData) { char buff[2048]; int len; len = httpdFindArg(connData->getArgs, "rate", buff, sizeof(buff)); if (len > 0) { int rate = atoi(buff); if (rate >= 9600 && rate <= 1000000) { jsonHeader(connData, 200); uart0_baud(rate); return HTTPD_CGI_DONE; } } jsonHeader(connData, 400); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR cgiWiFiScan(HttpdConnData *connData) { if (connData->requestType == HTTPD_METHOD_GET) { return cgiWiFiGetScan(connData); }else if(connData->requestType == HTTPD_METHOD_POST) { // DO NOT start APs scan in AP mode int mode = wifi_get_opmode(); if(mode==2){ jsonHeader(connData, 400); return HTTPD_CGI_DONE; }else{ return cgiWiFiStartScan(connData); } }else{ jsonHeader(connData, 404); return HTTPD_CGI_DONE; } }
static int ICACHE_FLASH_ATTR cgiWiFiStartScan(HttpdConnData *connData) { jsonHeader(connData, 200); if (!cgiWifiAps.scanInProgress) { cgiWifiAps.scanInProgress = 1; os_timer_disarm(&scanTimer); os_timer_setfn(&scanTimer, scanStartCb, NULL); os_timer_arm(&scanTimer, 1000, 0); } return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR cgiTcp(HttpdConnData *connData) { if (connData->requestType == HTTPD_METHOD_GET) { return cgiTcpGet(connData); } else if (connData->requestType == HTTPD_METHOD_POST) { return cgiTcpSet(connData); } else { jsonHeader(connData, 404); return HTTPD_CGI_DONE; } }
static int ICACHE_FLASH_ATTR cgiWiFiStartScan(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. jsonHeader(connData, 200); if (!cgiWifiAps.scanInProgress) { cgiWifiAps.scanInProgress = 1; os_timer_disarm(&scanTimer); os_timer_setfn(&scanTimer, scanStartCb, NULL); os_timer_arm(&scanTimer, 200, 0); } return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR cgiPins(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. if (connData->requestType == HTTPD_METHOD_GET) { return cgiPinsGet(connData); } else if (connData->requestType == HTTPD_METHOD_POST) { return cgiPinsSet(connData); } else { jsonHeader(connData, 404); return HTTPD_CGI_DONE; } }
// Cgi to change choice of pin assignments int ICACHE_FLASH_ATTR cgiTcpSet(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Handle tcp_enable flag char buff[128]; int len = httpdFindArg(connData->getArgs, "tcp_enable", buff, sizeof(buff)); if (len <= 0) { jsonHeader(connData, 400); return HTTPD_CGI_DONE; } flashConfig.tcp_enable = os_strcmp(buff, "true") == 0; // Handle rssi_enable flag len = httpdFindArg(connData->getArgs, "rssi_enable", buff, sizeof(buff)); if (len <= 0) { jsonHeader(connData, 400); return HTTPD_CGI_DONE; } flashConfig.rssi_enable = os_strcmp(buff, "true") == 0; // Handle api_key flag len = httpdFindArg(connData->getArgs, "api_key", buff, sizeof(buff)); if (len < 0) { jsonHeader(connData, 400); return HTTPD_CGI_DONE; } buff[sizeof(flashConfig.api_key)-1] = 0; // ensure we don't get an overrun os_strcpy(flashConfig.api_key, buff); if (configSave()) { httpdStartResponse(connData, 200); httpdEndHeaders(connData); } else { httpdStartResponse(connData, 500); httpdEndHeaders(connData); httpdSend(connData, "Failed to save config", -1); } return HTTPD_CGI_DONE; }
// Cgi to return various Wifi information int ICACHE_FLASH_ATTR cgiWifiInfo(HttpdConnData *connData) { char buff[1024]; if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. os_strcpy(buff, "{"); printWifiInfo(buff+1); os_strcat(buff, "}"); jsonHeader(connData, 200); httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; }
// Cgi to return TCP client settings int ICACHE_FLASH_ATTR cgiTcpGet(HttpdConnData *connData) { char buff[1024]; int len; if (connData->conn==NULL) return HTTPD_CGI_DONE; len = os_sprintf(buff, "{ \"tcp_enable\":%d, \"rssi_enable\": %d, \"api_key\":\"%s\" }", flashConfig.tcp_enable, flashConfig.rssi_enable, flashConfig.api_key); jsonHeader(connData, 200); httpdSend(connData, buff, len); return HTTPD_CGI_DONE; }
//This cgi changes the operating mode: STA / AP / STA+AP int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) { int len; char buff[1024]; if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff)); if (len!=0) { int m = atoi(buff); DBG("Wifi switching to mode %d\n", m); wifi_set_opmode(m&3); if (m == 1) { // STA-only mode, reset into STA+AP after a timeout if we don't get an IP address os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); } jsonHeader(connData, 200); } else { jsonHeader(connData, 400); } return HTTPD_CGI_DONE; }
//This cgi changes the operating mode: STA / AP / STA+AP int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) { int len; char buff[1024]; int previous_mode = wifi_get_opmode(); if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff)); int next_mode = atoi(buff); if (len!=0) { if (next_mode == 2){ // moving to AP mode, so disconnect before leave STA mode wifi_station_disconnect(); } DBG("Wifi switching to mode %d\n", next_mode); wifi_set_opmode(next_mode&3); if (previous_mode == 2) { // moving to STA or STA+AP mode from AP, try to connect and set timer stconf.bssid_set = 0; wifi_station_set_config(&stconf); wifi_station_connect(); os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); } if(previous_mode == 1){ // moving to AP or STA+AP from STA, so softap config call needed wifi_softap_set_config(&apconf); } jsonHeader(connData, 200); } else { jsonHeader(connData, 400); } return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR ajaxConsoleSend(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. char buff[2048]; int len, status = 400; // figure out where to start in buffer based on URI param len = httpdFindArg(connData->getArgs, "text", buff, sizeof(buff)); if (len > 0) { uart0_tx_buffer(buff, len); status = 200; } jsonHeader(connData, status); return HTTPD_CGI_DONE; }
// Cgi to return choice of pin assignments int ICACHE_FLASH_ATTR cgiPinsGet(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted char buff[1024]; int len; len = os_sprintf(buff, "{ \"reset\":%d, \"isp\":%d, \"conn\":%d, \"ser\":%d, \"swap\":%d, \"rxpup\":%d }", flashConfig.reset_pin, flashConfig.isp_pin, flashConfig.conn_led_pin, flashConfig.ser_led_pin, !!flashConfig.swap_uart, 1); jsonHeader(connData, 200); httpdSend(connData, buff, len); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR ajaxConsole(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. char buff[2048]; int len; // length of text in buff int console_len = (console_wr+BUF_MAX-console_rd) % BUF_MAX; // num chars in console_buf int start = 0; // offset onto console_wr to start sending out chars jsonHeader(connData, 200); // figure out where to start in buffer based on URI param len = httpdFindArg(connData->getArgs, "start", buff, sizeof(buff)); if (len > 0) { start = atoi(buff); if (start < console_pos) { start = 0; } else if (start >= console_pos+console_len) { start = console_len; } else { start = start - console_pos; } } // start outputting len = os_sprintf(buff, "{\"len\":%d, \"start\":%d, \"text\": \"", console_len-start, console_pos+start); int rd = (console_rd+start) % BUF_MAX; while (len < 2040 && rd != console_wr) { uint8_t c = console_buf[rd]; if (c == '\\' || c == '"') { buff[len++] = '\\'; buff[len++] = c; } else if (c == '\r') { // this is crummy, but browsers display a newline for \r\n sequences } else if (c < ' ') { len += os_sprintf(buff+len, "\\u%04x", c); } else { buff[len++] = c; } rd = (rd + 1) % BUF_MAX; } os_strcpy(buff+len, "\"}"); len+=2; //DBG_REST("ARDUINO CONSOLE buff: %s \n", buff); //Vash httpdSend(connData, buff, len); return HTTPD_CGI_DONE; }
static int ICACHE_FLASH_ATTR cgiWiFiGetScan(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. char buff[1460]; 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\"}%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, "]}}\n"); httpdSend(connData, buff, len); return HTTPD_CGI_DONE; } else { connData->cgiData = (void*)(pos+1); httpdSend(connData, buff, len); return HTTPD_CGI_MORE; } } jsonHeader(connData, 200); if (cgiWifiAps.scanInProgress==1) { //We're still scanning. Tell Javascript code that. len = os_sprintf(buff, "{\n \"result\": { \n\"inProgress\": \"1\"\n }\n}\n"); httpdSend(connData, buff, len); return HTTPD_CGI_DONE; } len = os_sprintf(buff, "{\"result\": {\"inProgress\": \"0\", \"APs\": [\n"); connData->cgiData = (void *)1; // start with first result next time we're called httpdSend(connData, buff, len); return HTTPD_CGI_MORE; }
int ICACHE_FLASH_ATTR ajaxLog(HttpdConnData *connData) { char buff[2048]; int len; // length of text in buff int log_len = (log_wr+BUF_MAX-log_rd) % BUF_MAX; // num chars in log_buf int start = 0; // offset onto log_wr to start sending out chars if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. jsonHeader(connData, 200); // figure out where to start in buffer based on URI param len = httpdFindArg(connData->getArgs, "start", buff, sizeof(buff)); if (len > 0) { start = atoi(buff); if (start < log_pos) { start = 0; } else if (start >= log_pos+log_len) { start = log_len; } else { start = start - log_pos; } } // start outputting len = os_sprintf(buff, "{\"len\":%d, \"start\":%d, \"text\": \"", log_len-start, log_pos+start); int rd = (log_rd+start) % BUF_MAX; while (len < 2040 && rd != log_wr) { uint8_t c = log_buf[rd]; if (c == '\\' || c == '"') { buff[len++] = '\\'; buff[len++] = c; } else if (c < ' ') { len += os_sprintf(buff+len, "\\u%04x", c); } else { buff[len++] = c; } rd = (rd + 1) % BUF_MAX; } os_strcpy(buff+len, "\"}"); len+=2; httpdSend(connData, buff, len); return HTTPD_CGI_DONE; }
// Cgi to return NFC settings int ICACHE_FLASH_ATTR cgiNFCGet(HttpdConnData *connData) { char buff[1024]; int len; if (connData->conn==NULL) return HTTPD_CGI_DONE; len = os_sprintf(buff, "{ " "\"nfc-url\":\"%s\", " "\"nfc-device-id\":\"%s\", " "\"nfc-device-secret\":\"%s\", " "\"nfc-counter\":%d }", flashConfig.nfc_url, flashConfig.nfc_device_id, flashConfig.nfc_device_secret, flashConfig.nfc_counter); jsonHeader(connData, 200); httpdSend(connData, buff, len); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR ajaxConsoleBaud(HttpdConnData *connData) { if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. char buff[512]; int len, status = 400; len = httpdFindArg(connData->getArgs, "rate", buff, sizeof(buff)); if (len > 0) { int rate = atoi(buff); if (rate >= 9600 && rate <= 1000000) { uart0_baud(rate); flashConfig.baud_rate = rate; status = configSave() ? 200 : 400; } } else if (connData->requestType == HTTPD_METHOD_GET) { status = 200; } jsonHeader(connData, status); os_sprintf(buff, "{\"rate\": %ld}", flashConfig.baud_rate); httpdSend(connData, buff, -1); return HTTPD_CGI_DONE; }
static int ICACHE_FLASH_ATTR cgiWiFiGetScan(HttpdConnData *connData) { char buff[2048]; int len; jsonHeader(connData, 200); if (cgiWifiAps.scanInProgress==1) { //We're still scanning. Tell Javascript code that. len = os_sprintf(buff, "{\n \"result\": { \n\"inProgress\": \"1\"\n }\n}\n"); httpdSend(connData, buff, len); return HTTPD_CGI_DONE; } len = os_sprintf(buff, "{\"result\": {\"inProgress\": \"0\", \"APs\": [\n"); for (int pos=0; pos<cgiWifiAps.noAps; pos++) { len += os_sprintf(buff+len, "{\"essid\": \"%s\", \"rssi\": %d, \"enc\": \"%d\"}%s\n", cgiWifiAps.apData[pos]->ssid, cgiWifiAps.apData[pos]->rssi, cgiWifiAps.apData[pos]->enc, (pos==cgiWifiAps.noAps-1)?"":","); } len += os_sprintf(buff+len, "]}}\n"); //os_printf("Sending %d bytes: %s\n", len, buff); httpdSend(connData, buff, len); return HTTPD_CGI_DONE; }
int ICACHE_FLASH_ATTR cgiRadioConnStatus(HttpdConnData *connData) { char buff[1024]; int len; if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up. jsonHeader(connData, 200); len = os_sprintf(buff, "{"); len += printRadioStatus(buff+len); len += os_sprintf(buff+len, ", "); // if (radioReason != 0) { // len += os_sprintf(buff+len, "\"reason\": \"%s\", ", radioGetReason()); // } #if 0 // commented out 'cause often the client that requested the change can't get a request in to // find out that it succeeded. Better to just wait the std 15 seconds... // int st=radio_station_get_connect_status(); // if (st == STATION_GOT_IP) { // if (radio_get_opmode() != 1) { // // Reset into AP-only mode sooner. // } }
int ICACHE_FLASH_ATTR ajaxConsoleReset(HttpdConnData *connData) { jsonHeader(connData, 200); serbridgeReset(); return HTTPD_CGI_DONE; }