WiFi PRO 20: Scan | Libelium

This example shows how to scan for access points

Required Materials

1 x Waspmote 1 x Battery 1 x WiFi PRO Module

Notes

- The battery has to be connected. - This example can be executed in Waspmote v15

Code

/*  
 *  ------ WIFI Example -------- 
 *  
 *  Explanation: This example shows how to scan for access points
 *  
 *  Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify  
 *  it under the terms of the GNU General Public License as published by  
 *  the Free Software Foundation, either version 3 of the License, or  
 *  (at your option) any later version.  
 *   
 *  This program is distributed in the hope that it will be useful,  
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of  
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the  
 *  GNU General Public License for more details.  
 *   
 *  You should have received a copy of the GNU General Public License  
 *  along with this program.  If not, see .  
 *  
 *  Version:           3.0
 *  Design:            David Gascon 
 *  Implementation:    Yuri Carmona
 */

// Put your libraries here (#include ...)
#include <WaspWIFI_PRO.h>


// choose socket (SELECT USER'S SOCKET)
///////////////////////////////////////
uint8_t socket = SOCKET0;
///////////////////////////////////////


uint8_t error;
uint8_t status;
unsigned long previous;



void setup() 
{
  USB.ON();
  USB.println(F("Start program"));  
  USB.println(F("***************************************"));  
  USB.println(F("Once the module is set with one or more"));
  USB.println(F("AP settings, it attempts to join the AP"));
  USB.println(F("automatically once it is powered on"));    
  USB.println(F("Refer to example 'WIFI_PRO_01' to configure"));  
  USB.println(F("the WiFi module with proper settings"));
  USB.println(F("***************************************")); 
}



void loop()
{   

  //////////////////////////////////////////////////
  // 1. Switch ON
  //////////////////////////////////////////////////  
  error = WIFI_PRO.ON(socket);

  if (error == 0)
  {    
    USB.println(F("1. WiFi switched ON"));
  }
  else
  {
    USB.println(F("1. WiFi did not initialize correctly"));
  }


  //////////////////////////////////////////////////
  // 2. Join AP
  //////////////////////////////////////////////////  

  // get actual time
  previous = millis();

  // check connectivity
  status =  WIFI_PRO.isConnected();

  // Check if module is connected
  if (status == true)
  { 
    USB.print(F("2. WiFi is connected OK."));
    USB.print(F(" Time(ms):"));    
    USB.println(millis()-previous);

    // scan and print info related to surrounding APs
    error = WIFI_PRO.scan();

    // check response
    if (error == 0)
    {
      SD.ON();
      SD.showFile(WIFI_PRO_SCANFILE);
      SD.OFF();
    }
    else
    {
      USB.println(F("Error calling 'scan' function")); 
      WIFI_PRO.printErrorCode();
    } 


  }
  else
  {
    USB.print(F("2. WiFi is connected ERROR.")); 
    USB.print(F(" Time(ms):"));    
    USB.println(millis()-previous);  
  }


  //////////////////////////////////////////////////
  // 3. Switch OFF
  //////////////////////////////////////////////////  
  WIFI_PRO.OFF(socket);
  USB.println(F("3. WiFi switched OFF\n\n")); 
  USB.println(F("Wait 10 seconds...\n")); 
  delay(10000);
}

Output

H#
Start program
***************************************
Once the module is set with one or more
AP settings, it attempts to join the AP
automatically once it is powered on
Refer to example 'WIFI_PRO_01' to configure
the WiFi module with proper settings
***************************************
1. WiFi switched ON
2. WiFi is connected OK. Time(ms):3407

-------------------
libelium_AP,AP,04:F0:21:1B:5F:EF,WPA2,3,61
NETIK-360-102,AP,B8:27:EB:24:E8:AF,WPA2,2,70
libelium_teaming,AP,0E:18:D6:63:E5:2C,WPA2,6,69
libelium_wsn2,AP,2A:A4:3C:99:2F:B2,WPA2,6,72
libelium_formacion,AP,32:A4:3C:99:2F:B2,WPA2,6,69
libelium_teaming,AP,2E:A4:3C:99:2F:B2,WPA2,6,69
libelium_wsn2,AP,0A:18:D6:63:E5:2C,WPA2,6,63
libelium_formacion,AP,12:18:D6:63:E5:2C,WPA2,6,64
meshlium_39e0,AP,00:0B:6B:23:34:E4,NONE,6,77
meshlium_bcc0,AP,A8:54:B2:92:FE:C5,NONE,9,49
libelium_wsn2,AP,2A:A4:3C:99:2F:C3,WPA2,11,59
libelium_teaming,AP,2E:A4:3C:99:2F:C3,WPA2,11,57
libelium_formacion,AP,32:A4:3C:99:2F:C3,WPA2,11,57
SANMETAL,AP,54:2A:A2:7E:B4:B1,WPA2,11,71
libelium_teaming,AP,2E:A4:3C:99:30:E2,WPA2,1,72
libelium_wsn2,AP,2A:A4:3C:99:30:E2,WPA2,1,72
I/OK

-------------------
3. WiFi switched OFF


Wait 10 seconds...

Last updated