Iot network

From MDD wiki
Jump to navigation Jump to search

The HvA provides an IoT network called iotroam. In order to connect to this network we need to register the device it's mac address.

How to find a mac address

The MAC address (Physical Address) is listed as series of 12 digits across six pairs (00:1A:C2:7B:00:47, for example)

Windows

  1. Goto Settings > wifi
  2. Click hardware properties
  3. Find Physical address (MAC)

Troubleshooting

Make sure you have turned off random hardware addresses

Settings > wifi

Windows-mac.png

Mac(book)

  1. Goto Preferences > network
  2. Click Advanced…
  3. Find Wi-Fi Address

iOS

  1. Goto Settings > wifi
  2. Click on the on the connected network
  3. Find Wi-Fi Address

Troubleshooting

Make sure you have Private Address toggled off

Ios-mac.png

Arduino board

Getting the address

  1. Upload the following sketch to your board:
#ifdef ESP32
  #include <WiFi.h>
#else
  #include <ESP8266WiFi.h>
#endif

void setup(){
  Serial.begin(9600); // Make sure your serial monitor is set to 9600 baud
  Serial.println();
  Serial.print("ESP Board MAC Address:  ");
  Serial.println(WiFi.macAddress());
}
 
void loop(){
}
  1. After running the code you should be able to see something similar to this in your serial monitor (Tools > serial monitor)

Arduino-mac.png


  1. After a teacher has registered the MAC address to the iotroam network you should be able to connect. Upload the following sketch to verify your device is able to connect
#ifdef ESP32
  #include <WiFi.h>
#else
  #include <ESP8266WiFi.h>
#endif

void setup(){
  Serial.begin(9600);
  Serial.println();

  WiFi.begin("iotroam", "loislane");

  while (WiFi.status() != WL_CONNECTED)
  {
    delay(500);
    Serial.print(".");
  }

  Serial.println(WiFi.localIP());
}
 
void loop(){
}
  1. After running and uploading the code from step 3 you should get an output showing an IP address similar to

Arduino-ip.png

Troubleshooting

The serial monitor does not show any output

Baud rate: Make sure you have selected the correct baud rate. This should be the same value as set in Serial.begin([value])

Opened serial monitor after uploading: Sometimes you open the serial monitor after you uploaded the code. The text has already been printed, you just missed it. There are two possible solutions to this while having the serial monitor open

  1. Reupload the code
  2. Press the tiny reset button on the device

Install `Wifi.h` and `ESP8266WiFi.h`

Install the `Wifi.h`

This library should be installed by default but in case it wasn’t you can install it yourself

  1. Goto Tools > Manage libraries
  2. Search for Wifi by Arduino
Installing the `ESP8266WiFi.h`

Follow https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/


Arduino-lib.png

Multiple libraries were found for "WiFi.h"

Fix found at https://github.com/1amchris/WiFi32.h

Raspberry

  1. Create a new file on the desktop called get-mac.py
  2. Add the following code to the file
def getEthName():
  # Get name of the Ethernet interface
  try:
    for root,dirs,files in os.walk('/sys/class/net'):
      for dir in dirs:
        if dir[:3]=='enx' or dir[:3]=='eth':
          interface=dir
  except:
    interface="None"
  return interface
 
def getMAC(interface='eth0'):
  # Return the MAC address of the specified interface
  try:
    str = open('/sys/class/net/%s/address' %interface).read()
  except:
    str = "00:00:00:00:00:00"
  return str[0:17]
 
ethName=getEthName()
ethMAC=getMAC(ethName)
 
print(f"MAC address for {ethName}: {ethMAC}")
  1. Open a terminal
  2. Run