fixes for services

pull/72/head
Benjamin Runnels 9 years ago
parent 13bc8019c6
commit bfee1cf694
  1. 51
      esp-link/cgiservices.c
  2. 1
      esp-link/cgiservices.h
  3. 13
      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,14 +91,15 @@ int ICACHE_FLASH_ATTR cgiSystemInfo(HttpdConnData *connData) {
return HTTPD_CGI_DONE; return HTTPD_CGI_DONE;
} }
static void ICACHE_FLASH_ATTR cgiServicesSNTPInit() { void ICACHE_FLASH_ATTR cgiServicesSNTPInit() {
if (flashConfig.sntp_server[0]) { if (flashConfig.sntp_server[0] != '\0') {
DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset);
sntp_stop(); sntp_stop();
if (true == sntp_set_timezone(flashConfig.timezone_offset)) {
sntp_setservername(0, flashConfig.sntp_server); sntp_setservername(0, flashConfig.sntp_server);
sntp_set_timezone(flashConfig.timezone_offset);
sntp_init(); sntp_init();
} }
DBG("SNTP timesource set to %s with offset %d\n", flashConfig.sntp_server, flashConfig.timezone_offset);
}
} }
int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) { int ICACHE_FLASH_ATTR cgiServicesInfo(HttpdConnData *connData) {
@ -162,34 +163,38 @@ int ICACHE_FLASH_ATTR cgiServicesSet(HttpdConnData *connData) {
int8_t mdns = 0; int8_t mdns = 0;
mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable); mdns |= getBoolArg(connData, "mdns_enable", &flashConfig.mdns_enable);
if (mdns < 0) return HTTPD_CGI_DONE; if (mdns < 0)
mdns |= getStringArg(connData, "mdns_servername", flashConfig.mdns_servername, sizeof(flashConfig.mdns_servername)); return HTTPD_CGI_DONE;
if (mdns < 0) return HTTPD_CGI_DONE; else if (flashConfig.mdns_enable){
if (syslog > 0) {
if (!flashConfig.syslog_enable) {
flashConfig.syslog_host[0] = '\0';
}
syslog_init(flashConfig.syslog_host);
}
if (sntp > 0) {
cgiServicesSNTPInit();
}
if (mdns > 0) {
espconn_mdns_disable();
if (flashConfig.mdns_enable) {
struct ip_info ipconfig; struct ip_info ipconfig;
wifi_get_ip_info(STATION_IF, &ipconfig); wifi_get_ip_info(STATION_IF, &ipconfig);
mdns_started = false;
if (wifiState == wifiGotIP && ipconfig.ip.addr != 0) { if (wifiState == wifiGotIP && ipconfig.ip.addr != 0) {
wifiStartMDNS(ipconfig.ip); wifiStartMDNS(ipconfig.ip);
} }
} }
else { else {
espconn_mdns_server_unregister();
espconn_mdns_close();
mdns_started = true; 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);
}
if (sntp > 0) {
cgiServicesSNTPInit();
} }
if (configSave()) { if (configSave()) {

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

@ -81,6 +81,7 @@ static void ICACHE_FLASH_ATTR wifiHandleEventCb(System_Event_t *evt) {
IP2STR(&evt->event_info.got_ip.ip), IP2STR(&evt->event_info.got_ip.mask), 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.gw));
statusWifiUpdate(wifiState); statusWifiUpdate(wifiState);
if (!mdns_started)
wifiStartMDNS(evt->event_info.got_ip.ip); wifiStartMDNS(evt->event_info.got_ip.ip);
break; break;
case EVENT_SOFTAPMODE_STACONNECTED: case EVENT_SOFTAPMODE_STACONNECTED:
@ -112,15 +113,19 @@ void ICACHE_FLASH_ATTR wifiAddStateChangeCb(WifiStateChangeCb cb) {
} }
void ICACHE_FLASH_ATTR wifiStartMDNS(struct ip_addr ip) { 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)); struct mdns_info *mdns_info = (struct mdns_info *)os_zalloc(sizeof(struct mdns_info));
mdns_info->host_name = flashConfig.hostname; mdns_info->host_name = flashConfig.hostname;
mdns_info->server_name = flashConfig.mdns_servername; // service name mdns_info->server_name = flashConfig.mdns_servername;
mdns_info->server_port = 80; // service port mdns_info->server_port = 80;
mdns_info->ipAddr = ip.addr; mdns_info->ipAddr = ip.addr;
espconn_mdns_init(mdns_info); espconn_mdns_init(mdns_info);
mdns_started = true;
} }
else {
espconn_mdns_server_unregister();
espconn_mdns_close();
}
mdns_started = true;
} }
// ===== wifi scanning // ===== wifi scanning

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

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

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

@ -84,7 +84,7 @@ struct syslog_entry_t {
syslog_host_t syslogserver; 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[], ...); void ICACHE_FLASH_ATTR syslog(uint8_t facility, uint8_t severity, const char tag[], const char message[], ...);
// some convenience macros // some convenience macros

Loading…
Cancel
Save