void ICACHE_FLASH_ATTR config_wifi_new(void){ wifi_softap_dhcps_stop(); //vTaskDelay( xDelay ); wifi_set_opmode(NULL_MODE); //vTaskDelay( xDelay ); wifi_set_opmode(SOFTAP_MODE); //vTaskDelay( xDelay ); struct softap_config apConfig; char ssid[8]; wifi_set_event_handler_cb(wifi_event_cb); //mode_info(); memset(apConfig.ssid, 0, sizeof(apConfig.ssid)); sprintf(ssid, "%s\0", WIFI_APSSID); memcpy(apConfig.ssid, ssid, strlen(ssid)); printf("SSID %s\n",apConfig.ssid); apConfig.authmode = AUTH_OPEN; apConfig.channel = 5; apConfig.ssid_len=strlen(ssid); apConfig.max_connection = 255; apConfig.ssid_hidden = 0; wifi_softap_set_config(&apConfig); //vTaskDelay( xDelay ); wifi_softap_dhcps_start(); //vTaskDelay( xDelay*10 ); coap_restart(0); }
void user_init() { struct station_config conf; // This is used to setup the serial communication uart_div_modify(0, UART_CLK_FREQ / 115200); wifi_set_opmode(STATION_MODE); // os_bzero ( &conf, sizeof(struct station_config) ); os_memset ( &conf, 0, sizeof(struct station_config) ); os_memcpy (&conf.ssid, ssid, 32); os_memcpy (&conf.password, pass, 64 ); wifi_station_set_config (&conf); // And this is used to print some information os_printf("\n"); os_printf("SDK version:%s\n", system_get_sdk_version()); system_print_meminfo(); os_delay_us ( 1 ); os_printf ( "CPU Hz = %d\n", system_get_cpu_freq() ); show_mac (); show_ip (); /* set a callback for wifi events */ wifi_set_event_handler_cb ( wifi_event ); }
ESP8266WiFiClass::ESP8266WiFiClass() : _useApMode(false) , _useClientMode(false) , _useStaticIp(false) { wifi_set_event_handler_cb((wifi_event_handler_cb_t)&ESP8266WiFiClass::_eventCallback); }
// Init function void ICACHE_FLASH_ATTR user_init() { struct station_config station_conf; // Enable GPIO gpio_init(); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO0_U, FUNC_GPIO0); gpio_output_set(0, 0, (1<<ELGPIO), 0); // Set station mode wifi_set_opmode_current(STATION_MODE); // Set AP settings os_memcpy(&station_conf.ssid, SSID, 32); os_memcpy(&station_conf.password, SSID_PASSWORD, 64); wifi_station_set_config(&station_conf); // Set an event handler for WiFi events wifi_set_event_handler_cb(wifi_callback); // Setup poll and EL timers, but don't start them yet os_timer_disarm(&poll_timer); os_timer_setfn(&poll_timer, poll_timer_callback, NULL); os_timer_disarm(&el_timer); os_timer_setfn(&el_timer, el_timer_callback, NULL); os_printf("user_init() complete!\n\r"); }
void ICACHE_FLASH_ATTR dhconnector_init(dhconnector_command_json_cb cb) { dhrequest_load_settings(); mCommandCallback = cb; mConnectionState = CS_DISCONNECT; dhrequest_create_info(&mInfoRequest); dhrequest_create_register(&mRegisterRequest); mPollRequest.len = mPollRequest.data[0] = 0; wifi_set_opmode(STATION_MODE); wifi_station_set_auto_connect(1); wifi_station_set_reconnect_policy(true); struct station_config stationConfig; wifi_station_get_config(&stationConfig); wifi_set_phy_mode(PHY_MODE_11N); os_memset(stationConfig.ssid, 0, sizeof(stationConfig.ssid)); os_memset(stationConfig.password, 0, sizeof(stationConfig.password)); snprintf(stationConfig.ssid, sizeof(stationConfig.ssid), "%s", dhsettings_get_wifi_ssid()); snprintf(stationConfig.password, sizeof(stationConfig.password), "%s", dhsettings_get_wifi_password()); wifi_station_set_config(&stationConfig); static esp_tcp tcp; os_memset(&tcp, 0, sizeof(tcp)); os_memset(&mDHConnector, 0, sizeof(mDHConnector)); mDHConnector.type = ESPCONN_TCP; mDHConnector.state = ESPCONN_NONE; mDHConnector.proto.tcp = &tcp; mDHConnector.proto.tcp->local_port = espconn_port(); wifi_set_event_handler_cb(wifi_state_cb); }
void ICACHE_FLASH_ATTR user_init(void) { uart_init(BIT_RATE_115200, BIT_RATE_115200); os_printf("SDK version:%s\n", system_get_sdk_version()); i2c_init(); #ifdef ESP8266OLED oled_init(); #endif key_and_gpio_init(); #ifdef ESP8266DOOR door_switch_init(); #endif wifi_set_event_handler_cb(wifi_handle_event_cb); mqttstart(); #ifdef ESP8266ENVINFO task_send_environment_info_init(); #endif #ifdef ESP8266CARDREAD pn532_init(); pn532_cb_event_init(); #endif struct station_config s_staconf; wifi_station_get_config_default(&s_staconf); if (os_strlen(s_staconf.ssid) == 0) { wifi_set_opmode(STATION_MODE); smartconfig_set_type(SC_TYPE_ESPTOUCH); smartconfig_start(smartconfig_done); } }
/* * 函数:user_wifi_init * 说明:WiFi配置初始化 */ void ICACHE_FLASH_ATTR user_wifi_init(void) { wifi_set_opmode(STATION_MODE); user_set_station_config(WIFI_SSID, WIFI_PASSWORD); wifi_set_event_handler_cb(wifi_handle_event_cb); }
void ICACHE_FLASH_ATTR user_events_init() { wifi_set_event_handler_cb(user_event_wifi); webserver_register_handler_callback(EVENTS_URL, events_handler); #if EVENTS_SYS_TIMER setInterval(user_event_system_timer, NULL, 1000); #endif }
//Init function. This is where the program enters void user_init() { uart_init(BIT_RATE_115200, BIT_RATE_115200); // set the baud rate for UART0 and UART1, I will use UART1 for debugging and UART0 for flashing os_printf("Hello !\n\r"); os_printf("Chip Id: %lu\n\r", system_get_chip_id()); //Prints chip ID os_printf("SDK Version: %s\n\r", system_get_sdk_version()); // Gets the sdk version system_init_done_cb(initDone); wifi_set_event_handler_cb(eventHandler); }
ESP8266WiFiClass::ESP8266WiFiClass() : _smartConfigStarted(false) , _smartConfigDone(false) , _useStaticIp(false) { uint8 m = wifi_get_opmode(); _useClientMode = (m & WIFI_STA); _useApMode = (m & WIFI_AP); wifi_set_event_handler_cb((wifi_event_handler_cb_t)&ESP8266WiFiClass::_eventCallback); }
/****************************************************************************** * FunctionName : user_init * Description : entry of user application, init user function here * Parameters : none * Returns : none *******************************************************************************/ void ICACHE_FLASH_ATTR user_init(void) { if(eraminfo.size > 0) os_printf("Found free IRAM: base: %p, size: %d bytes\n", eraminfo.base, eraminfo.size); os_printf("System memory:\n"); system_print_meminfo(); os_printf("bssi : 0x%x ~ 0x%x, len: %d\n", &_lit4_start, &_lit4_end, (uint32)(&_lit4_end) - (uint32)(&_lit4_start)); os_printf("free : 0x%x ~ 0x%x, len: %d\n", (uint32)(&_lit4_end), (uint32)(eraminfo.base) + eraminfo.size, (uint32)(eraminfo.base) + eraminfo.size - (uint32)(&_lit4_end)); os_printf("Start 'heap' size: %d bytes\n", system_get_free_heap_size()); os_printf("Set CPU CLK: %u MHz\n", ets_get_cpu_frequency()); system_deep_sleep_set_option(0); wifi_set_event_handler_cb(wifi_handle_event_cb); system_init_done_cb(init_done_cb); }
//Init function void ICACHE_FLASH_ATTR user_init() { //uart_div_modify(0, UART_CLK_FREQ / 115200); system_set_os_print(1); uart_init(BIT_RATE_115200, BIT_RATE_115200); os_printf("Hello !\n\r"); os_printf("Chip Id: %lu\n\r", system_get_chip_id()); os_printf("SDK Version: %s\n\r", system_get_sdk_version()); system_init_done_cb(initDone); wifi_set_event_handler_cb(eventHandler); }
void do_stuff() { #if !defined(ESP_ENABLE_HW_WATCHDOG) && !defined(RTOS_TODO) ets_wdt_disable(); #endif pp_soft_wdt_stop(); last_ts = system_get_time(); wifi_set_event_handler_cb(x_wifi_changed_cb); sj_wifi_setup_sta("TehCloud", ""); mg_mgr_init(&s_mgr, NULL); }
static void wifi_connect() { struct station_config conf; wifi_station_set_auto_connect(FALSE); wifi_set_event_handler_cb(wifi_change_cb); strcpy((char *) conf.ssid, NETWORK_SSID); strcpy((char *) conf.password, NETWORK_PWD); printf("connecting to %s\n", conf.ssid); conf.bssid_set = 0; wifi_set_opmode_current(STATION_MODE); wifi_station_disconnect(); wifi_station_set_config_current(&conf); wifi_station_connect(); }
/*JSON{ "type" : "staticmethod", "class" : "ESP8266WiFi", "name" : "init", "generate" : "jswrap_ESP8266WiFi_init" }*/ void jswrap_ESP8266WiFi_init() { os_printf("> jswrap_ESP8266WiFi_init\n"); // register the state change handler so we get debug printout for sure wifi_set_phy_mode(2); wifi_set_event_handler_cb(wifiEventHandler); os_printf("Wifi init, mode=%d\n", wifi_get_opmode()); wifi_station_set_hostname("espruino"); netInit_esp8266_board(); setupJsNetwork(); networkState = NETWORKSTATE_ONLINE; os_printf("< jswrap_ESP8266WiFi_init\n"); }
void ICACHE_FLASH_ATTR user_init(void) { uart_div_modify(0, UART_CLK_FREQ / BAUD); os_printf("Startup\r\n"); /*** Initialize subsystems ***/ psu_init(); ws2811dma_init(); wifi_init(); mxp_init(ws2811dma_put); psu_server_init(); /*** Use LED strip as status indicator ***/ wifi_set_event_handler_cb(onWifiEvent); status_indicate(STAT_NO_CONNECT); }
/* Setup the Acess point settings */ void ICACHE_FLASH_ATTR user_set_station_config(void) { struct station_config stationConf; wifi_set_opmode(0x01); // Set AP, Station or Both mode stationConf.bssid_set = 0; //need not check MAC address of AP os_memcpy(&stationConf.ssid, SSID, 32); os_memcpy(&stationConf.password, PASSWORD, 64); wifi_station_set_config(&stationConf); wifi_set_event_handler_cb(wifi_handle_event_cb); }
//////////////////////////////////////////////////////////////////// // connectWiFi() - Connects to SSID and PASSWORD in user_config.h // //////////////////////////////////////////////////////////////////// void connectWiFi(void) { wifi_set_opmode(STATION_MODE); // Set into station mode // Create a station_config struct, and fill it with our SSID and Password struct station_config config; bzero(&config, sizeof(struct station_config)); // Zero it out first sprintf(config.ssid, SSID); // Put the SSID in sprintf(config.password, PASSWORD); // Put the password in // Put our new config struct into the wifi_station_set_config function wifi_station_set_config(&config); // Set up a callback function for any WiFi event wifi_set_event_handler_cb(wifi_event_handler_cb); }
void dispatch_init2(void) { int io, pin; unsigned int cmd_port, uart_port; if(config_get_int("trigger.status.io", &io, -1, -1) && config_get_int("trigger.status.pin", &pin, -1, -1)) { trigger_alert.io = io; trigger_alert.pin = pin; } if(config_get_int("trigger.assoc.io", &io, -1, -1) && config_get_int("trigger.assoc.pin", &pin, -1, -1)) { assoc_alert.io = io; assoc_alert.pin = pin; } if(!config_get_uint("cmd.port", &cmd_port, -1, -1)) cmd_port = 24; if(!config_get_uint("bridge.port", &uart_port, -1, -1)) uart_port = 0; wifi_set_event_handler_cb(wlan_event_handler); command_left_to_read = 0; lwip_if_socket_create(&command_socket, &command_socket_receive_buffer, &command_socket_send_buffer, cmd_port, true, config_flags_match(flag_udp_term_empty), socket_command_callback_data_received); if(uart_port > 0) { lwip_if_socket_create(&uart_socket, &uart_socket_receive_buffer, &uart_socket_send_buffer, uart_port, true, config_flags_match(flag_udp_term_empty), socket_uart_callback_data_received); uart_bridge_active = true; } os_timer_setfn(&slow_timer, slow_timer_callback, (void *)0); os_timer_arm(&slow_timer, 100, 1); // slow system timer / 10 Hz / 100 ms os_timer_setfn(&fast_timer, fast_timer_callback, (void *)0); os_timer_arm(&fast_timer, 10, 1); // fast system timer / 100 Hz / 10 ms dispatch_post_command(command_task_init_displays); }
// Init the wireless, which consists of setting a timer if we expect to connect to an AP // so we can revert to STA+AP mode if we can't connect. void ICACHE_FLASH_ATTR wifiInit() { // wifi_set_phy_mode(2); // limit to 802.11b/g 'cause n is flaky int x = wifi_get_opmode() & 0x3; DBG("Wifi init, mode=%s\n", wifiMode[x]); configWifiIP(); // The default sleep mode should be modem_sleep, but we set it here explicitly for good // measure. We can't use light_sleep because that powers off everthing and we would loose // all connections. wifi_set_sleep_type(MODEM_SLEEP_T); wifi_set_event_handler_cb(wifiHandleEventCb); // check on the wifi in a few seconds to see whether we need to switch mode os_timer_disarm(&resetTimer); os_timer_setfn(&resetTimer, resetTimerCb, NULL); os_timer_arm(&resetTimer, RESET_TIMEOUT, 0); }
void ICACHE_FLASH_ATTR user_init(void) { stdout_init(); printf("\n"); bzero(bots, sizeof(bots)); bzero(&bridge, sizeof(bridge)); #ifdef USE_SECURE //espconn_secure_ca_enable(0x01, 0x3C); #endif wifi_set_event_handler_cb(wifiEventHandlerCb); #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); os_timer_arm(&prHeapTimer, 3000, 1); #endif printf("\nReady\n"); }
bool ICACHE_FLASH_ATTR hap_init() { settings_load(); httpd_register(index_httpd_request); static ETSTimer upTimeTimer; os_timer_disarm(&upTimeTimer); os_timer_setfn(&upTimeTimer, (os_timer_func_t *)uptimeIncrement, NULL); os_timer_arm(&upTimeTimer, 1000, 1); wifi_set_event_handler_cb(onWifiEvent); bool result; if (!settings_valid()) { DEBUG_PRINT("[HAP]Settings not valid, using defaults, starting AP\n"); settings.password[0] = 0; settings.ssid[0] = 0; strcpy(settings.serverName, "hap_server"); strcpy(settings.mqttUser, "user"); strcpy(settings.mqttPassword, "password"); strcpy(settings.mqttTopic, "topic"); settings.udpPort = 5100; char aux[20]; os_sprintf(aux, "hap_%d", system_get_chip_id()); result = setup_wifi_ap_mode(aux); } else { DEBUG_PRINT("[HAP]Settings valid, connecting to AP %s\n", settings.ssid); udp_init(); result = setup_wifi_st_mode(settings.ssid, settings.password); } if (result) httpd_init(80); return result; }
void ICACHE_FLASH_ATTR user_init(void) { #ifndef NDEBUG uart_init(9600, 9600); #endif gpio_init(); /* set GPIO0 and GPIO2 as HIGH outputs */ gpio_output_set(GPIO0 | GPIO2, 0, GPIO0 | GPIO2, 0); /* select GPIO2 function for GPIO2 pin */ PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2); PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U); wifi_set_event_handler_cb(wifi_event_handler); client_connection_setup(); }
void WifiClass::begin(WifiStateChangeDelegate dlg) { changeDlg = dlg; if (AppSettings.exist()) { if (AppSettings.ssid.equals("") && !WifiStation.getSSID().equals("")) { AppSettings.ssid = WifiStation.getSSID(); AppSettings.password = WifiStation.getPassword(); AppSettings.save(); } WifiStation.config(AppSettings.ssid, AppSettings.password); if (!AppSettings.dhcp && !AppSettings.ip.isNull()) { WifiStation.setIP(AppSettings.ip, AppSettings.netmask, AppSettings.gateway); } } else { String SSID = WifiStation.getSSID(); if (!SSID.equals("")) { AppSettings.ssid = SSID; AppSettings.password = WifiStation.getPassword(); AppSettings.save(); } } wifi_set_event_handler_cb(wifi_cb); WifiStation.enable(true); softApEnable(); otaEnable(); }
void ICACHE_FLASH_ATTR configure(void){ restartActive=0; struct station_config st_config; memset(st_config.ssid, 0, sizeof(st_config.ssid)); memcpy(st_config.ssid, ssid_name, strlen(ssid_name)); //st_config.ssid_len=strlen(ssid_name); memset(st_config.password, 0, sizeof(st_config.password)); memcpy(st_config.password, password, strlen(password)); // if(!isnew){ memset(user_config.ssid, 0, sizeof(user_config.ssid)); memcpy(user_config.ssid, ssid_name, strlen(ssid_name)); memset(user_config.pwd, 0, sizeof(user_config.pwd)); memcpy(user_config.pwd, password, strlen(password)); // } printf("STA config: SSID: %s, PASSWORD: %s\r\n",st_config.ssid,st_config.password ); printf("info: SSID: %s, PASSWORD: %s\r\n",ssid_name,password ); int ch; wifi_softap_dhcps_stop(); wifi_set_event_handler_cb(wifi_event_cb); //vTaskDelay( xDelay ); wifi_set_opmode(NULL_MODE); vTaskDelay( xDelay ); //save_user_config(&user_config); wifi_set_opmode(STATION_MODE); //vTaskDelay( xDelay ); wifi_station_set_config_current(&st_config); // int ret = wifi_station_set_auto_connect(1); //vTaskDelay( xDelay ); wifi_station_connect(); //vTaskDelay( xDelay ); wifi_station_dhcpc_start(); //vTaskDelay( 100 ); //vTaskDelay( 100 ); coap_restart(1); }
//Init function void ICACHE_FLASH_ATTR user_init() { // WiFi creds char ssid[32] = SSID; char password[64] = SSID_PASSWORD; struct station_config stationConf; // UART PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_U1TXD); // Necessary? uart_init(BIT_RATE_115200, BIT_RATE_115200); uart0_sendStr("UART Online!"); os_printf("OS Online!"); // ADC // No initialization needed? // Timer os_timer_setfn(&adc_timer, read_adc, NULL); // Call-back to read_adc os_timer_arm(&adc_timer, 1000, 1); // Repeating 1000 ms timer //Set station mode wifi_set_opmode( 0x1 ); //Set ap settings os_memcpy(&stationConf.ssid, ssid, 32); os_memcpy(&stationConf.password, password, 64); wifi_station_set_config(&stationConf); // When wifi connects, callback wifi_set_event_handler_cb(wifi_cb); //Start os task //system_os_task(loop, user_procTaskPrio,user_procTaskQueue, // user_procTaskQueueLen); }
void ICACHE_FLASH_ATTR init_wifi(void) { char ssid[32] = SSID; char password[64] = SSID_PASSWORD; struct station_config config; //wifi_station_set_hostname("ds18b20"); wifi_set_opmode(STATION_MODE); wifi_station_set_reconnect_policy(false); config.bssid_set = 0; os_memcpy(&config.ssid, ssid, sizeof ssid); os_memcpy(&config.password, password, sizeof password); wifi_station_set_config(&config); wifi_set_event_handler_cb(wifi_callback); IP4_ADDR(&dnsserver, 8,8,8,8); espconn_dns_setserver(0, &dnsserver); os_printf("%s : init_wifi OK.\n", __FUNCTION__); }
void ICACHE_FLASH_ATTR user_events_init() { wifi_set_event_handler_cb(user_event_wifi); webserver_register_handler_callback(EVENTS_URL, events_handler); }
ESP8266WiFiGenericClass::ESP8266WiFiGenericClass() { wifi_set_event_handler_cb((wifi_event_handler_cb_t) &ESP8266WiFiGenericClass::_eventCallback); }
static void _esp_wifi_setup(void) { esp_wifi_netdev_t* dev = &_esp_wifi_dev; ESP_WIFI_DEBUG("%p", dev); if (dev->netdev.driver) { ESP_WIFI_DEBUG("early returning previously initialized device"); return; } /* initialize netdev data structure */ dev->rx_len = 0; dev->state = ESP_WIFI_DISCONNECTED; dev->event = EVENT_MAX; /* set the netdev driver */ dev->netdev.driver = &_esp_wifi_driver; #ifndef MODULE_ESP_NOW /* set the WiFi interface mode */ if (!wifi_set_opmode_current(ESP_WIFI_MODE)) { ESP_WIFI_LOG_ERROR("could not set WiFi working mode"); return; } /* set the WiFi SoftAP configuration */ if (!wifi_softap_set_config_current((struct softap_config *)&softap_cfg)) { ESP_WIFI_LOG_ERROR("could not set WiFi configuration"); return; } #endif /* set the WiFi station configuration */ if (!wifi_station_set_config_current((struct station_config *)&station_cfg)) { ESP_WIFI_LOG_ERROR("could not set WiFi configuration"); return; } /* get station mac address and store it in device address */ if (!wifi_get_macaddr(ESP_WIFI_STATION_IF, dev->mac)) { ESP_WIFI_LOG_ERROR("could not get MAC address of WiFi interface"); return; } ESP_WIFI_DEBUG("own MAC addr is " MAC_STR, MAC_STR_ARG(dev->mac)); /* set auto reconnect policy */ wifi_station_set_reconnect_policy(true); wifi_station_set_auto_connect(true); /* register callbacks */ wifi_set_event_handler_cb(_esp_wifi_handle_event_cb); /* reconnect timer initialization */ _esp_wifi_reconnect_timer.callback = &_esp_wifi_reconnect_timer_cb; _esp_wifi_reconnect_timer.arg = dev; /* set the the reconnect timer */ xtimer_set(&_esp_wifi_reconnect_timer, ESP_WIFI_RECONNECT_TIME); /* avoid the WiFi modem going into sleep mode */ wifi_set_sleep_type(NONE_SLEEP_T); /* connect */ wifi_station_connect(); _esp_wifi_dev.state = ESP_WIFI_CONNECTING; return; }