Wifishield Arduino: Scan Networks, problem with BSSID

Hello everyone

A part of my project involves getting the standard information of a network and the routers. Because I love Arduino, I have chosen Arduino Mega 2560 and the official Wifishield for my purpose.
I did some experimentation and research to get the information from network through the Wifishield. Arduino has made my life easy with their example ScanNetworks, but i can't get the correct BSSID information of the different routers.

My intention is to scan a network with information of SSID, BSSID and RSSI.

Arduino board: Mega 2560
Shield: Official Wifishield
IDE: 1.0.2.
Libraries: SPI.h and WiFi.h
Place of use: Hospital
Experience in programming: Moderate

Any help would be welcome :slight_smile:

Serial information:

Scanning available networks...
** Scan Networks **
MAC: 78:C4:E:1:DD:2C
Scanning available networks...
** Scan Networks **
number of available networks:10
0) 	Signal: -72 dBm	Encryption: WPA2
BSSID: 0:0:0:0:0:EE
	
1) 	Signal: -75 dBm	Encryption: WPA2
BSSID: 0:0:0:0:0:EE
	
2) 	Signal: -76 dBm	Encryption: WPA2
BSSID: 0:0:0:0:0:EE
	
3) 	Signal: -77 dBm	Encryption: WPA2
BSSID: 0:0:0:0:0:EE
	
4) 	Signal: -78 dBm	Encryption: WPA2
BSSID: 0:0:0:0:0:EE
	
5) 	Signal: -79 dBm	Encryption: WPA2
BSSID: 0:0:0:0:0:EE
	
6) 	Signal: -82 dBm	Encryption: WPA2
BSSID: 0:0:0:0:0:EE
	
7) 	Signal: -82 dBm	Encryption: WPA2
BSSID: 0:0:0:0:0:EE
	
8) ZOL Guest	Signal: -82 dBm	Encryption: None
BSSID: 0:0:0:0:0:EE
	
9) 	Signal: -89 dBm	Encryption: WPA2
BSSID: 0:0:0:0:0:EE

My Code:

#include <SPI.h>
#include <WiFi.h>

void setup() {
  //Initialize serial and wait for port to open:
  Serial.begin(9600); 
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present"); 
    // don't continue:
    while(true);
  } 

  // Print WiFi MAC address:
  printMacAddress();

  // scan for existing networks:
  Serial.println("Scanning available networks...");
  listNetworks();
}

void loop() {
  delay(10000);
  // scan for existing networks:
  Serial.println("Scanning available networks...");
  listNetworks();
}

void printMacAddress() {
  // the MAC address of your Wifi shield
  byte mac[6];                     

  // print your MAC address:
  WiFi.macAddress(mac);
  Serial.print("MAC: ");
  Serial.print(mac[5],HEX);
  Serial.print(":");
  Serial.print(mac[4],HEX);
  Serial.print(":");
  Serial.print(mac[3],HEX);
  Serial.print(":");
  Serial.print(mac[2],HEX);
  Serial.print(":");
  Serial.print(mac[1],HEX);
  Serial.print(":");
  Serial.println(mac[0],HEX);
}

void listNetworks() {
  // scan for nearby networks:
  Serial.println("** Scan Networks **");
  int numSsid = WiFi.scanNetworks();
  if (numSsid == -1)
  { 
    Serial.println("Couldn't get a wifi connection");
    while(true);
  } 

  // print the list of networks seen:
  Serial.print("number of available networks:");
  Serial.println(numSsid);

  // print the network number and name for each network found:
  for (int thisNet = 0; thisNet<numSsid; thisNet++) {
    Serial.print(thisNet);
    Serial.print(") ");
    Serial.print(WiFi.SSID(thisNet));
    Serial.print("\tSignal: ");
    Serial.print(WiFi.RSSI(thisNet));
    Serial.print(" dBm");
    Serial.print("\tEncryption: ");
    printEncryptionType(WiFi.encryptionType(thisNet));
    printBSSID(thisNet);
    Serial.print("\n");
  }
}

void printEncryptionType(int thisType) {
  // read the encryption type and print out the name:
  switch (thisType) {
  case ENC_TYPE_WEP:
    Serial.println("WEP");
    break;
  case ENC_TYPE_TKIP:
    Serial.println("WPA");
    break;
  case ENC_TYPE_CCMP:
    Serial.println("WPA2");
    break;
  case ENC_TYPE_NONE:
    Serial.println("None");
    break;
  case ENC_TYPE_AUTO:
    Serial.println("Auto");
    break;
  } 
}

void printBSSID(int thisType2) {
  
  
 
  switch (thisType2) {
     case 0:
  
   byte bssid0[6];                     

  // print your MAC address:
  byte bssid00[6];
  WiFi.BSSID(bssid00);    
  Serial.print("BSSID: ");
  Serial.print(bssid00[5],HEX);
  Serial.print(":");
  Serial.print(bssid00[4],HEX);
  Serial.print(":");
  Serial.print(bssid00[3],HEX);
  Serial.print(":");
  Serial.print(bssid00[2],HEX);
  Serial.print(":");
  Serial.print(bssid00[1],HEX);
  Serial.print(":");
  Serial.println(bssid00[0],HEX);
    break;
    
  case 1:
  // print your MAC address:
  byte bssid1[6];
  WiFi.BSSID(bssid1);    
  Serial.print("BSSID: ");
  Serial.print(bssid1[5],HEX);
  Serial.print(":");
  Serial.print(bssid1[4],HEX);
  Serial.print(":");
  Serial.print(bssid1[3],HEX);
  Serial.print(":");
  Serial.print(bssid1[2],HEX);
  Serial.print(":");
  Serial.print(bssid1[1],HEX);
  Serial.print(":");
  Serial.println(bssid1[0],HEX);
    break;
    
  case 2:
  
   byte bssid2[6];
  WiFi.BSSID(bssid2);    
  Serial.print("BSSID: ");
  Serial.print(bssid2[5],HEX);
  Serial.print(":");
  Serial.print(bssid2[4],HEX);
  Serial.print(":");
  Serial.print(bssid2[3],HEX);
  Serial.print(":");
  Serial.print(bssid2[2],HEX);
  Serial.print(":");
  Serial.print(bssid2[1],HEX);
  Serial.print(":");
  Serial.println(bssid2[0],HEX);
  
    break;
    
  case 3:
  
  byte bssid3[6];
  WiFi.BSSID(bssid3);    
  Serial.print("BSSID: ");
  Serial.print(bssid3[5],HEX);
  Serial.print(":");
  Serial.print(bssid3[4],HEX);
  Serial.print(":");
  Serial.print(bssid3[3],HEX);
  Serial.print(":");
  Serial.print(bssid3[2],HEX);
  Serial.print(":");
  Serial.print(bssid3[1],HEX);
  Serial.print(":");
  Serial.println(bssid3[0],HEX);
    break;
    
  case 4:
  
    byte bssid4[6];
  WiFi.BSSID(bssid4);    
  Serial.print("BSSID: ");
  Serial.print(bssid4[5],HEX);
  Serial.print(":");
  Serial.print(bssid4[4],HEX);
  Serial.print(":");
  Serial.print(bssid4[3],HEX);
  Serial.print(":");
  Serial.print(bssid4[2],HEX);
  Serial.print(":");
  Serial.print(bssid4[1],HEX);
  Serial.print(":");
  Serial.println(bssid4[0],HEX);
  
    break;
    
  case 5:
  
    byte bssid5[6];
  WiFi.BSSID(bssid5);    
  Serial.print("BSSID: ");
  Serial.print(bssid5[5],HEX);
  Serial.print(":");
  Serial.print(bssid5[4],HEX);
  Serial.print(":");
  Serial.print(bssid5[3],HEX);
  Serial.print(":");
  Serial.print(bssid5[2],HEX);
  Serial.print(":");
  Serial.print(bssid5[1],HEX);
  Serial.print(":");
  Serial.println(bssid5[0],HEX);
  
    break;
    
     case 6:
   byte bssid6[6];
  WiFi.BSSID(bssid6);    
  Serial.print("BSSID: ");
  Serial.print(bssid6[5],HEX);
  Serial.print(":");
  Serial.print(bssid6[4],HEX);
  Serial.print(":");
  Serial.print(bssid6[3],HEX);
  Serial.print(":");
  Serial.print(bssid6[2],HEX);
  Serial.print(":");
  Serial.print(bssid6[1],HEX);
  Serial.print(":");
  Serial.println(bssid6[0],HEX);
  
    break;
    
     case 7:
   byte bssid7[6];
  WiFi.BSSID(bssid7);    
  Serial.print("BSSID: ");
  Serial.print(bssid7[5],HEX);
  Serial.print(":");
  Serial.print(bssid7[4],HEX);
  Serial.print(":");
  Serial.print(bssid7[3],HEX);
  Serial.print(":");
  Serial.print(bssid7[2],HEX);
  Serial.print(":");
  Serial.print(bssid7[1],HEX);
  Serial.print(":");
  Serial.println(bssid7[0],HEX);
    break;
    
     case 8:
    byte bssid8[6];
  WiFi.BSSID(bssid8);    
  Serial.print("BSSID: ");
  Serial.print(bssid8[5],HEX);
  Serial.print(":");
  Serial.print(bssid8[4],HEX);
  Serial.print(":");
  Serial.print(bssid8[3],HEX);
  Serial.print(":");
  Serial.print(bssid8[2],HEX);
  Serial.print(":");
  Serial.print(bssid8[1],HEX);
  Serial.print(":");
  Serial.println(bssid8[0],HEX);
    break;
     case 9:
    
  byte bssid9[6];
  WiFi.BSSID(bssid9);    
  Serial.print("BSSID: ");
  Serial.print(bssid9[5],HEX);
  Serial.print(":");
  Serial.print(bssid9[4],HEX);
  Serial.print(":");
  Serial.print(bssid9[3],HEX);
  Serial.print(":");
  Serial.print(bssid9[2],HEX);
  Serial.print(":");
  Serial.print(bssid9[1],HEX);
  Serial.print(":");
  Serial.println(bssid9[0],HEX);
  
    break;
   
   
  } 
}

Perhaps it's just me, but I can't see any difference in the cases in printBSSID().

Have you looked at the BSSID() method in the WiFi class?

Thank you for your quick replay PaulS.

My thoughts about getting different BSSIDs, was by calling the BSSID function described in WiFi - Arduino Reference and changing the "bssid' in WiFi.BSSID(bssid) with bssid1, bssid2 etc.
Am i wrong for thinking that this was possible?

Arne

and changing the "bssid' in WiFi.BSSID(bssid) with bssid1, bssid2 etc.

For what purpose? You can't change the MAC address of the router you as are talking to. I really don't understand why that data is relevant. At best, you could change the behavior of the Arduino based on which router you connect to, but that seems like an likely thing to want to do.

I thought that if you did" ScanNetwork", you could examine different networks from different routers. My purpose is to do a calculation of triangulation of the different routers to determine the place of the patient who is wearing arduino (prototpe).

I thought that if you did" ScanNetwork", you could examine different networks from different routers.

You can. I can see how the developers might have neglected to thoroughly test the WiFi.BSSID() function, though. I can also see situations where the router says that its MAC address is none of your business. I wonder if that is the situation you are encountering.

You'll need to dig into the library to tell whether the problem is that the router isn't supply the information or the library isn't populating some buffer correctly.

My purpose is to do a calculation of triangulation of the different routers to determine the place of the patient who is wearing arduino (prototpe).

I fail to see how you are going to do that. The RSSI value gives you no clue as to distance. The Arduino doesn't have a map of the routers (does it?) so it won't be able to report its location with respect to the routers it sees.

Thank you for this information. I will give it my best, but my skills in programming aren't that good :).

For the positioning: In this project, the arduino just has to get the BSSID and RSSI in a list, which sends it to a webserver. I'm currently writing a program in Labview to get this information from the server and do the calculation. I have a plan of the routers in the hospital and would like to upload it in Labview.