diff --git a/firmware/web.cpp b/firmware/web.cpp index ed55e2d..f627fcc 100644 --- a/firmware/web.cpp +++ b/firmware/web.cpp @@ -204,6 +204,18 @@ void websocket_task(void *pvParameter) { } + vTaskDelayMs(250); + { + uint8_t response[3]; + uint16_t val; + val = sdk_system_adc_read(); + response[2] = (uint8_t) val; + response[1] = val >> 8; + response[0] = 'V'; + LOCK_TCPIP_CORE(); + websocket_write(pcb, response, 3, WS_BIN_MODE); + UNLOCK_TCPIP_CORE(); + } vTaskDelayMs(500); } @@ -247,56 +259,92 @@ void websocket_cb(struct tcp_pcb *pcb, char *data, u16_t data_len, bool togl = false; - switch (data[0]) { - case 'R': // Restart - cmd = 'R'; - ret = OK; - break; - case 'X': // Clear Config - cmd = 'X'; - ret = OK; - break; - case 'D': // Disable LED - syslog("G\n"); - signal_led(false); - cmd = 'G'; - ret = OK; - val = 1; - break; - case 'E': // Enable LED - syslog("E\n"); - signal_led(true); - cmd = 'G'; - ret = OK; - val = 0; - break; - case 'F': - togl = !togl; - signal_led(togl); - { - auto *f = (fw_frame *) data; - if(f->seq == 0) { - system_otaflash_init(); - } - uint16_t ack = 0; - ret = system_otaflash_chunk(f->data, ntohs(f->len), ntohs(f->seq), ntohl(f->hash), &ack); - val = htons(ack); - } - cmd = 'F'; - break; - case 'C': - signal_led(false); - { - auto *f = (fw_check *) data; - ret = system_otaflash_verify_and_switch(ntohl(f->len), ntohl(f->hash)); - } - cmd = 'C'; - break; - default: - printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data); - printf("Unknown command %c\n", data[0]); - ret = ERROR; - break; + if(data[0] == 'V') { + /* This should be done on a separate thread in 'real' applications */ + val = sdk_system_adc_read(); + cmd = 'V'; + } else if(data[0] == 'R') { + // Restart + cmd = 'R'; + ret = OK; + } else if(data[0] == 'X') { + // Clear Config + cmd = 'X'; + ret = OK; + } else if(data[0] == 'D') { + // Disable LED + syslog("G\n"); + signal_led(false); + cmd = 'G'; + ret = OK; + val = 1; + } else if(data[0] == 'E') { + // Enable LED + syslog("E\n"); + signal_led(true); + cmd = 'G'; + ret = OK; + val = 0; + } else if(data[0] == 'F') { + togl = !togl; + signal_led(togl); + auto *f = (fw_frame *) data; + if(f->seq == 0) { + system_otaflash_init(); + } + uint16_t ack = 0; + ret = system_otaflash_chunk(f->data, ntohs(f->len), ntohs(f->seq), ntohl(f->hash), &ack); + val = htons(ack); + cmd = 'F'; + } else if(data[0] == 'C') { + signal_led(false); + auto *f = (fw_check *) data; + ret = system_otaflash_verify_and_switch(ntohl(f->len), ntohl(f->hash)); + cmd = 'C'; + } else if(data[0] == 'S') { + int8_t en = 0; + if(data[1] == 'E') + en = 1; + char *ssid = &data[2]; + size_t ssid_len = strlen(ssid); + char *password = &data[3 + ssid_len]; + size_t password_len = strlen(password); + (void) password_len; + + sysparam_set_int8("wifi_sta_enable", en); + sysparam_set_string("wifi_sta_ssid", ssid); + sysparam_set_string("wifi_sta_password", password); + + //sysparam_get_int8("wifi_sta_dhcp", wifi_sta_dhcp); + //sysparam_get_int32("wifi_sta_ip_addr", wifi_sta_ip_addr); + //sysparam_get_int32("wifi_sta_netmask", wifi_sta_netmask); + //sysparam_get_int32("wifi_sta_gateway", wifi_sta_gateway); + cmd = 'S'; + } else if(data[0] == 'A') { + int8_t en = 0; + uint8_t dns_enable = 0; + uint8_t mdns_enable = 0; + if(data[1] == 'E') + en = 1; + char *ssid = &data[2]; + size_t ssid_len = strlen(ssid); + char *password = &data[3 + ssid_len]; + size_t password_len = strlen(password); + (void) password_len; + + sysparam_set_int8("wifi_ap_enable", en); + sysparam_set_string("wifi_ap_ssid", ssid); + sysparam_set_string("wifi_ap_password", password); + + //sysparam_get_int32("wifi_ap_ip_addr", "172.16.0.1"); + //sysparam_get_int32("wifi_ap_netmask", "255.255.0.0"); + //sysparam_set_int8("wifi_ap_dns", dns_enable); + //sysparam_set_int8("wifi_ap_mdns", mdns_enable); + cmd = 'A'; + } else { + printf("[websocket_callback]:\n%.*s\n", (int) data_len, (char *) data); + printf("Unknown command %c\n", data[0]); + ret = ERROR; } LOCK_TCPIP_CORE(); diff --git a/firmware/webdir/index.html b/firmware/webdir/index.html index 317dc10..e394222 100644 --- a/firmware/webdir/index.html +++ b/firmware/webdir/index.html @@ -17,6 +17,7 @@
@@ -75,6 +76,87 @@ +