Code:
struct station_config stationConfig;
os_strcpy(stationConfig.ssid, ssid);
os_strcpy(stationConfig.password, password);
// Must also be set or garbages values will make the scan/connection fail
stationConfig.bssid_set = 0; // Don't match the BSSID
stationConfig.threshold.rssi = 0; // To "ignore" the RSSI level when scanning the network ?
stationConfig.threshold.authmode = AUTH_OPEN; // The router must no ask for a challenge when scanning ?
Statistics: Posted by Pato — Mon Jun 11, 2018 6:50 pm
Statistics: Posted by blubb — Sun Jun 10, 2018 11:53 pm
Statistics: Posted by Bernard — Sat Jun 09, 2018 12:01 am
Code:
Setting up the Esp as a Wifi station...
bcn 0
del if1
usl
mode : sta(ec:fa:bc:05:9b:59)
add if0
Connecting to WiFi...
scandone
scandone
AP: iPhone of Juliet
AP: SFR-12Y0
AP: MyNetwork <= MyNetwork is visible
AP: Livebox-F553
AP: Livebox-F89E
AP: Livebox-EC52
AP: AndroidAP
AP: eduroam
reconnect
scandone
no MyNetwork found, reconnect after 1s <= MyNetwork is said not found...
Disconnect from ssid MyNetwork, reason 201 <= code 201 = REASON_NO_AP_FOUND
reconnect
scandone
no MyNetwork found, reconnect after 1s
Disconnect from ssid MyNetwork, reason 201
reconnect
scandone
no MyNetwork found, reconnect after 1s
Disconnect from ssid MyNetwork, reason 201
reconnect
...
Code:
/**
* @brief Callback function called when the wifi connection is fully operational.
*
*/
void ICACHE_FLASH_ATTR WifiConnectedCb(System_Event_t *event)
{
if(event->event == EVENT_STAMODE_DISCONNECTED)
{
os_printf("Disconnect from ssid %s, reason %d\n", event->event_info.disconnected.ssid, event->event_info.disconnected.reason);
}
/* Run OTA process only when we are fully connected to WiFi */
if(event->event == EVENT_STAMODE_GOT_IP)
{
os_printf("Connected to Wifi (EVENT_STAMODE_GOT_IP) \n");
}
}
/**
* @brief Print all visible APs.
*
*/
static void ICACHE_FLASH_ATTR scan_done_CB(void *arg, STATUS status)
{
if (status == OK)
{
struct bss_info *bss_link = (struct bss_info *)arg;
while(bss_link != NULL)
{
os_printf("AP: %s \n", bss_link->ssid);
bss_link = STAILQ_NEXT(bss_link, next);
}
}
}
/**
* @brief Called when system is fully initialized. Here we do our custom initialization
* like connecting to wifi and setting timers.
*/
void PostInitCb()
{
/* Connect to WiFi */
os_printf("I'm version 2 ! \n");
os_printf("Setting up the Esp as a Wifi station... \n");
struct station_config stationConfig;
os_strcpy(stationConfig.ssid, ssid);
os_strcpy(stationConfig.password, password);
wifi_set_opmode_current(STATION_MODE);
wifi_station_disconnect();
wifi_station_set_config(&stationConfig);
wifi_set_event_handler_cb(WifiConnectedCb);
wifi_station_connect();
os_printf("Connecting to WiFi... \n");
//DEBUG
wifi_station_scan(NULL, scan_done_CB);
}
/**
* @brief Was present in IoT_Demo/user/user_main.c on which this code is based...
* Set the 5th sector from the end of the flash to store the RF_CAL parameter.
*/
uint32 ICACHE_FLASH_ATTR user_rf_cal_sector_set(void)
{
enum flash_size_map size_map = system_get_flash_size_map();
uint32 rf_cal_sec = 0;
switch (size_map) {
case FLASH_SIZE_4M_MAP_256_256:
rf_cal_sec = 128 - 5;
priv_param_start_sec = 0x3C;
break;
case FLASH_SIZE_8M_MAP_512_512:
rf_cal_sec = 256 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_16M_MAP_512_512:
rf_cal_sec = 512 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_16M_MAP_1024_1024:
rf_cal_sec = 512 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_32M_MAP_512_512:
rf_cal_sec = 1024 - 5;
priv_param_start_sec = 0x7C;
break;
case FLASH_SIZE_32M_MAP_1024_1024:
rf_cal_sec = 1024 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_64M_MAP_1024_1024:
rf_cal_sec = 2048 - 5;
priv_param_start_sec = 0xFC;
break;
case FLASH_SIZE_128M_MAP_1024_1024:
rf_cal_sec = 4096 - 5;
priv_param_start_sec = 0xFC;
break;
default:
rf_cal_sec = 0;
priv_param_start_sec = 0;
break;
}
return rf_cal_sec;
}
/**
* @brief Was present in IoT_Demo/user/user_main.c on wich this code is based...
*/
void ICACHE_FLASH_ATTR user_rf_pre_init(void)
{
}
/**
* @brief Main entry point of our programm
*/
void user_init()
{
system_init_done_cb(PostInitCb);
}
Statistics: Posted by Pato — Fri Jun 08, 2018 10:36 pm