/****************************************************************************** * FunctionName : user_MeshStart * Description : mesh procedure init function * Parameters : none * Returns : none * Comments : Set callback function and start mesh. MESH_ONLINE: CAN BE CONTROLLED BY WAN SERVER,AS WELL AS LAN APP VIA ROUTER. MESH_LOCAL: CAN ONLY BE CONTROLLED BY LOCAL NETWORK. *******************************************************************************/ void ICACHE_FLASH_ATTR user_MeshParamInit() { user_MeshSetInfo(); mesh_MacIdInit(); LightMeshProc.mesh_suc_cb=mesh_SuccessCb; LightMeshProc.mesh_fail_cb=mesh_FailCb; LightMeshProc.mesh_init_tout_cb=mesh_TimeoutCb; LightMeshProc.start_time = system_get_time(); LightMeshProc.init_retry = 0; //set max hops of mesh espconn_mesh_set_max_hops(MESH_MAX_HOP_NUM); }
bool ICACHE_FLASH_ATTR esp_mesh_demo_init() { struct station_config config; // print version of mesh espconn_mesh_print_ver(); /* * set the AP password of mesh node */ if (!espconn_mesh_encrypt_init(MESH_AUTH, MESH_PASSWD, MESH_DEMO_STRLEN(MESH_PASSWD))) { MESH_DEMO_PRINT("set pw fail\n"); return false; } /* * if you want set max_hop > 4 * please make the heap is avaliable * mac_route_table_size = (4^max_hop - 1)/3 * 6 */ if (!espconn_mesh_set_max_hops(MESH_MAX_HOP)) { MESH_DEMO_PRINT("fail, max_hop:%d\n", espconn_mesh_get_max_hops()); return false; } /* * mesh_ssid_prefix * mesh_group_id and mesh_ssid_prefix represent mesh network */ if (!espconn_mesh_set_ssid_prefix(MESH_SSID_PREFIX, MESH_DEMO_STRLEN(MESH_SSID_PREFIX))) { MESH_DEMO_PRINT("set prefix fail\n"); return false; } /* * mesh_group_id * mesh_group_id and mesh_ssid_prefix represent mesh network */ if (!espconn_mesh_group_id_init((uint8_t *)MESH_GROUP_ID, sizeof(MESH_GROUP_ID))) { MESH_DEMO_PRINT("set grp id fail\n"); return false; } if (!espconn_mesh_server_init((struct ip_addr *)server_ip, server_port)) { MESH_DEMO_PRINT("server_init fail\n"); return false; } /* * please change MESH_ROUTER_SSID and MESH_ROUTER_PASSWD according to your router */ MESH_DEMO_MEMSET(&config, 0, sizeof(config)); MESH_DEMO_MEMCPY(config.ssid, MESH_ROUTER_SSID, MESH_DEMO_STRLEN(MESH_ROUTER_SSID)); MESH_DEMO_MEMCPY(config.password, MESH_ROUTER_PASSWD, MESH_DEMO_STRLEN(MESH_ROUTER_PASSWD)); /* * if you use router with hide ssid, you MUST set bssid in config, * otherwise, node will fail to connect router. * * if you use normal router, please pay no attention to the bssid, * and you don't need to modify the bssid, mesh will ignore the bssid. */ config.bssid_set = 1; MESH_DEMO_MEMCPY(config.bssid, MESH_ROUTER_BSSID, sizeof(config.bssid)); /* * you can use esp-touch(smart configure) to sent information about router AP to mesh node * if you donn't use esp-touch, you should use espconn_mesh_set_router to set router for mesh node */ if (!espconn_mesh_set_router(&config)) { MESH_DEMO_PRINT("set_router fail\n"); return false; } return true; }