/****************************************************************************** * FunctionName : esptouch_FailCb * Description : esp-touch fail callback *******************************************************************************/ void ICACHE_FLASH_ATTR esptouch_FailCb(void* data) { wifi_station_disconnect(); smartconfig_stop(); //wifi_set_opmode(STATIONAP_MODE); SC_INFO("ESP-TOUCH FAIL \r\n"); os_timer_disarm(&esptouch_tout_t); #if LIGHT_DEVICE light_shadeStart(HINT_RED,2000,0,1,NULL); #endif SC_INFO("ENABLE LIGHT ACTION(ESP-NOW)"); os_printf("debug: channel:%d\r\n",wifi_get_channel()); #if ESP_NOW_SUPPORT light_EspnowInit(); #endif #if ESP_MESH_SUPPORT SC_INFO("RESTART MESH NOW...\r\n"); #if LIGHT_DEVICE light_hint_stop(HINT_RED); #endif //user_MeshStart(); wifi_RestartMeshScan(5000); #else SC_INFO("ESP-TOUCH FAIL, OPEN WEBSERVER NOW"); mesh_SetSoftap();//check #endif }
/****************************************************************************** * FunctionName : esptouch_StartCb * Description : esp-touch start callback *******************************************************************************/ void ICACHE_FLASH_ATTR esptouch_StartCb(void* para) { SC_INFO("LIGHT SHADE & START ESP-TOUCH"); #if LIGHT_DEVICE light_shadeStart(HINT_GREEN,1000,0,1,NULL); #endif }
void ICACHE_FLASH_ATTR light_ShowDevLevel_t(void* mlevel_t) { uint32 mlevel = (uint32)mlevel_t; light_hint_abort(); uint32 color = HINT_WHITE; switch(mlevel){ case 1: color = HINT_WHITE; break; case 2: color = HINT_RED; break; case 3: color = HINT_GREEN; break; case 4: color = HINT_BLUE; break; case 5: //level 5: PURPLE color = HINT_PURPLE; break; case 6: //level 6: YELLOW color = HINT_YELLOW; break; default: color = HINT_WHITE; break; } light_shadeStart(color,500,mlevel,1,NULL); #if ESP_DEBUG_MODE os_timer_disarm(&light_recover_t); os_timer_setfn(&light_recover_t,light_ColorRecover,NULL); os_timer_arm(&light_recover_t,15000,0); #endif }
void ICACHE_FLASH_ATTR sp_LightPairState(void) { #if 1 switch(light_state){ case (SP_LIGHT_IDLE): os_printf("status:SP_LIGHT_IDLE\n"); //pair start command, correct if(USER_PBULIC_BUTTON_INFO==buttonPairingInfo.simple_pair_state){ os_printf("statue:Get button Info,next wait button request\n"); sp_LightPairTimerStart(); sp_LightPairAccept(); light_state=SP_LIGHT_WAIT_BUTTON_REQUEST; light_shadeStart(HINT_WHITE,500,3,1,NULL); } //exception else{ light_state=SP_LIGHT_ERROR_HANDLE; light_hint_stop(HINT_RED); os_printf("buttonPairingInfo.simple_pair_state=%d\n",buttonPairingInfo.simple_pair_state); sp_LightPairState(); } break; case (SP_LIGHT_WAIT_BUTTON_REQUEST): os_printf("status:SP_LIGHT_WAIT_BUTTON_REQUEST\n"); light_shadeStart(HINT_GREEN,500,3,0,NULL); //receive button pair request, send req to phone if(LIGHT_RECV_BUTTON_REQUSET==buttonPairingInfo.simple_pair_state){ os_printf("statue:Get button request,next wait user permit or refuse\n"); sp_LightPairRequestPermission(); light_state=SP_LIGHT_WAIT_USER_INDICATE_PERMIT; } //receive pair start command again before timeout , right now, restart state machine else if(USER_PBULIC_BUTTON_INFO==buttonPairingInfo.simple_pair_state){ os_printf("statue:Get button Info,restart state machine,wait button request\n"); sp_LightPairTimerStart(); sp_LightPairAccept(); light_state=SP_LIGHT_WAIT_BUTTON_REQUEST; } //error if other states else{ //simple_pair_deinit(); light_state=SP_LIGHT_ERROR_HANDLE; light_hint_stop(HINT_RED); os_printf("err in SP_LIGHT_WAIT_BUTTON_REQUEST ;simple_pair_state=%d\n",buttonPairingInfo.simple_pair_state); sp_LightPairState(); } break; case (SP_LIGHT_WAIT_USER_INDICATE_PERMIT): light_shadeStart(HINT_BLUE,500,3,0,NULL); os_printf("status:SP_LIGHT_WAIT_USER_INDICATE_PERMIT\n"); //phone user permit pairing if(USER_PERMIT_SIMPLE_PAIR==buttonPairingInfo.simple_pair_state){ os_printf("statue:User permit simple pair,next wait simple result\n"); sp_PairedDevRmAll(&PairedDev);// sp_LightPairStart(); light_state=SP_LIGHT_WAIT_SIMPLE_PAIR_RESULT; } //phone user refuse pairing, END else if(USER_REFUSE_SIMPLE_PAIR==buttonPairingInfo.simple_pair_state){ os_printf("statue:User refuse simple pair,state clear\n"); //check state sp_LightPairRefuse(); //light_state=SP_LIGHT_IDLE; //buttonPairingInfo.simple_pair_state=LIGHT_PAIR_IDLE; light_state = SP_LIGHT_END; light_shadeStart(HINT_RED,500,2,0,NULL); sp_LightPairState(); } //exceptions else{ //simple_pair_deinit(); light_state=SP_LIGHT_ERROR_HANDLE; light_hint_stop(HINT_RED); os_printf("buttonPairingInfo.simple_pair_state=%d\n",buttonPairingInfo.simple_pair_state); sp_LightPairState(); } break; case (SP_LIGHT_WAIT_SIMPLE_PAIR_RESULT): os_printf("status:SP_LIGHT_WAIT_SIMPLE_PAIR_RESULT\n"); //pairing finished , END if(LIGHT_SIMPLE_PAIR_SUCCED==buttonPairingInfo.simple_pair_state){ os_printf("status:sp_LightPairSucced\n"); light_shadeStart(HINT_WHITE,500,2,0,NULL); //1.get key //buttonPairingInfo.espnowKey //2.add peer and save int res = esp_now_add_peer((uint8*)(buttonPairingInfo.button_mac), (uint8)ESP_NOW_ROLE_CONTROLLER,(uint8)wifi_get_channel(), (uint8*)(buttonPairingInfo.espnowKey), (uint8)ESPNOW_KEY_LEN); os_printf("INIT RES: %d ; MAC:"MACSTR"\r\n",res,MAC2STR(((uint8*)(buttonPairingInfo.button_mac)))); //3.save sp_AddPairedDev(&PairedDev,buttonPairingInfo.button_mac,buttonPairingInfo.espnowKey,wifi_get_channel()); sp_DispPairedDev(&PairedDev); //simple_pair_deinit();//check //light_state=SP_LIGHT_IDLE; //buttonPairingInfo.simple_pair_state=LIGHT_PAIR_IDLE; sp_LightPairReportResult(true); light_state = SP_LIGHT_END; sp_LightPairState(); } //pairing failed , END else if(LIGHT_SIMPLE_PAIR_FAIL==buttonPairingInfo.simple_pair_state){ os_printf("status:sp_LightPairFail\n"); //simple_pair_deinit();//check //light_state=SP_LIGHT_IDLE; //buttonPairingInfo.simple_pair_state=LIGHT_PAIR_IDLE; sp_LightPairReportResult(false); light_state = SP_LIGHT_END; light_hint_stop(HINT_RED); sp_LightPairState(); } //exception else{ simple_pair_deinit(); light_hint_stop(HINT_RED); light_state=SP_LIGHT_ERROR_HANDLE; os_printf("buttonPairingInfo.simple_pair_state=%d\n",buttonPairingInfo.simple_pair_state); sp_LightPairState(); } break; case (SP_LIGHT_ERROR_HANDLE): os_printf("status:simpaire in Err!!!\r\nBACK TO IDLE\r\n"); light_hint_stop(HINT_RED); case (SP_LIGHT_END): //reset state, deinit simplepair, stop tout timer sp_LightPairTimerStop(); simple_pair_deinit(); light_state=SP_LIGHT_IDLE; buttonPairingInfo.simple_pair_state=LIGHT_PAIR_IDLE; sp_PairedDevLoadAll(&PairedDev); break; default: os_printf("status:unsafe param: %d\n",light_state); break; } #endif }
void ICACHE_FLASH_ATTR light_Espnow_ShowSyncSuc() { light_shadeStart(HINT_WHITE,500,2,1,NULL); }
/****************************************************************************** * FunctionName : esptouch_ProcCb * Description : esp-touch status change callback for smartconfig_start *******************************************************************************/ LOCAL void ICACHE_FLASH_ATTR esptouch_ProcCb(sc_status status, void *pdata) { switch(status) { case SC_STATUS_WAIT: SC_INFO("SC_STATUS_WAIT\n"); break; case SC_STATUS_FIND_CHANNEL: SC_INFO("SC_STATUS_FIND_CHANNEL\n"); if(esptouch_proc.esptouch_start_cb){ esptouch_proc.esptouch_start_cb(NULL); } break; case SC_STATUS_GETTING_SSID_PSWD: SC_INFO("SC_STATUS_GETTING_SSID_PSWD\n"); #if LIGHT_DEVICE light_shadeStart(HINT_BLUE,1000,0,1,NULL); #endif if(esptouch_proc.esptouch_fail_cb){ os_timer_disarm(&esptouch_tout_t); os_timer_setfn(&esptouch_tout_t,esptouch_proc.esptouch_fail_cb,NULL); os_timer_arm(&esptouch_tout_t,ESP_TOUCH_TIMEOUT_MS,0); } break; case SC_STATUS_LINK: SC_INFO("SC_STATUS_LINK\n"); struct station_config *sta_conf = pdata; //os_printf(); wifi_station_set_config(sta_conf); wifi_station_disconnect(); //wifi_station_disconnect(); //====================== #if ESP_MESH_SUPPORT //mesh_enable_task(); //user_MeshStart(); //user_esp_platform_connect_ap_cb(); #endif //====================== wifi_station_connect(); os_timer_disarm(&esptouch_tout_t); os_timer_arm(&esptouch_tout_t,ESPTOUCH_CONNECT_TIMEOUT_MS,0); #if LIGHT_DEVICE //light_blinkStart(HINT_WHITE); light_shadeStart(HINT_WHITE,1000,0,1,NULL); #endif break; case SC_STATUS_LINK_OVER: os_timer_disarm(&esptouch_tout_t); SC_INFO("SC_STATUS_LINK_OVER\n"); if (esptouch_proc.esptouch_type == SC_TYPE_ESPTOUCH) { uint8 phone_ip[4] = {0}; os_memcpy(phone_ip, (uint8*)pdata, 4); SC_INFO("Phone ip: %d.%d.%d.%d\n",phone_ip[0],phone_ip[1],phone_ip[2],phone_ip[3]); } smartconfig_stop(); SC_INFO("UPDATE PASSWORD HERE\r\n"); if(esptouch_proc.esptouch_suc_cb){ esptouch_proc.esptouch_suc_cb(NULL);//run finish cb } break; } }