//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { wifi_station_set_auto_connect(FALSE); stdoutInit(); CFG_Load(); ioInit(); MAIN_DEBUG("\nInitialise ENC stack, dhcp if requested\n"); stack_init(); /* This DNS is only for the wifi interface, as wired never acts as an 'AP' */ captdnsInit(); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. #ifdef ESPFS_POS espFsInit((void*)(0x40200000 + ESPFS_POS)); #else espFsInit((void*)(webpages_espfs_start)); #endif httpdInit(builtInUrls, 80); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 3000, 1); #endif os_timer_disarm(&websockTimer); os_timer_setfn(&websockTimer, websockTimerCb, NULL); os_timer_arm(&websockTimer, 1000, 1); os_printf("\nReady\n"); }
/*** Main function ***/ void ICACHE_FLASH_ATTR user_init() { uart_div_modify(0, UART_CLK_FREQ / BAUD); os_printf("Startup from %d...\r\n", system_get_rst_info()->reason); gpio_init(); ap_init(); // HTTPD espFsInit((void*)(webpages_espfs_start)); httpdInit(builtInUrls, 80); // Set GPIO2 (DCF77 pin) to input, disable pullup gpio_output_set(0, 0, 0, 2); PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U); // DCF77 read timer os_timer_disarm(&dcf_read_timer); os_timer_setfn(&dcf_read_timer, (os_timer_func_t *) dcf_read_timer_cb, NULL); os_timer_arm(&dcf_read_timer, 5, 1); // Second increase timer os_timer_disarm(&time_inc_timer); os_timer_setfn(&time_inc_timer, (os_timer_func_t *) time_inc_timer_cb, NULL); os_timer_arm(&time_inc_timer, 1000, 1); // DCF77 decode timer: decide wheter 1 or 0 dcf_decode_timer_adjust(); os_printf(" completed!\r\n\r\n"); system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen); system_os_post(user_procTaskPrio, 0, 0); }
void doWork(void *ignore) { char buff[5*1024]; ESP_LOGD(tag, "Flash address is 0x%x", (int)flashAddress); if (espFsInit(flashAddress, 64*1024) != ESPFS_INIT_RESULT_OK) { ESP_LOGD(tag, "Failed to initialize espfs"); return; } EspFsFile *fh = espFsOpen("files/test3.txt");; if (fh != NULL) { int sizeRead = 0; sizeRead = espFsRead(fh, buff, sizeof(buff)); ESP_LOGD(tag, "Result: %.*s", sizeRead, buff); size_t fileSize; char *data; sizeRead = espFsAccess(fh, (void **)&data, &fileSize); ESP_LOGD(tag, "Result from access: %.*s", fileSize, data); espFsClose(fh); vTaskDelete(NULL); } }
void ICACHE_FLASH_ATTR user_init(void) { uart0_init(BIT_RATE_74880); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. espFsInit((void*)(0x40200000 + ESPFS_POS)); httpdInit(builtInUrls, 80); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 3000, 1); #endif init_relay(); os_timer_disarm(&startup_timer); os_timer_setfn(&startup_timer, (os_timer_func_t *)onesec, (void *)0); os_timer_arm(&startup_timer, 1000, 1); os_timer_disarm(&delayed_start_timer); os_timer_setfn(&delayed_start_timer, (os_timer_func_t *)delayed_start, (void *)0); os_timer_arm(&delayed_start_timer, 500, 1); load_config(); os_printf("running\n"); }
// Main routine, initialize some basic stuff void ICACHE_FLASH_ATTR user_init(void) { // Init some stuff stdoutInit(); batteryInit(); configInit(); configLoad(); // Check if wifi mode is correct configCheckWifiMode(); // Measure battery voltage batteryMeasureVoltage(); if(!batteryCheckVoltage()) { // Voltage too low, go to sleep mode! sleepmode(); } // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. espFsInit((void*)(0x40200000 + ESPFS_POS)); httpdInit(builtInUrls, 80); // Register callback system_init_done_cb(init_done); os_printf("Ready\n"); }
void user_init(void) { stdout_init(); io_init(); dht_init(SENSORTYPE, POOLTIME); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. #ifdef ESPFS_POS espFsInit((void*)(0x40200000 + ESPFS_POS)); #else espFsInit((void*)(webpages_espfs_start)); #endif httpdInit(builtInUrls, 80); wifi_init(); config_init(); action_init(); os_printf("\nESP Ready\n"); }
// 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..."); }
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { stdoutInit(); ioInit(); captdnsInit(); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. #ifdef ESPFS_POS espFsInit((void*)(0x40200000 + ESPFS_POS)); #else espFsInit((void*)(webpages_espfs_start)); #endif httpdInit(builtInUrls, 80); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 3000, 1); #endif os_printf("\nReady\n"); }
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done. void user_init(void) { mmInit(mmData); //Redirect stdout to websocket os_install_putc1((void *)stdoutPutcharWs); ioInit(); captdnsInit(); telnetInit(333); // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position // where image is written in flash that is defined in Makefile. #ifdef ESPFS_POS espFsInit((void*)(0x40200000 + ESPFS_POS)); #else espFsInit((void*)(webpages_espfs_start)); #endif httpdInit(builtInUrls, 80); os_timer_disarm(&websockTimer); os_timer_setfn(&websockTimer, websockTimerCb, NULL); os_timer_arm(&websockTimer, 1000, 1); os_printf("\nReady\n"); wifi_set_sleep_type(LIGHT_SLEEP_T); }
//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"); }
/*The main working flow of this demo: a. start mesh function, searching for existing mesh network b. if there is no mesh network, search AP cache to connect to a recorded router. c. If we still failed to establish a connection, start ESP-TOUCH wait for configure. d. If ESP-TOUCH time out, re-search mesh network and AP CACHE. e. During the whole procedure,we can control and configure the light via a restful webserver. f. ESP-NOW is the recently released function to control the light without any WiFi connection.You can find it in app_switch */ void ICACHE_FLASH_ATTR light_main_flow() { #if ESP_NOW_SUPPORT /*We have added esp-now feature in the light project */ /*So that the lights in a certain MAC group can be easily controlled by an ESP-NOW controller*/ /*The sample code is in APP_CONTROLLER/APP_SWITCH*/ sp_MacInit();//csc add button Mac add and delet light_EspnowInit(); #endif #if 1 #if ESP_PLATFORM /*Initialization of the peripheral drivers*/ /*For light demo , it is user_light_init();*/ /* Also check whether assigned ip addr by the router.If so, connect to ESP-server */ user_esp_platform_init_peripheral(); disp_heap(5); #endif /*Establish a udp socket to receive local device detect info.*/ /*Listen to the port 1025, as well as udp broadcast. /*If receive a string of device_find_request, it reply its IP address and MAC.*/ user_devicefind_init(); disp_heap(6); /*Establish a TCP server for http(with JSON) POST or GET command to communicate with the device.*/ /*You can find the command in "2B-SDK-Espressif IoT Demo.pdf" to see the details.*/ /*the JSON command for curl is like:*/ /*3 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000}}" http://192.168.4.1/config?command=light */ /*5 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000,\"cwhite\":3000,\"wwhite\",3000}}" http://192.168.4.1/config?command=light */ /***********NOTE!!**************/ /*in MESH mode, you need to add "sip","sport" and "mdev_mac" fields to send command to the desired device*/ /*see details in MESH documentation*/ /*MESH INTERFACE IS AT PORT 8000*/ #if ESP_WEB_SUPPORT //Initialize DNS server for captive portal //captdnsInit(); //Initialize espfs containing static webpages espFsInit((void*)(webpages_espfs_start)); //Initialize webserver httpdInit(builtInUrls, SERVER_PORT); //user_webserver_init(SERVER_PORT); #else #ifdef SERVER_SSL_ENABLE user_webserver_init(SERVER_SSL_PORT); #else user_webserver_init(SERVER_PORT); #endif #endif #endif ////simplepair_test();//debug only //In debug mode, if you restart the light within 2 seconds, it will get into softap mode and wait for local upgrading firmware. //Restart again, it will clear the system param and set to default status. #if ESP_DEBUG_MODE extern struct esp_platform_saved_param esp_param; if(esp_param.reset_flg == MODE_APMODE){ os_printf("==================\r\n"); os_printf("RESET FLG==2,STATIONAP_MODE \r\n"); os_printf("==================\r\n"); #if ESP_MESH_SUPPORT user_DeviceFindRespSet(false); #endif struct softap_config config_softap; char ssid[33]={0}; wifi_softap_get_config(&config_softap); os_memset(config_softap.password, 0, sizeof(config_softap.password)); os_memset(config_softap.ssid, 0, sizeof(config_softap.ssid)); os_sprintf(ssid,"ESP_%06X",system_get_chip_id()); os_memcpy(config_softap.ssid, ssid, os_strlen(ssid)); config_softap.ssid_len = os_strlen(ssid); config_softap.authmode = AUTH_OPEN; wifi_softap_set_config(&config_softap); os_printf("SET STATION-AP MODE\r\n"); //wifi_set_opmode(STATIONAP_MODE); wifi_set_opmode(STATIONAP_MODE); user_esp_platform_set_reset_flg(MODE_RESET); os_timer_disarm(&reset_flg_t); os_timer_setfn(&reset_flg_t,user_esp_platform_set_reset_flg,MODE_NORMAL); os_timer_arm(&reset_flg_t,2000,0); user_light_set_duty(0, LIGHT_RED); user_light_set_duty(0, LIGHT_GREEN); user_light_set_duty(0, LIGHT_BLUE); user_light_set_duty(22222, LIGHT_WARM_WHITE); user_light_set_duty(22222, LIGHT_COLD_WHITE); os_delay_us(5000); light_ShowDevLevel(5); return; } #if ESP_RESET_DEBUG_EN else if(esp_param.reset_flg == MODE_RESET){ os_printf("==================\r\n"); os_printf("RESET FLG==1,RESET IN 200 MS \r\n"); os_printf("==================\r\n"); user_esp_platform_set_reset_flg(MODE_APMODE); os_timer_disarm(&reset_flg_t); os_timer_setfn(&reset_flg_t,user_esp_platform_reset_default,0); os_timer_arm(&reset_flg_t,200,0); } else{ os_printf("==================\r\n"); os_printf("RESET FLG==0,NORMAL MODE \r\n"); os_printf("==================\r\n"); user_esp_platform_set_reset_flg(MODE_APMODE); os_timer_disarm(&reset_flg_t); os_timer_setfn(&reset_flg_t,user_esp_platform_set_reset_flg,0); os_timer_arm(&reset_flg_t,2000,0); } #endif #endif #if ESP_MESH_SUPPORT /*initialize mesh network. 1. search for existing mesh. 2. if failed , try connecting recorded router. */ //user_MeshSetInfo(); user_MeshInit(); #elif ESP_TOUCH_SUPPORT esptouch_FlowStart(); #endif }
// 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..."); }