|
|
@ -31,6 +31,9 @@ |
|
|
|
#include "log.h" |
|
|
|
#include "log.h" |
|
|
|
#include <gpio.h> |
|
|
|
#include <gpio.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData); |
|
|
|
|
|
|
|
static int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData); |
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
This is the main url->function dispatching data struct. |
|
|
|
This is the main url->function dispatching data struct. |
|
|
|
In short, it's a struct with various URLs plus their handlers. The handlers can |
|
|
|
In short, it's a struct with various URLs plus their handlers. The handlers can |
|
|
@ -64,8 +67,9 @@ HttpdBuiltInUrl builtInUrls[] = { |
|
|
|
{ "/wifi/connstatus", cgiWiFiConnStatus, NULL }, |
|
|
|
{ "/wifi/connstatus", cgiWiFiConnStatus, NULL }, |
|
|
|
{ "/wifi/setmode", cgiWiFiSetMode, NULL }, |
|
|
|
{ "/wifi/setmode", cgiWiFiSetMode, NULL }, |
|
|
|
{ "/wifi/special", cgiWiFiSpecial, NULL }, |
|
|
|
{ "/wifi/special", cgiWiFiSpecial, NULL }, |
|
|
|
|
|
|
|
{ "/system/info", cgiSystemInfo, NULL }, |
|
|
|
|
|
|
|
{ "/system/update", cgiSystemSet, NULL }, |
|
|
|
{ "/pins", cgiPins, NULL }, |
|
|
|
{ "/pins", cgiPins, NULL }, |
|
|
|
{ "/tcpclient", cgiTcp, NULL }, |
|
|
|
|
|
|
|
#ifdef MQTT |
|
|
|
#ifdef MQTT |
|
|
|
{ "/mqtt", cgiMqtt, NULL }, |
|
|
|
{ "/mqtt", cgiMqtt, NULL }, |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -97,6 +101,53 @@ static char *flash_maps[] = { |
|
|
|
"2MB:1024/1024", "4MB:1024/1024" |
|
|
|
"2MB:1024/1024", "4MB:1024/1024" |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cgi to return various System information
|
|
|
|
|
|
|
|
static int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) { |
|
|
|
|
|
|
|
char buff[1024]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
uint8 part_id = system_upgrade_userbin_check(); |
|
|
|
|
|
|
|
uint32_t fid = spi_flash_get_id(); |
|
|
|
|
|
|
|
struct rst_info *rst_info = system_get_rst_info(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
os_sprintf(buff, "{\"name\": \"%s\", \"reset cause\": \"%d=%s\", " |
|
|
|
|
|
|
|
"\"size\": \"%s\"," "\"id\": \"0x%02lX 0x%04lX\"," "\"partition\": \"%s\"," |
|
|
|
|
|
|
|
"\"slip\": \"%s\"," "\"mqtt\": \"%s/%s\"," "\"baud\": \"%ld\"," |
|
|
|
|
|
|
|
"\"description\": \"%s\"" "}", |
|
|
|
|
|
|
|
flashConfig.sys_name, rst_info->reason, rst_codes[rst_info->reason], |
|
|
|
|
|
|
|
flash_maps[system_get_flash_size_map()], fid & 0xff, (fid&0xff00)|((fid>>16)&0xff), |
|
|
|
|
|
|
|
part_id ? "user2.bin" : "user1.bin", |
|
|
|
|
|
|
|
flashConfig.slip_enable ? "enabled" : "disabled", |
|
|
|
|
|
|
|
flashConfig.mqtt_enable ? "enabled" : "disabled", |
|
|
|
|
|
|
|
mqttState(), flashConfig.baud_rate, flashConfig.sys_descr |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
jsonHeader(connData, 200); |
|
|
|
|
|
|
|
httpdSend(connData, buff, -1); |
|
|
|
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Cgi to update system info (name/description)
|
|
|
|
|
|
|
|
static int ICACHE_FLASH_ATTR cgiSystemSet(HttpdConnData *connData) { |
|
|
|
|
|
|
|
if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int8_t status = 0; |
|
|
|
|
|
|
|
status |= getStringArg(connData, "name", flashConfig.sys_name, sizeof(flashConfig.sys_name)); |
|
|
|
|
|
|
|
status |= getStringArg(connData, "description", flashConfig.sys_descr, sizeof(flashConfig.sys_descr)); |
|
|
|
|
|
|
|
if (status < 0) return HTTPD_CGI_DONE; // getStringArg has produced an error response
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (configSave()) { |
|
|
|
|
|
|
|
httpdStartResponse(connData, 204); |
|
|
|
|
|
|
|
httpdEndHeaders(connData); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
httpdStartResponse(connData, 500); |
|
|
|
|
|
|
|
httpdEndHeaders(connData); |
|
|
|
|
|
|
|
httpdSend(connData, "Failed to save config", -1); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return HTTPD_CGI_DONE; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
extern void app_init(void); |
|
|
|
extern void app_init(void); |
|
|
|
extern void mqtt_client_init(void); |
|
|
|
extern void mqtt_client_init(void); |
|
|
|
|
|
|
|
|
|
|
@ -120,6 +171,7 @@ void user_init(void) { |
|
|
|
os_delay_us(10000L); |
|
|
|
os_delay_us(10000L); |
|
|
|
os_printf("\n\n** %s\n", esp_link_version); |
|
|
|
os_printf("\n\n** %s\n", esp_link_version); |
|
|
|
os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*"); |
|
|
|
os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*"); |
|
|
|
|
|
|
|
if (flashConfig.sys_name[0] == 0) os_strcpy(flashConfig.sys_name, "nameme"); |
|
|
|
|
|
|
|
|
|
|
|
#if defined(STA_SSID) && defined(STA_PASS) |
|
|
|
#if defined(STA_SSID) && defined(STA_PASS) |
|
|
|
int x = wifi_get_opmode() & 0x3; |
|
|
|
int x = wifi_get_opmode() & 0x3; |
|
|
|