int main(int argc, char** argv){ int retval = 0; retval = init_web_server(argc,argv); logger(INFO,"Starting server...."); retval = run_web_server(); return 0; }
void ICACHE_FLASH_ATTR user_init() { // init UART for debugging baud rate comes from user_config.h uart_div_modify(0, UART_CLK_FREQ / BAUD_RATE); os_printf("\r\nESP8266 OOK decoding\r\n"); // speed boost (hopefully) //system_update_cpu_freq(160); system_update_cpu_freq(80); // setup loop callback in system task queue system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); system_os_post(user_procTaskPrio, 0, 0); // init wifi using creds in wifi_config.h. Put your own creds in the file connect_wifi(WIFI_SSID, WIFI_PSK); // apparently an accurate system time is needed for SSL, so start up // SNTP stuff. // SNTP is also used for timestamping emails and alarm triggeringings sntp_setservername(0, "time.nist.gov"); sntp_setservername(1, "time-c.nist.gov"); sntp_set_timezone(TIMEZONE); sntp_init(); // init stuff for the ook decoder gpio_init(); gpio_intr_handler_register(ook_intr_handler, (void*) &unprocessedPackets); init_ook_decoder(); // webserver-related initialisation init_web_server(); attach_btn_clear(clearTriggeredSensors); attach_btn_arm_alarm(arm_alarm); attach_btn_disarm_alarm(disarm_alarm); // update so we don't just have a blank page on startup updateWebpage(); }
int init_device(struct v7 *v7) { int result = 1; uint8_t mac[6] = ""; /* Load system defaults - mandatory */ memset(&s_cfg, 0, sizeof(s_cfg)); if (!load_config_defaults(&s_cfg)) { LOG(LL_ERROR, ("Failed to load config defaults")); return 0; } #ifndef SJ_DISABLE_GPIO /* * Check factory reset GPIO. We intentionally do it before loading CONF_FILE * so that it cannot be overridden by the end user. */ if (s_cfg.debug.factory_reset_gpio >= 0) { int gpio = s_cfg.debug.factory_reset_gpio; sj_gpio_set_mode(gpio, GPIO_MODE_INPUT, GPIO_PULL_PULLUP); if (sj_gpio_read(gpio) == GPIO_LEVEL_LOW) { LOG(LL_WARN, ("Factory reset requested via GPIO%d", gpio)); if (remove(CONF_FILE) == 0) { LOG(LL_WARN, ("Removed %s", CONF_FILE)); } /* Continue as if nothing happened, no reboot necessary. */ } } #endif /* Successfully loaded system config. Try overrides - they are optional. */ load_config_file(CONF_FILE, s_cfg.conf_acl, 0, &s_cfg); REGISTER_RO_VAR(fw_id, &build_id); REGISTER_RO_VAR(fw_timestamp, &build_timestamp); REGISTER_RO_VAR(fw_version, &build_version); REGISTER_RO_VAR(arch, &s_architecture); /* Init mac address readonly var - users may use it as device ID */ device_get_mac_address(mac); snprintf(s_mac_address, sizeof(s_mac_address), "%02X%02X%02X%02X%02X%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); REGISTER_RO_VAR(mac_address, &mac_address_ptr); LOG(LL_INFO, ("MAC: %s", s_mac_address)); if (get_cfg()->wifi.ap.ssid != NULL) { expand_mac_address_placeholders((char *) get_cfg()->wifi.ap.ssid); } result = device_init_platform(v7, get_cfg()); if (result != 0) { if (get_cfg()->http.enable) { result = init_web_server(get_cfg()); } } else { LOG(LL_ERROR, ("Platform init failed")); } #ifndef CS_DISABLE_JS /* NOTE(lsm): must be done last */ export_read_only_vars_to_v7(v7); #endif return result; }