void setupwebpage_init(void) { int reset_count = 0; while (!GPIO_INPUT_GET(LED_GPIO_4)) // Check to see if web page setup button is held low on powerup { INFO("*"); ++reset_count; os_delay_us(500000); // Half second tick if (reset_count > 6) { for (int i = 0; i < 5; i++) { os_delay_us(100000); digitalWrite(LED_GPIO_13, 1); os_delay_us(100000); digitalWrite(LED_GPIO_13, 0);} break; } } if (reset_count < 6) // OK button not held down at power up, setup MQTT etc { wifiInit(STATION_MODE); // Only connect to the local network if (sysCfg.enable_webpage_control) { INFO("Setting up for normal MQTT Operation\r"); builtInUrls[0].cgiArg = "/led.tpl"; httpdInit(builtInUrls, 80); } INFO("ESP8266 in STA mode configured.\r\n"); // Setup a timer to initialise the mqtt system 5 seconds after a wifi connection is established os_timer_disarm(&MQTTlogontimer); os_timer_setfn(&MQTTlogontimer, MQTTLogonTimerCb, NULL); os_timer_arm(&MQTTlogontimer, 5000, 1); allow_mqtt_init = 1; // Allow the MQTT system to connect } else { //struct softap_config apConfig; INFO("Setting up for Web Page Configuration\r"); httpdInit(builtInUrls, 80); wifiInit(STATIONAP_MODE); // Connect to the local network //wifi_softap_get_config(&apConfig); } }
void user_init(void) { // Uart init uart_div_modify(0, UART_CLK_FREQ / 115200); os_printf("\nStarting...\n"); int i; for(i=0; i<MAX_CONNS; i++) { // c field is used as indicator for free/used connection slots conns[i].id = 0; } // Add page to ureq //ureq_serve("/", s_home, "GET"); ureq_serve("/get", s_get, "GET"); ureq_serve("/post", s_post, "ALL"); ureq_serve("/redirect", s_redirect, "GET"); ureq_serve("/redirected", s_redirected, "GET"); // Some gpio-related stuff gpio_init(); //Set GPIO2 to output mode PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO0_U); //Set GPIO2 high gpio_output_set(BIT0, 0, BIT0, 0); // Wifi setup wifiInit(); ssServerInit(); // Print a message that we have completed user_init on debug uart os_printf("Ready.\n"); }
/********************************************************************************************* * Setup relevant hardware *********************************************************************************************/ static void prvSetupHardware( void ) { // Ensure that all 4 interrupt priority bits are used as the pre-emption priority NVIC_PriorityGroupConfig( NVIC_PriorityGroup_4 ); // Setup LEDs ledInit(); // Setup WiFi wifiInit(); }
// Main routine to initialize esp-link. void user_init(void) { // get the flash config so we know how to init things //configWipe(); // uncomment to reset the config for testing purposes bool restoreOk = configRestore(); // Init gpio pin registers gpio_init(); gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled // init UART uart_init(flashConfig.baud_rate, 115200); logInit(); // must come after init of uart // Say hello (leave some time to cause break in TX after boot loader's msg os_delay_us(10000L); os_printf("\n\n** %s\n", esp_link_version); os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*"); // Status LEDs statusInit(); serledInit(); // Wifi wifiInit(); // init the flash filesystem with the html stuff espFsInit(&_binary_espfs_img_start); //EspFsInitResult res = espFsInit(&_binary_espfs_img_start); //os_printf("espFsInit %s\n", res?"ERR":"ok"); // mount the http handlers httpdInit(builtInUrls, 80); // init the wifi-serial transparent bridge (port 23) serbridgeInit(23, 2323); uart_add_recv_cb(&serbridgeUartCb); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 10000, 1); #endif struct rst_info *rst_info = system_get_rst_info(); NOTICE("Reset cause: %d=%s", rst_info->reason, rst_codes[rst_info->reason]); NOTICE("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x", rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3, rst_info->excvaddr, rst_info->depc); uint32_t fid = spi_flash_get_id(); NOTICE("Flash map %s, manuf 0x%02lX chip 0x%04lX", flash_maps[system_get_flash_size_map()], fid & 0xff, (fid&0xff00)|((fid>>16)&0xff)); NOTICE("** esp-link ready"); // Init SNTP service cgiServicesSNTPInit(); #ifdef MQTT NOTICE("initializing MQTT"); mqtt_client_init(); #endif NOTICE("initializing user application"); app_init(); NOTICE("Waiting for work to do..."); }
//Init function void ICACHE_FLASH_ATTR user_init() { uart_init(BIT_RATE_115200, BIT_RATE_115200); os_delay_us(100000); wifiInit(); //Start os task system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); system_os_post(user_procTaskPrio, 0, 0); }
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { // init gpio pins used to reset&reprogram attached microcontrollers gpio_init(); // put MCU into reset in case it interferes with serial-programming of the esp8266 //GPIO_OUTPUT_SET(MCU_RESET, 0); // init UART uart_init(BIT_RATE_115200, BIT_RATE_115200); // say hello (leave some time to cause break in TX after boot loader's msg os_delay_us(10000L); # define VERS_STR_STR(V) #V # define VERS_STR(V) VERS_STR_STR(V) os_printf("\n\nInitializing esp-link\n" VERS_STR(VERSION) "\n"); //configWipe(); if (configRestore()) os_printf("Flash config restored\n"); else os_printf("*** Flash config restore failed, using defaults ***\n"); // Status LEDs statusInit(); serledInit(); logInit(); // Wifi wifiInit(); // init the flash filesystem with the html stuff EspFsInitResult res = espFsInit(&_binary_espfs_img_start); os_printf("espFsInit(0x%08lx) returned %d\n", (uint32_t)&_binary_espfs_img_start, res); // mount the http handlers httpdInit(builtInUrls, 80); // init the wifi-serial transparent bridge (port 23) serbridgeInit(23); uart_add_recv_cb(&serbridgeUartCb); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 3000, 1); #endif struct rst_info *rst_info = system_get_rst_info(); os_printf("Reset cause: %d=%s\n", rst_info->reason, rst_codes[rst_info->reason]); os_printf("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x\n", rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3, rst_info->excvaddr, rst_info->depc); os_printf("** esp-link ready\n"); }
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { // get the flash config so we know how to init things //configWipe(); // uncomment to reset the config for testing purposes bool restoreOk = configRestore(); // init gpio pin registers gpio_init(); // init UART uart_init(flashConfig.baud_rate, 115200); logInit(); // must come after init of uart // say hello (leave some time to cause break in TX after boot loader's msg os_delay_us(10000L); os_printf("\n\n** %s\n", esp_link_version); os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*"); // Status LEDs statusInit(); serledInit(); // Wifi wifiInit(); // init the flash filesystem with the html stuff espFsInit(&_binary_espfs_img_start); //EspFsInitResult res = espFsInit(&_binary_espfs_img_start); //os_printf("espFsInit %s\n", res?"ERR":"ok"); // mount the http handlers httpdInit(builtInUrls, 80); // init the wifi-serial transparent bridge (port 23) serbridgeInit(23); uart_add_recv_cb(&serbridgeUartCb); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 10000, 1); #endif struct rst_info *rst_info = system_get_rst_info(); os_printf("Reset cause: %d=%s\n", rst_info->reason, rst_codes[rst_info->reason]); os_printf("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x\n", rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3, rst_info->excvaddr, rst_info->depc); os_printf("Flash map %d, chip %08X\n", system_get_flash_size_map(), spi_flash_get_id()); os_printf("** esp-link ready\n"); }
int main() { irqInit(); irqEnable(IRQ_VBLANK); videoSetMode(0); videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE); vramSetBankC(VRAM_C_SUB_BG); SUB_BG0_CR = BG_MAP_BASE(31); BG_PALETTE_SUB[255] = RGB15(31, 31, 31); consoleInitDefault((u16 *) SCREEN_BASE_BLOCK_SUB(31), (u16 *) CHAR_BASE_BLOCK_SUB(0), 16); printf("Starting FAT\n"); fatInitDefault(); printf("Starting WiFi\n"); wifiInit(); while(1) Menu::Main(); return 0; }
String wakeupSendSleep(String APname,String APpassword,String data,String path,String servername,String datatype,int port, String* res){ String str = ""; String response; wifi_init(); int counter = 0; wakeup(); String APconnect = wifiInit(APname, APpassword); if(APconnect == "OK"){ str = connectAndSend(data,path,servername,datatype,port,res); while(!sleep(1000)){ counter++; if(counter>=5){ SerialUSB.println("Wi-Fi sleeping Failed!"); return "Error: 13"; //Wi-Fi sleeping Failed! } } } else{ return APconnect; } return str; }
// Main routine to initialize esp-link. void ICACHE_FLASH_ATTR user_init(void) { // Init gpio pin registers gpio_init(); gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled // init UART uart_init(115200); // Say hello (leave some time to cause break in TX after boot loader's msg os_delay_us(10000L); NOTICE("\n\n** %s\n", esp_link_version); // Wifi wifiInit(); // mount the http handlers httpdInit(builtInUrls, 80); struct rst_info *rst_info = system_get_rst_info(); NOTICE("Reset cause: %d=%s", rst_info->reason, rst_codes[rst_info->reason]); NOTICE("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x", rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3, rst_info->excvaddr, rst_info->depc); uint32_t fid = spi_flash_get_id(); NOTICE("Flash map %s, manuf 0x%02lX chip 0x%04lX", flash_maps[system_get_flash_size_map()], fid & 0xff, (fid&0xff00)|((fid>>16)&0xff)); }
// Main routine to initialize esp-link. void user_init(void) { // get the flash config so we know how to init things // configWipe(); // uncomment to reset the config for testing purposes bool restoreOk = configRestore(); // init gpio pin registers gpio_init(); gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled // init UART uart_init(flashConfig.baud_rate, 115200); logInit(); // must come after init of uart // say hello (leave some time to cause break in TX after boot loader's msg os_delay_us(10000L); os_printf("\n\n** %s\n", esp_link_version); os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*"); #if defined(STA_SSID) && defined(STA_PASS) int x = wifi_get_opmode() & 0x3; if (x == 2) { // we only force the STA settings when a full flash of the module has been made, which // resets the wifi settings not to have anything configured struct station_config stconf; wifi_station_get_config(&stconf); if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) { os_strncpy((char*)stconf.ssid, VERS_STR(STA_SSID), 32); os_strncpy((char*)stconf.password, VERS_STR(STA_PASS), 64); #ifdef CGIWIFI_DBG os_printf("Wifi pre-config trying to connect to AP %s pw %s\n", (char*)stconf.ssid, (char*)stconf.password); #endif wifi_set_opmode(3); // sta+ap, will switch to sta-only 15 secs after connecting stconf.bssid_set = 0; wifi_station_set_config(&stconf); } } #endif // Status LEDs statusInit(); serledInit(); // Wifi wifiInit(); // init the flash filesystem with the html stuff espFsInit(&_binary_espfs_img_start); //EspFsInitResult res = espFsInit(&_binary_espfs_img_start); //os_printf("espFsInit %s\n", res?"ERR":"ok"); // mount the http handlers httpdInit(builtInUrls, 80); // init the wifi-serial transparent bridge (port 23) serbridgeInit(23, 2323); uart_add_recv_cb(&serbridgeUartCb); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 10000, 1); #endif struct rst_info *rst_info = system_get_rst_info(); NOTICE("Reset cause: %d=%s", rst_info->reason, rst_codes[rst_info->reason]); NOTICE("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x", rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3, rst_info->excvaddr, rst_info->depc); uint32_t fid = spi_flash_get_id(); NOTICE("Flash map %s, manuf 0x%02lX chip 0x%04lX", flash_maps[system_get_flash_size_map()], fid & 0xff, (fid&0xff00)|((fid>>16)&0xff)); NOTICE("** esp-link ready"); cgiServicesSNTPInit(); #ifdef MQTT NOTICE("initializing MQTT"); mqtt_client_init(); #endif NOTICE("initializing user application"); app_init(); NOTICE("waiting for work to do..."); }
void wifiServerListener() { while (1) { wifiBufferLoop(); if (hasNewLine()) { if (strstr_P(useLineBuffer(), PSTR("+IPD")) != NULL) { // now we parse the request Serial.println(F("Get something, parsing to see if it's http or not")); if (sscanf_P(useLineBuffer(), PSTR("+IPD,%d,%*d:%7s %15s %8s\r"), &linkID, httpMethod, httpPath, httpVer)!=4){ Serial.println(httpMethod); Serial.println(httpPath); Serial.println(httpVer); wifiInitiateSend(linkID); wifiServerSendPGMP(http400, &stream); wifiEndSend(); continue; } if ((!strcmp_P(httpVer, PSTR("HTTP/1.1"))) || (!strcmp_P(httpVer, PSTR("HTTP/1.0")))) { Serial.println(F("It's really a HTTP request")); while (strcmp_P(useLineBuffer(), PSTR("\r")) != 0) wifiBufferLoop(); if (strcmp_P(httpPath, PSTR("/")) == 0) { Serial.println(F("Sending index page")); wifiInitiateSend(linkID); wifiServerSendIndex(&stream); wifiEndSend(); } else if (strcmp_P(httpPath, PSTR("/save")) == 0 && strcmp_P(httpMethod, PSTR("POST")) == 0) { wifiServerSaveConfig(); } else if (strcmp_P(httpPath, PSTR("/currSetting")) == 0) { Serial.println(F("Sending curr setting")); wifiInitiateSend(linkID); wifiServerSendPGMP(http200json, &stream); wifiServerSendConfig(&stream); wifiEndSend(); } else if (strcmp_P(httpPath, PSTR("/restart"))==0){ Serial.println(F("Soft restarting")); wifiInitiateSend(linkID); wifiServerSendPGMP(http200json, &stream); wifiServerSendPGMP(success, &stream); wifiEndSend(); while (1); // just let the watchdog timeout } else { Serial.println(F("Sending 404")); wifiInitiateSend(linkID); wifiServerSendPGMP(http404, &stream); wifiEndSend(); } } else { wifiInitiateSend(linkID); wifiServerSendPGMP(http400, &stream); wifiEndSend(); } } else if (strcmp_P(useLineBuffer(), PSTR("ready\r"))==0){ Serial.println(F("ESP unexpectedly reseted, initializing")); wifiInit(); wifiServerInit(); } } } }