In this tutorial, we're going through the initial steps to get setup with NB-IoT and publish an Event to Wia.
Installing Python and PyserialIf you haven’t already, you need to install Python on your computer to complete this tutorial.
- Version 2.7.x
- Follow the download instructions for your operating system
When using Windows, you'll need to add python to your path to make use of it anywhere in your OS. More on that here.
Now to install the pyserial
library:
- For Windows, open PowerShell (or Command Prompt) and run the command
pip install pyserial
.
- For Mac/Linux open Terminal and run the command
pip install pyserial
.
In the rare case if pip install pyserial
doesn't work, try the following instead: python -m pip install pyserial
- For Windows, open power-shell in the location of your choosing and run
git clone git@github.com:wiaio/nb-iot-utilities.git
in the power-shell terminal
- For Mac/Linux open a terminal in the location of your choosing and run
git clone git@github.com:wiaio/nb-iot-utilities.git
in the terminal
Alternatively you can download the zip file here.
- Extract the zip in the location of your choosing
- Download and install the USB to UART bridge drivers from here. Select the appropriate version for your operating system and architecture
- Open a terminal window and run the command
ls /dev/tty*
- Look for a device with the name that begins with
/dev/tty
e.g./dev/tty.usbmodemPy343431
on MAC or/dev/ttyUSB0
/dev/ttyACM0
on Linux
For Linux, you may need to run the two commands below. Once you've completed that, reboot your computer. This will add permissions that will allow you to upload a sketch to the board.
sudo usermod -a -G tty ${USER}sudo usermod -a -G dialout ${USER}
- Download and install the USB to UART bridge drivers from here. Select the appropriate version for your operating system and architecture
- Open the Windows start menu and search for
Device Manager
- The COM port for the Pycom device will be listed as
USB Serial Device
or something similar
- Keep note of the COM port (e.g. COM4)
In order to communicate with your NB-IoT shield through your Arduino, you'll need to flash the Arduino with code that gives power to the Shield and provides a tunnel for the instructions.
- Install the Arduino IDE. This is whereYou can download it for Mac OS X, Windows and Linux here
In the Arduino IDE:
- Go to menu:
Tools > Board > Boards Manager
- Search for
Arduino SAMD
. When found, clickInstall
In the Arduino IDE:
- Select the Arduino M0 board type by going to
Tools > Board
- Select the port that displays
Arduino M0
- Now copy and paste the initial_config.ino code into the Arduino IDE
- Click
Upload
to flash the board
Now you should be ready to communicate to your shield.
Updating nb-iot.pyBefore we interface with your Device, there are a few variables that need to be updated the file nb-iot.py
.In your favourite text editor, open nb-iot.py
and follow these steps:
- Find and replace the
serial_name
with the port obtained earlier in the tutorial
- Find and replace the
accessToken
with your Device's secret key found in your Wia dashboard
- Find and replace the
apn
with your operators APN (Default: Vodafone Ireland)
- Find and replace the
network_operator
with your operators ID (Default: Vodafone Ireland)
52.17.209.228
is the IP address of the Wia CoAP API and 5683
is the port.
- For Windows, in PowerShell, run
python nb-iot.py -a
in the PowerShell terminal
- For Mac/Linux open a terminal and run
python nb-iot.py -a
in the terminal
This command checks if the device is working with our code by running the simplest command on the device (AT).
For a full list of commands available:
- For Windows, in PowerShell, run
python nb-iot.py -h
in the PowerShell terminal
- For Mac/Linux open a terminal and run
python nb-iot.py -h
in the terminal
To publish an Event to Wia with your NB-IoT device, run the following:
- For Windows, in PowerShell, run the command
python nb-iot.py -aknt
- For Mac/Linux open Terminal and run the command
python nb-iot.py -aknt
This script does the following:
- Checks if the code can interface with the device
- Resets the device
- Attaches the device to the network
- Opens a socket and sends a message via UDP to Wia
The output should look like the image below:
Some devices might be on older firmware that's not compatible with the network you are trying to connect with. You can update your devices firmware by following the instructions here.
If you are still having trouble connecting, drop us a note!
Comments