mirror of
https://github.com/jeelabs/esp-link.git
synced 2026-03-06 01:14:00 +01:00
Merge remote-tracking branch 'origin/master' into rs485
This commit is contained in:
6
Makefile
6
Makefile
@@ -46,7 +46,7 @@
|
||||
CHANGE_TO_STA ?= yes
|
||||
|
||||
# hostname or IP address for wifi flashing
|
||||
ESP_HOSTNAME ?= esp-link
|
||||
ESP_HOSTNAME ?= esp-link
|
||||
|
||||
# --------------- toolchain configuration ---------------
|
||||
|
||||
@@ -57,7 +57,7 @@ XTENSA_TOOLS_ROOT ?= $(abspath ../esp-open-sdk/xtensa-lx106-elf/bin)/
|
||||
# Firmware version
|
||||
# WARNING: if you change this expect to make code adjustments elsewhere, don't expect
|
||||
# that esp-link will magically work with a different version of the SDK!!!
|
||||
SDK_VERS ?= esp_iot_sdk_v1.5.2
|
||||
SDK_VERS ?= esp_iot_sdk_v1.5.4
|
||||
|
||||
# Try to find the firmware manually extracted, e.g. after downloading from Espressif's BBS,
|
||||
# http://bbs.espressif.com/viewforum.php?f=46
|
||||
@@ -101,7 +101,7 @@ LED_SERIAL_PIN ?= 14
|
||||
# --------------- esp-link modules config options ---------------
|
||||
|
||||
# Optional Modules mqtt
|
||||
MODULES ?= mqtt rest syslog
|
||||
MODULES ?= mqtt rest #syslog
|
||||
|
||||
# --------------- esphttpd config options ---------------
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|ARM">
|
||||
@@ -72,6 +72,7 @@
|
||||
<ClInclude Include="httpd\base64.h" />
|
||||
<ClInclude Include="httpd\httpd.h" />
|
||||
<ClInclude Include="httpd\httpdespfs.h" />
|
||||
<ClInclude Include="include\c_types.h" />
|
||||
<ClInclude Include="include\esp8266.h" />
|
||||
<ClInclude Include="include\espmissingincludes.h" />
|
||||
<ClInclude Include="include\uart_hw.h" />
|
||||
@@ -110,8 +111,14 @@
|
||||
<None Include="html\ui.js" />
|
||||
<None Include="html\wifi\wifi.html" />
|
||||
<None Include="html\wifi\wifi.js" />
|
||||
<None Include="html\wifi\wifiAp.html" />
|
||||
<None Include="html\wifi\wifiAp.js" />
|
||||
<None Include="html\wifi\wifiSta.html" />
|
||||
<None Include="html\wifi\wifiSta.js" />
|
||||
<None Include="Makefile" />
|
||||
<None Include="README.adoc" />
|
||||
<None Include="README.md" />
|
||||
<None Include="syslog\syslog.md" />
|
||||
<None Include="wiflash" />
|
||||
<None Include="WINDOWS.md" />
|
||||
</ItemGroup>
|
||||
@@ -121,6 +128,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Image Include="html\favicon.ico" />
|
||||
<Image Include="html\wifi\icons.png" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{A92F0CAA-F89B-4F78-AD2A-A042429BD87F}</ProjectGuid>
|
||||
@@ -140,7 +148,7 @@
|
||||
<PropertyGroup>
|
||||
<NMakeOutput />
|
||||
<NMakePreprocessorDefinitions>__ets__;_STDINT_H;ICACHE_FLASH;__MINGW32__;__WIN32__;MQTT;REST;SYSLOG;FIRMWARE_SIZE</NMakePreprocessorDefinitions>
|
||||
<NMakeIncludeSearchPath>.\syslog;.\rest;.\esp-link;.\mqtt;.\cmd;.\serial;.\user;.\espfs;.\httpd;.\include;..\esp_iot_sdk_v1.5.0\include;..\xtensa-lx106-elf\xtensa-lx106-elf\include;c:\tools\mingw64\x86_64-w64-mingw32\include;c:\tools\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.3\include</NMakeIncludeSearchPath>
|
||||
<NMakeIncludeSearchPath>.\syslog;.\rest;.\esp-link;.\mqtt;.\cmd;.\serial;.\user;.\espfs;.\httpd;.\include;..\esp_iot_sdk_v1.5.2\include;..\xtensa-lx106-elf\xtensa-lx106-elf\include;c:\tools\mingw64\x86_64-w64-mingw32\include;c:\tools\mingw64\lib\gcc\x86_64-w64-mingw32\4.8.3\include</NMakeIncludeSearchPath>
|
||||
<ExecutablePath />
|
||||
<ReferencePath />
|
||||
<LibraryPath />
|
||||
@@ -168,4 +176,4 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -95,11 +95,11 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) {
|
||||
|
||||
if (mqtt_server < 0) return HTTPD_CGI_DONE;
|
||||
mqtt_server |= getBoolArg(connData, "mqtt-clean-session",
|
||||
&flashConfig.mqtt_clean_session);
|
||||
(bool *)&flashConfig.mqtt_clean_session);
|
||||
|
||||
if (mqtt_server < 0) return HTTPD_CGI_DONE;
|
||||
int8_t mqtt_en_chg = getBoolArg(connData, "mqtt-enable",
|
||||
&flashConfig.mqtt_enable);
|
||||
(bool *)&flashConfig.mqtt_enable);
|
||||
|
||||
char buff[16];
|
||||
|
||||
@@ -134,7 +134,7 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) {
|
||||
mqtt_client_init();
|
||||
|
||||
// if just enable changed we just need to bounce the client
|
||||
}
|
||||
}
|
||||
else if (mqtt_en_chg > 0) {
|
||||
DBG("MQTT server enable=%d changed\n", flashConfig.mqtt_enable);
|
||||
if (flashConfig.mqtt_enable && strlen(flashConfig.mqtt_host) > 0)
|
||||
@@ -145,16 +145,16 @@ int ICACHE_FLASH_ATTR cgiMqttSet(HttpdConnData *connData) {
|
||||
|
||||
// no action required if mqtt status settings change, they just get picked up at the
|
||||
// next status tick
|
||||
if (getBoolArg(connData, "mqtt-status-enable", &flashConfig.mqtt_status_enable) < 0)
|
||||
if (getBoolArg(connData, "mqtt-status-enable", (bool *)&flashConfig.mqtt_status_enable) < 0)
|
||||
return HTTPD_CGI_DONE;
|
||||
if (getStringArg(connData, "mqtt-status-topic",
|
||||
flashConfig.mqtt_status_topic, sizeof(flashConfig.mqtt_status_topic)) < 0)
|
||||
return HTTPD_CGI_DONE;
|
||||
|
||||
// if SLIP-enable is toggled it gets picked-up immediately by the parser
|
||||
int slip_update = getBoolArg(connData, "slip-enable", &flashConfig.slip_enable);
|
||||
int slip_update = getBoolArg(connData, "slip-enable", (bool *)&flashConfig.slip_enable);
|
||||
if (slip_update < 0) return HTTPD_CGI_DONE;
|
||||
if (slip_update > 0)
|
||||
if (slip_update > 0)
|
||||
DBG("SLIP-enable changed: %d\n", flashConfig.slip_enable);
|
||||
|
||||
DBG("Saving config\n");
|
||||
|
||||
@@ -3,9 +3,11 @@
|
||||
#include "cgiwifi.h"
|
||||
#include "cgi.h"
|
||||
#include "config.h"
|
||||
#include "syslog.h"
|
||||
#include "sntp.h"
|
||||
#include "cgimqtt.h"
|
||||
#ifdef SYSLOG
|
||||
#include "syslog.h"
|
||||
#endif
|
||||
|
||||
#ifdef CGISERVICES_DBG
|
||||
#define DBG(format, ...) do { os_printf(format, ## __VA_ARGS__); } while(0)
|
||||
@@ -110,21 +112,25 @@ int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) {
|
||||
|
||||
os_sprintf(buff,
|
||||
"{ "
|
||||
#ifdef SYSLOG
|
||||
"\"syslog_host\": \"%s\", "
|
||||
"\"syslog_minheap\": %d, "
|
||||
"\"syslog_filter\": %d, "
|
||||
"\"syslog_showtick\": \"%s\", "
|
||||
"\"syslog_showdate\": \"%s\", "
|
||||
#endif
|
||||
"\"timezone_offset\": %d, "
|
||||
"\"sntp_server\": \"%s\", "
|
||||
"\"mdns_enable\": \"%s\", "
|
||||
"\"mdns_servername\": \"%s\""
|
||||
" }",
|
||||
#ifdef SYSLOG
|
||||
flashConfig.syslog_host,
|
||||
flashConfig.syslog_minheap,
|
||||
flashConfig.syslog_filter,
|
||||
flashConfig.syslog_showtick ? "enabled" : "disabled",
|
||||
flashConfig.syslog_showdate ? "enabled" : "disabled",
|
||||
#endif
|
||||
flashConfig.timezone_offset,
|
||||
flashConfig.sntp_server,
|
||||
flashConfig.mdns_enable ? "enabled" : "disabled",
|
||||
@@ -147,14 +153,16 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
|
||||
if (syslog < 0) return HTTPD_CGI_DONE;
|
||||
syslog |= getUInt8Arg(connData, "syslog_filter", &flashConfig.syslog_filter);
|
||||
if (syslog < 0) return HTTPD_CGI_DONE;
|
||||
syslog |= getBoolArg(connData, "syslog_showtick", &flashConfig.syslog_showtick);
|
||||
syslog |= getBoolArg(connData, "syslog_showtick", (bool *)&flashConfig.syslog_showtick);
|
||||
if (syslog < 0) return HTTPD_CGI_DONE;
|
||||
syslog |= getBoolArg(connData, "syslog_showdate", &flashConfig.syslog_showdate);
|
||||
syslog |= getBoolArg(connData, "syslog_showdate", (bool *)&flashConfig.syslog_showdate);
|
||||
if (syslog < 0) return HTTPD_CGI_DONE;
|
||||
|
||||
#ifdef SYSLOG
|
||||
if (syslog > 0) {
|
||||
syslog_init(flashConfig.syslog_host);
|
||||
}
|
||||
#endif
|
||||
|
||||
int8_t sntp = 0;
|
||||
sntp |= getInt8Arg(connData, "timezone_offset", &flashConfig.timezone_offset);
|
||||
@@ -167,7 +175,7 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
|
||||
}
|
||||
|
||||
int8_t mdns = 0;
|
||||
mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable);
|
||||
mdns |= getBoolArg(connData, "mdns_enable", (bool *)&flashConfig.mdns_enable);
|
||||
if (mdns < 0) return HTTPD_CGI_DONE;
|
||||
|
||||
if (mdns > 0) {
|
||||
|
||||
@@ -851,6 +851,8 @@ void ICACHE_FLASH_ATTR wifiInit() {
|
||||
os_strncpy((char*)stconf.ssid, VERS_STR(STA_SSID), 32);
|
||||
os_strncpy((char*)stconf.password, VERS_STR(STA_PASS), 64);
|
||||
|
||||
wifi_set_opmode(3);
|
||||
|
||||
DBG("Wifi pre-config trying to connect to AP %s pw %s\n",(char*)stconf.ssid, (char*)stconf.password);
|
||||
|
||||
// wifi_set_phy_mode(2); // limit to 802.11b/g 'cause n is flaky
|
||||
|
||||
@@ -29,13 +29,19 @@
|
||||
#include "config.h"
|
||||
#include "log.h"
|
||||
#include "gpio.h"
|
||||
#include "syslog.h"
|
||||
#include "cgiservices.h"
|
||||
|
||||
#define NOTICE(format, ...) do { \
|
||||
LOG_NOTICE(format, ## __VA_ARGS__ ); \
|
||||
os_printf(format "\n", ## __VA_ARGS__); \
|
||||
#ifdef SYSLOG
|
||||
#include "syslog.h"
|
||||
#define NOTICE(format, ...) do { \
|
||||
LOG_NOTICE(format, ## __VA_ARGS__ ); \
|
||||
os_printf(format "\n", ## __VA_ARGS__); \
|
||||
} while ( 0 )
|
||||
#else
|
||||
#define NOTICE(format, ...) do { \
|
||||
os_printf(format "\n", ## __VA_ARGS__); \
|
||||
} while ( 0 )
|
||||
#endif
|
||||
|
||||
/*
|
||||
This is the main url->function dispatching data struct.
|
||||
|
||||
@@ -31,7 +31,11 @@ function updateText(resp) {
|
||||
if (resp.start > el.textEnd) {
|
||||
el.innerHTML = el.innerHTML.concat("\r\n<missing lines\r\n");
|
||||
}
|
||||
el.innerHTML = el.innerHTML.concat(resp.text);
|
||||
el.innerHTML = el.innerHTML.concat(resp.text
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"'));
|
||||
el.textEnd = resp.start + resp.len;
|
||||
delay = 500;
|
||||
|
||||
|
||||
@@ -51,7 +51,12 @@ function displayServices(data) {
|
||||
$("#sntp-spinner").setAttribute("hidden", "");
|
||||
$("#mdns-spinner").setAttribute("hidden", "");
|
||||
|
||||
$("#Syslog-form").removeAttribute("hidden");
|
||||
if (data.syslog_host !== undefined) {
|
||||
$("#Syslog-form").removeAttribute("hidden");
|
||||
} else {
|
||||
# syslog disabled...
|
||||
$("#Syslog-form").parentNode.setAttribute("hidden", "");
|
||||
}
|
||||
$("#SNTP-form").removeAttribute("hidden");
|
||||
$("#mDNS-form").removeAttribute("hidden");
|
||||
|
||||
|
||||
@@ -44,6 +44,7 @@ struct HttpdPriv {
|
||||
char *sendBuff; // output buffer
|
||||
short headPos; // offset into header
|
||||
short sendBuffLen; // offset into output buffer
|
||||
short sendBuffMax; // size of output buffer
|
||||
short code; // http response code (only for logging)
|
||||
};
|
||||
|
||||
@@ -226,6 +227,13 @@ int ICACHE_FLASH_ATTR httpdGetHeader(HttpdConnData *conn, char *header, char *re
|
||||
return 0;
|
||||
}
|
||||
|
||||
//Setup an output buffer
|
||||
void ICACHE_FLASH_ATTR httpdSetOutputBuffer(HttpdConnData *conn, char *buff, short max) {
|
||||
conn->priv->sendBuff = buff;
|
||||
conn->priv->sendBuffLen = 0;
|
||||
conn->priv->sendBuffMax = max;
|
||||
}
|
||||
|
||||
//Start the response headers.
|
||||
void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code) {
|
||||
char buff[128];
|
||||
@@ -277,9 +285,9 @@ int ICACHE_FLASH_ATTR cgiRedirect(HttpdConnData *connData) {
|
||||
//Returns 1 for success, 0 for out-of-memory.
|
||||
int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len) {
|
||||
if (len<0) len = strlen(data);
|
||||
if (conn->priv->sendBuffLen + len>MAX_SENDBUFF_LEN) {
|
||||
if (conn->priv->sendBuffLen + len>conn->priv->sendBuffMax) {
|
||||
DBG("%sERROR! httpdSend full (%d of %d)\n",
|
||||
connStr, conn->priv->sendBuffLen, MAX_SENDBUFF_LEN);
|
||||
connStr, conn->priv->sendBuffLen, conn->priv->sendBuffMax);
|
||||
return 0;
|
||||
}
|
||||
os_memcpy(conn->priv->sendBuff + conn->priv->sendBuffLen, data, len);
|
||||
@@ -288,7 +296,7 @@ int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len)
|
||||
}
|
||||
|
||||
//Helper function to send any data in conn->priv->sendBuff
|
||||
static void ICACHE_FLASH_ATTR xmitSendBuff(HttpdConnData *conn) {
|
||||
void ICACHE_FLASH_ATTR httpdFlush(HttpdConnData *conn) {
|
||||
if (conn->priv->sendBuffLen != 0) {
|
||||
sint8 status = espconn_sent(conn->conn, (uint8_t*)conn->priv->sendBuff, conn->priv->sendBuffLen);
|
||||
if (status != 0) {
|
||||
@@ -307,13 +315,12 @@ static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
|
||||
if (conn == NULL) return; // aborted connection
|
||||
|
||||
char sendBuff[MAX_SENDBUFF_LEN];
|
||||
conn->priv->sendBuff = sendBuff;
|
||||
conn->priv->sendBuffLen = 0;
|
||||
httpdSetOutputBuffer(conn, sendBuff, sizeof(sendBuff));
|
||||
|
||||
if (conn->cgi == NULL) { //Marked for destruction?
|
||||
//os_printf("Closing 0x%p/0x%p->0x%p\n", arg, conn->conn, conn);
|
||||
espconn_disconnect(conn->conn); // we will get a disconnect callback
|
||||
return; //No need to call xmitSendBuff.
|
||||
return; //No need to call httpdFlush.
|
||||
}
|
||||
|
||||
int r = conn->cgi(conn); //Execute cgi fn.
|
||||
@@ -324,7 +331,7 @@ static void ICACHE_FLASH_ATTR httpdSentCb(void *arg) {
|
||||
DBG("%sERROR! Bad CGI code %d\n", connStr, r);
|
||||
conn->cgi = NULL; //mark for destruction.
|
||||
}
|
||||
xmitSendBuff(conn);
|
||||
httpdFlush(conn);
|
||||
}
|
||||
|
||||
static const char *httpNotFoundHeader = "HTTP/1.0 404 Not Found\r\nConnection: close\r\n"
|
||||
@@ -366,7 +373,7 @@ static void ICACHE_FLASH_ATTR httpdProcessRequest(HttpdConnData *conn) {
|
||||
//generate a built-in 404 to handle this.
|
||||
DBG("%s%s not found. 404!\n", connStr, conn->url);
|
||||
httpdSend(conn, httpNotFoundHeader, -1);
|
||||
xmitSendBuff(conn);
|
||||
httpdFlush(conn);
|
||||
conn->cgi = NULL; //mark for destruction.
|
||||
if (conn->post) conn->post->len = 0; // skip any remaining receives
|
||||
return;
|
||||
@@ -378,12 +385,12 @@ static void ICACHE_FLASH_ATTR httpdProcessRequest(HttpdConnData *conn) {
|
||||
r = conn->cgi(conn);
|
||||
if (r == HTTPD_CGI_MORE) {
|
||||
//Yep, it's happy to do so and has more data to send.
|
||||
xmitSendBuff(conn);
|
||||
httpdFlush(conn);
|
||||
return;
|
||||
}
|
||||
else if (r == HTTPD_CGI_DONE) {
|
||||
//Yep, it's happy to do so and already is done sending data.
|
||||
xmitSendBuff(conn);
|
||||
httpdFlush(conn);
|
||||
conn->cgi = NULL; //mark for destruction.
|
||||
if (conn->post) conn->post->len = 0; // skip any remaining receives
|
||||
return;
|
||||
@@ -485,8 +492,7 @@ static void ICACHE_FLASH_ATTR httpdRecvCb(void *arg, char *data, unsigned short
|
||||
if (conn == NULL) return; // aborted connection
|
||||
|
||||
char sendBuff[MAX_SENDBUFF_LEN];
|
||||
conn->priv->sendBuff = sendBuff;
|
||||
conn->priv->sendBuffLen = 0;
|
||||
httpdSetOutputBuffer(conn, sendBuff, sizeof(sendBuff));
|
||||
|
||||
//This is slightly evil/dirty: we abuse conn->post->len as a state variable for where in the http communications we are:
|
||||
//<0 (-1): Post len unknown because we're still receiving headers
|
||||
|
||||
@@ -59,10 +59,12 @@ int httpdUrlDecode(char *val, int valLen, char *ret, int retLen);
|
||||
int ICACHE_FLASH_ATTR httpdFindArg(char *line, char *arg, char *buff, int buffLen);
|
||||
void ICACHE_FLASH_ATTR httpdInit(HttpdBuiltInUrl *fixedUrls, int port);
|
||||
const char *httpdGetMimetype(char *url);
|
||||
void ICACHE_FLASH_ATTR httpdSetOutputBuffer(HttpdConnData *conn, char *buff, short max);
|
||||
void ICACHE_FLASH_ATTR httpdStartResponse(HttpdConnData *conn, int code);
|
||||
void ICACHE_FLASH_ATTR httpdHeader(HttpdConnData *conn, const char *field, const char *val);
|
||||
void ICACHE_FLASH_ATTR httpdEndHeaders(HttpdConnData *conn);
|
||||
int ICACHE_FLASH_ATTR httpdGetHeader(HttpdConnData *conn, char *header, char *ret, int retLen);
|
||||
int ICACHE_FLASH_ATTR httpdSend(HttpdConnData *conn, const char *data, int len);
|
||||
void ICACHE_FLASH_ATTR httpdFlush(HttpdConnData *conn);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -10,7 +10,11 @@
|
||||
#include "console.h"
|
||||
#include "slip.h"
|
||||
#include "cmd.h"
|
||||
#ifdef SYSLOG
|
||||
#include "syslog.h"
|
||||
#else
|
||||
#define syslog(X1...)
|
||||
#endif
|
||||
|
||||
#define SKIP_AT_RESET
|
||||
|
||||
|
||||
Reference in New Issue
Block a user