/****************************************************************************** * FunctionName : mesh_FailCb * Description : callback func when mesh init failed(both timeout and failed) *******************************************************************************/ void ICACHE_FLASH_ATTR mesh_FailCb(void* arg) { MESH_INFO("mesh fail\r\n"); mesh_StopCheckTimer(); #if ESP_NOW_SUPPORT //initialize ESP-NOW light_EspnowInit(); #endif MESH_INFO("CALL MESH DISABLE HERE...\r\n"); //stop or disable mesh espconn_mesh_disable(mesh_DisableCb); //open softap interface //mesh_SetSoftap(); //try AP CACHE and connect //WIFI_StartAPScan(); //start Esptouch #if ESP_TOUCH_SUPPORT if(false == esptouch_getAckFlag()){ esptouch_FlowStart(); return; } #endif wifi_RestartMeshScan(5000); return; }
//OTA reboot function void ICACHE_FLASH_ATTR debug_OtaReboot() { #if ESP_MESH_SUPPORT ESP_DBG("deinit for OTA\r\n"); espconn_mesh_disable(NULL); wifi_station_disconnect(); wifi_set_opmode(NULL_MODE); #endif user_esp_clr_upgrade_finish_flag();//clear flag and reboot system_upgrade_flag_set(UPGRADE_FLAG_FINISH); ESP_DBG("call system upgrade reboot...\r\n"); system_upgrade_reboot(); }
void ICACHE_FLASH_ATTR mesh_enable_cb(int8_t res) { MESH_DEMO_PRINT("mesh_enable_cb\n"); if (res == MESH_OP_FAILURE) { MESH_DEMO_PRINT("enable mesh fail, re-enable\n"); espconn_mesh_enable(mesh_enable_cb, MESH_ONLINE); return; } if (espconn_mesh_get_usr_context() && espconn_mesh_is_root() && res == MESH_LOCAL_SUC) goto TEST_SCENARIO; /* * try to estable user virtual connect * user can to use the virtual connect to sent packet to any node, server or mobile. * if you want to sent packet to one node in mesh, please build p2p packet * if you want to sent packet to server/mobile, please build normal packet (uincast packet) * if you want to sent bcast/mcast packet, please build bcast/mcast packet */ MESH_DEMO_MEMSET(&g_ser_conn, 0 ,sizeof(g_ser_conn)); MESH_DEMO_MEMSET(&ser_tcp, 0, sizeof(ser_tcp)); MESH_DEMO_MEMCPY(ser_tcp.remote_ip, server_ip, sizeof(server_ip)); ser_tcp.remote_port = server_port; ser_tcp.local_port = espconn_port(); g_ser_conn.proto.tcp = &ser_tcp; if (espconn_regist_connectcb(&g_ser_conn, esp_mesh_demo_con_cb)) { MESH_DEMO_PRINT("regist con_cb err\n"); espconn_mesh_disable(NULL); return; } if (espconn_regist_recvcb(&g_ser_conn, esp_recv_entrance)) { MESH_DEMO_PRINT("regist recv_cb err\n"); espconn_mesh_disable(NULL); return; } /* * regist the other callback * sent_cb, reconnect_cb, disconnect_cb * if you donn't need the above cb, you donn't need to register them. */ if (espconn_mesh_connect(&g_ser_conn)) { MESH_DEMO_PRINT("connect err\n"); if (espconn_mesh_is_root()) espconn_mesh_enable(mesh_enable_cb, MESH_LOCAL); else espconn_mesh_enable(mesh_enable_cb, MESH_ONLINE); return; } TEST_SCENARIO: mesh_device_list_init(); mesh_topo_test_init(); mesh_json_mcast_test_init(); mesh_json_bcast_test_init(); mesh_json_p2p_test_init(); }