fixes for services

pull/72/head
Benjamin Runnels 9 years ago
parent 13bc8019c6
commit bfee1cf694
  1. 61
      esp-link/cgiservices.c
  2. 1
      esp-link/cgiservices.h
  3. 25
      esp-link/cgiwifi.c
  4. 2
      esp-link/main.c
  5. 10
      html/services.js
  6. 9
      syslog/syslog.c
  7. 2
      syslog/syslog.h

@ -91,13 +91,14 @@ int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) {
return HTTPD_CGI_DONE;
}
static void ICACHE_FLASH_ATTR cgiServicesSNTPInit() {
if (flashConfig.sntp_server[0]) {
DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset);
void ICACHE_FLASH_ATTR cgiServicesSNTPInit() {
if (flashConfig.sntp_server[0] != '\0') {
sntp_stop();
sntp_setservername(0, flashConfig.sntp_server);
sntp_set_timezone(flashConfig.timezone_offset);
sntp_init();
if (true == sntp_set_timezone(flashConfig.timezone_offset)) {
sntp_setservername(0, flashConfig.sntp_server);
sntp_init();
}
DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset);
}
}
@ -162,14 +163,33 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
int8_t mdns = 0;
mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable);
if (mdns < 0) return HTTPD_CGI_DONE;
mdns |= getStringArg(connData, "mdns_servername", flashConfig.mdns_servername, sizeof(flashConfig.mdns_servername));
if (mdns < 0) return HTTPD_CGI_DONE;
if (syslog > 0) {
if (!flashConfig.syslog_enable) {
flashConfig.syslog_host[0] = '\0';
if (mdns < 0)
return HTTPD_CGI_DONE;
else if (flashConfig.mdns_enable){
struct ip_info ipconfig;
wifi_get_ip_info(STATION_IF, &ipconfig);
if (wifiState == wifiGotIP && ipconfig.ip.addr != 0) {
wifiStartMDNS(ipconfig.ip);
}
}
else {
espconn_mdns_server_unregister();
espconn_mdns_close();
mdns_started = true;
}
mdns |= getStringArg(connData, "mdns_servername", flashConfig.mdns_servername, sizeof(flashConfig.mdns_servername));
if (mdns < 0)
return HTTPD_CGI_DONE;
else if(mdns_started) {
espconn_mdns_server_unregister();
espconn_mdns_close();
espconn_mdns_set_servername(flashConfig.mdns_servername);
espconn_mdns_server_register();
}
if (syslog > 0) {
syslog_init(flashConfig.syslog_host);
}
@ -177,21 +197,6 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
cgiServicesSNTPInit();
}
if (mdns > 0) {
espconn_mdns_disable();
if (flashConfig.mdns_enable) {
struct ip_info ipconfig;
wifi_get_ip_info(STATION_IF, &ipconfig);
mdns_started = false;
if (wifiState == wifiGotIP && ipconfig.ip.addr != 0) {
wifiStartMDNS(ipconfig.ip);
}
}
else {
mdns_started = true;
}
}
if (configSave()) {
httpdStartResponse(connData, 204);
httpdEndHeaders(connData);

@ -6,6 +6,7 @@
int cgiSystemSet(HttpdConnData *connData);
int cgiSystemInfo(HttpdConnData *connData);
void cgiServicesSNTPInit();
int cgiServicesInfo(HttpdConnData *connData);
int cgiServicesSet(HttpdConnData *connData);

@ -60,28 +60,29 @@ static void ICACHE_FLASH_ATTR wifiHandleEventCb(System_Event_t *evt) {
wifiState = wifiIsConnected;
wifiReason = 0;
DBG("Wifi connected to ssid %s, ch %d\n", evt->event_info.connected.ssid,
evt->event_info.connected.channel);
evt->event_info.connected.channel);
statusWifiUpdate(wifiState);
break;
case EVENT_STAMODE_DISCONNECTED:
wifiState = wifiIsDisconnected;
wifiReason = evt->event_info.disconnected.reason;
DBG("Wifi disconnected from ssid %s, reason %s (%d)\n",
evt->event_info.disconnected.ssid, wifiGetReason(), evt->event_info.disconnected.reason);
evt->event_info.disconnected.ssid, wifiGetReason(), evt->event_info.disconnected.reason);
statusWifiUpdate(wifiState);
break;
case EVENT_STAMODE_AUTHMODE_CHANGE:
DBG("Wifi auth mode: %d -> %d\n",
evt->event_info.auth_change.old_mode, evt->event_info.auth_change.new_mode);
evt->event_info.auth_change.old_mode, evt->event_info.auth_change.new_mode);
break;
case EVENT_STAMODE_GOT_IP:
wifiState = wifiGotIP;
wifiReason = 0;
DBG("Wifi got ip:" IPSTR ",mask:" IPSTR ",gw:" IPSTR "\n",
IP2STR(&evt->event_info.got_ip.ip), IP2STR(&evt->event_info.got_ip.mask),
IP2STR(&evt->event_info.got_ip.gw));
IP2STR(&evt->event_info.got_ip.ip), IP2STR(&evt->event_info.got_ip.mask),
IP2STR(&evt->event_info.got_ip.gw));
statusWifiUpdate(wifiState);
wifiStartMDNS(evt->event_info.got_ip.ip);
if (!mdns_started)
wifiStartMDNS(evt->event_info.got_ip.ip);
break;
case EVENT_SOFTAPMODE_STACONNECTED:
DBG("Wifi AP: station " MACSTR " joined, AID = %d\n",
@ -112,15 +113,19 @@ void ICACHE_FLASH_ATTR wifiAddStateChangeCb(WifiStateChangeCb cb) {
}
void ICACHE_FLASH_ATTR wifiStartMDNS(struct ip_addr ip) {
if (!mdns_started) {
if (flashConfig.mdns_enable) {
struct mdns_info *mdns_info = (struct mdns_info *)os_zalloc(sizeof(struct mdns_info));
mdns_info->host_name = flashConfig.hostname;
mdns_info->server_name = flashConfig.mdns_servername; // service name
mdns_info->server_port = 80; // service port
mdns_info->server_name = flashConfig.mdns_servername;
mdns_info->server_port = 80;
mdns_info->ipAddr = ip.addr;
espconn_mdns_init(mdns_info);
mdns_started = true;
}
else {
espconn_mdns_server_unregister();
espconn_mdns_close();
}
mdns_started = true;
}
// ===== wifi scanning

@ -176,7 +176,7 @@ void user_init(void) {
fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
NOTICE("** esp-link ready");
//enableSNTP();
cgiServicesSNTPInit();
#ifdef MQTT
NOTICE("initializing MQTT");

@ -1,9 +1,11 @@
function changeServices(e) {
e.preventDefault();
var url = "services/update?1=1";
var i, inputs = document.querySelectorAll('#' + e.srcElement.id + ' input');
var i, inputs = document.querySelectorAll("#" + e.srcElement.id + " input");
for (i = 0; i < inputs.length; i++) {
if (inputs[i].type == "checkbox") {
if (inputs[i].name.slice(-6) == "enable")
continue;
var val = (inputs[i].checked) ? 1 : 0;
url += "&" + inputs[i].name + "=" + val;
}
@ -14,13 +16,13 @@ function changeServices(e) {
hideWarning();
var n = e.srcElement.id.replace("-form", "");
var cb = $("#" + n + "-button");
addClass(cb, 'pure-button-disabled');
addClass(cb, "pure-button-disabled");
ajaxSpin("POST", url, function (resp) {
showNotification(n + " updated");
removeClass(cb, 'pure-button-disabled');
removeClass(cb, "pure-button-disabled");
}, function (s, st) {
showWarning("Error: " + st);
removeClass(cb, 'pure-button-disabled');
removeClass(cb, "pure-button-disabled");
window.setTimeout(fetchServices, 100);
});
}

@ -234,12 +234,15 @@ static void ICACHE_FLASH_ATTR syslog_gethostbyname_cb(const char *name, ip_addr_
/******************************************************************************
* FunctionName : initSyslog
* Description : Initialize the syslog library
* Parameters : hostname -- the syslog server (host:port)
* Parameters : syslog_host -- the syslog host (host:port)
* host: IP-Addr | hostname
* Returns : none
*******************************************************************************/
void ICACHE_FLASH_ATTR syslog_init(char *syslog_server)
void ICACHE_FLASH_ATTR syslog_init(char *syslog_host)
{
if (!flashConfig.syslog_enable) {
syslog_host[0] = '\0';
}
char host[32], *port = &host[0];
syslog_task = register_usr_task(syslog_udp_send_event);
@ -247,7 +250,7 @@ void ICACHE_FLASH_ATTR syslog_init(char *syslog_server)
syslogHost.port = 514;
syslogState = SYSLOG_WAIT;
os_strncpy(host, syslog_server, 32);
os_strncpy(host, syslog_host, 32);
while (*port && *port != ':') // find port delimiter
port++;
if (*port) {

@ -84,7 +84,7 @@ struct syslog_entry_t {
syslog_host_t syslogserver;
void ICACHE_FLASH_ATTR syslog_init(char *syslog_server);
void ICACHE_FLASH_ATTR syslog_init(char *syslog_host);
void ICACHE_FLASH_ATTR syslog(uint8_t facility, uint8_t severity, const char tag[], const char message[], ...);
// some convenience macros

Loading…
Cancel
Save