/****************************************************************************** * FunctionName : user_MeshSetInfo * Description : set mesh node SSID,AUTH_MODE and PASSWORD * Parameters : none * Returns : none * Comments : In this initial version, the MESH device is grouped by the specific SSID Users can change the SSID and PASSWORD for SoftAP interface for the mesh nodes * NOTE : Only call it once and before espconn_mesh_enable() *******************************************************************************/ void ICACHE_FLASH_ATTR user_MeshSetInfo() { #if MESH_SET_GROUP_ID //set mesh group id espconn_mesh_group_id_init((uint8*)MESH_GROUP_ID,6); os_printf("==========================\r\n"); os_printf("SET GROUP ID: "MACSTR"",MAC2STR(MESH_GROUP_ID)); os_printf("==========================\r\n"); #endif //If the device is in MESH mode,the SSID would finally be MESH_SSID_PREFIX_X_XXXXXX #if LIGHT_DEVICE espconn_mesh_set_dev_type(ESP_DEV_LIGHT); #elif PLUG_DEVICE espconn_mesh_set_dev_type(ESP_DEV_PLUG); #elif SENSOR_DEVICE espconn_mesh_set_dev_type(ESP_DEV_HUMITURE); #endif if( espconn_mesh_set_ssid_prefix(MESH_SSID_PREFIX,os_strlen(MESH_SSID_PREFIX))){ MESH_INFO("SSID PREFIX SET OK..\r\n"); }else{ MESH_INFO("SSID PREFIX SET ERROR..\r\n"); } if(espconn_mesh_encrypt_init(MESH_AUTH,MESH_PASSWORD,os_strlen(MESH_PASSWORD))){ MESH_INFO("SOFTAP ENCRYPTION SET OK..\r\n"); }else{ MESH_INFO("SOFTAP ENCRYPTION SET ERROR..\r\n"); } }
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; }