The use of the ESP8266 in the world of IoT

User avatar
By Daven006
#32926 I must admit that I didn't check the return status but this seem to work:

Code: Select allstatic void ICACHE_FLASH_ATTR wifi_station_scan_done(void *arg, STATUS status) {
  uint8 ssid[33];

  if (status == OK) {
    struct bss_info *bss_link = (struct bss_info *)arg;

    while (bss_link != NULL) {
      os_memset(ssid, 0, 33);
      if (os_strlen(bss_link->ssid) <= 32) {
        os_memcpy(ssid, bss_link->ssid, os_strlen(bss_link->ssid));
      } else {
        os_memcpy(ssid, bss_link->ssid, 32);
      }
      os_printf("WiFi Scan: (%d,\"%s\",%d)\n", bss_link->authmode, ssid, bss_link->rssi);
      bss_link = bss_link->next.stqe_next;
    }
  } else {
     os_printf("wifi_station_scan fail %d\n", status);
  }
  startUp();
}

static void ICACHE_FLASH_ATTR  initDone_cb() {
   INFO("Start WiFi Scan\n");
   wifi_set_opmode(STATION_MODE);
   wifi_station_scan(NULL, wifi_station_scan_done);
}

void ICACHE_FLASH_ATTR user_init(void) {
   stdout_init();
   gpio_init();
   wifi_station_set_auto_connect(false);
   wifi_station_set_reconnect_policy(true);

   easygpio_pinMode(LED, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
   easygpio_outputSet(LED, 1);
   easygpio_pinMode(WS2811, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
   easygpio_outputSet(WS2811, 0);
   easygpio_pinMode(12, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
   easygpio_outputSet(12, 0);
   system_init_done_cb(&initDone_cb);
}
User avatar
By scargill
#32931 YES INEED IT DOES - you are my hero for the week - I just got a response - now all I need do is figure out how to get that to change the current access point..

So the idea is you might have 2 identically named access points - one stronger than the other - OR another access point that is stronger - or the current one might have given up.... so I want to scan and pick the best from a list of acceptable points.

This is a GOOD start, thank you for that.

Pete.

Daven006 wrote:I must admit that I didn't check the return status but this seem to work:

Code: Select allstatic void ICACHE_FLASH_ATTR wifi_station_scan_done(void *arg, STATUS status) {
  uint8 ssid[33];

  if (status == OK) {
    struct bss_info *bss_link = (struct bss_info *)arg;

    while (bss_link != NULL) {
      os_memset(ssid, 0, 33);
      if (os_strlen(bss_link->ssid) <= 32) {
        os_memcpy(ssid, bss_link->ssid, os_strlen(bss_link->ssid));
      } else {
        os_memcpy(ssid, bss_link->ssid, 32);
      }
      os_printf("WiFi Scan: (%d,\"%s\",%d)\n", bss_link->authmode, ssid, bss_link->rssi);
      bss_link = bss_link->next.stqe_next;
    }
  } else {
     os_printf("wifi_station_scan fail %d\n", status);
  }
  startUp();
}

static void ICACHE_FLASH_ATTR  initDone_cb() {
   INFO("Start WiFi Scan\n");
   wifi_set_opmode(STATION_MODE);
   wifi_station_scan(NULL, wifi_station_scan_done);
}

void ICACHE_FLASH_ATTR user_init(void) {
   stdout_init();
   gpio_init();
   wifi_station_set_auto_connect(false);
   wifi_station_set_reconnect_policy(true);

   easygpio_pinMode(LED, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
   easygpio_outputSet(LED, 1);
   easygpio_pinMode(WS2811, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
   easygpio_outputSet(WS2811, 0);
   easygpio_pinMode(12, EASYGPIO_NOPULL, EASYGPIO_OUTPUT);
   easygpio_outputSet(12, 0);
   system_init_done_cb(&initDone_cb);
}
User avatar
By drewle
#59026 it seems it only works if the initialization has been completed.
You should use the following code:

Code: Select allLOCAL void myInitDone(void)
{
   bool u1_Status;

   os_printf("myInitDone\r\n");

   u1_Status = wifi_set_opmode(STATION_MODE);
   os_printf("wifi_set_opmode %u\n\r",u1_Status);
   u1_Status = wifi_station_scan(NULL,scanCB);
   os_printf("wifi_station_scan %u\n\r",u1_Status);
}


void user_init()
{
   ...
   system_init_done_cb(myInitDone);
   ...
}