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); } }
void setup() { //serial_begin(115200); uart_init(115200, 115200); os_printf("Noduino Airkiss Example!\r\n"); //SC_TYPE_ESPTOUCH,SC_TYPE_AIRKISS,SC_TYPE_ESPTOUCH_AIRKISS smartconfig_set_type(SC_TYPE_AIRKISS); wifi_set_opmode(STATION_MODE); smartconfig_start(smartconfig_done); }
void ICACHE_FLASH_ATTR cos_check_ip() { struct ip_info ipconfig; static bool smartconfig_started = false; os_timer_disarm(&client_timer); wifi_get_ip_info(STATION_IF, &ipconfig); if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0) { // connect to router success // TODO: notify the cloud I'm online // cloud return the bind state // start broadcast airkiss-nff udp pkg airkiss_nff_start(); smartconfig_started = false; } else { // idle or connecting os_timer_setfn(&client_timer, (os_timer_func_t *)cos_check_ip, NULL); os_timer_arm(&client_timer, 100, 0); if (check_ip_count++ > 50) { // delay 10s, need to start airkiss to reconfig the network // TODO: flash led to show wifi disconnect if(!smartconfig_started) { smartconfig_set_type(SC_TYPE_AIRKISS); wifi_set_opmode(STATION_MODE); smartconfig_start(smartconfig_done); // set smartconfig flag to prevent start again smartconfig_started = true; } // reset the count check_ip_count = 0; } } }