Breakout SDK enables developers to connect their devices over Narrowband cellular line.
This SDK is primarily intended to connect our Massive IoT Developer Kits equipped with Twilio Narrowband SIMs to an MQTT broker but can also be used on similar boards with Arduino support and with different protocols with modification.
This Arduino compatible library is backed by a more generic cellular module abstraction layer, Twilio Breakout SDK for Massive IoT, which also has support for the Quectel BG96 NB-IoT module. The goal of this module is to make packet based communications easier when dealing with these cellular modules.
It is important to note that you must have a Narrowband SIM to utilize this kit, a standard LTE SIM will not be able to connect to the network.
This section should provide you with a quick start if everything goes smoothly for you. Please refer to the Detailed guides section for more information.
- Add Wio LTE board to Arduino. Use the instructions from Seeed Wiki for guidance.
- Clone the SDK recursively to the directory where your Arduino libraries live:
# Under Linux
git clone --recursive https://github.com/twilio/Breakout_Massive_SDK_Arduino ~/Arduino/libraries/Breakout_Massive_SDK_Arduino
Alternatively you can download one of the releases and install it as a zip library. Never use Download Zip button under 'Clone or download' list, because some dependencies will be missing from the downloaded archive.
- Install sensor support libraries.
-
Start Arduino IDE and open the sample in
File > Examples > Breakout Massive SDK Arduino Library > AlfaKit > Sample.ino
. By default it will build a sample for Grove temperature and humidity sensor. EditSample.ino
to enable different sensors. -
Edit
config.h
andtls_credentials.h
to configure the connection to your MQTT broker. See the section on how to configure the MQTT broker below. -
Attach the sensor to the board (The samples are configured for sensors attached to
D38
Grove socket), connect the board with a USB cable to you machine, and flash it via Arduino IDE. -
You can now subscribe to 'device/data' topic on the same MQTT broker the device is publishing to and see the data being posted.
- Registering the SIM card and preparing the docs.
- Setting up an MQTT broker.
- Setting up your development environment.
- Breakout SDK instalation
- Updating Breakout SDK on your local machine
- Dependency installation
- Flashing the board
- Developer board LEDs
- Sample code outline
- Protocols other than MQTT
- Troubleshooting
-
Register your Twilio Narrowband SIM card in the Programmable wireless console.
-
Insert the smallest form factor of the Narrowband SIM in the bottom of the two slots available on the Developer Board, closest to the PCB.
The smallest form factor of a SIM is the Nano (4FF) SIM size. The top slot is a Micro-SD card slot. If you insert the Narrowband SIM in the top slow, gently pry it out with needle-nose pliers.
- Connect the LTE Antenna to the LTE pin located on the bottom of the board.
The sample sends data over MQTT protocol. All the communication in MQTT goes through a central server called broker. There are several options on what broker to use, they all should be compatible with this sample.
- To set up a standalone broker in Docker,If you need a test broker to use for the samples, see our guide.
- Mosquitto has a free online broker for testing, that can also sign certificates for your device.
- MQTT is supported as one of the protocols in AWS IoT
- Adafruit.io provides an MQTT broker with simple visualization tools.
The following steps will guide you from downloading the Arduino IDE to installing sample applications on your Developer board.
- Download Arduino IDE 1.8.9+
The following step is required for OSX:
- Install Homebrew by typing the following in a Terminal:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
- Install dfu-util using Homebrew by typing the following in a Terminal:
brew install dfu-util libusb
Note: Use dfu-util 0.9 or greater if available. Check dfu-util version with
brew info dfu-util
The follow steps are required for Windows:
- Install USB Drivers
- You may also need to Update DFU Drivers for flashing to succeed
- Install an updated dfu-util using apt:
sudo apt-get install dfu-util
- Configure permissions for USB serial port provided by the Alfa developer board. Without this, you may face permission issues when flashing the board unless you run dfu-util setuid to root.
sudo tee -a /etc/udev/rules.d/50-twilio-local.rules << _DONE_
# Twilio Alfa kit
# Bus 001 Device 035: ID 0483:5740 STMicroelectronics STM32F407
SUBSYSTEMS=="usb", ATTRS{idVendor}=="0483", ATTRS{idProduct}=="5740", GROUP="dialout", MODE="0666"
_DONE_
- Plug in the developer kit and verify permissions:
ls -l /dev/ttyACM*
the device should be readable and writable by all users.
crw-rw-rw- 1 root dialout 166, 0 Jul 8 16:41 /dev/ttyACM0
- Insert the Micro-USB cable into the Developer Board
- Insert the other end of the USB cable in your computer
- Open Arduino IDE
- Click Arduino > Preferences
- Copy the following URL into the Additional Boards Manager URLs field:
https://raw.githubusercontent.com/Seeed-Studio/Seeed_Platform/master/package_seeeduino_boards_index.json
- Click OK
- Click Tools > Boards > Boards Manager
- Type "Seeed" into the search field
- Select the Seeed STM32F4 Boards version 1.2.5 or later
- Click Install
- Close the Boards Manager window
- Click Tools > Boards > Wio Tracker LTE
- Click Tools > Port > {Your Modem Port Here}
- OSX: /dev/{cu|tty}.usbmodem{XXXX}
- Linux: /dev/ttyACM{X}
- Windows: COM{X}
The Arduino library makes use of a submodule for the shared cellular module code. Please be sure to either install a bundled release zip below or perform a recursive clone locally.
- Visit the releases page for this project
- Download the most recent recent as a ZIP file, by expanding the Assets section of the release
- Make note of the download location
- Open Arduino IDE
- Select Sketch > Include Library > Add .ZIP Library and select the .zip file downloaded
- Restart Arduino IDE
The library will now be present for Arduino IDE to use. To update the library:
- Delete the library from your Arduino directory
- You can find the library to delete in your
Arduino/libraries
directory - OSX: in ~/Documents/Arduino/libraries
- You can find the library to delete in your
- Follow the steps in the Breakout SDK Installation section above
Tip: An alternative to downloading the library as a ZIP is to check the library out using
git
in the Arduino/libraries directory, or symlink the locally-checked out copy there, just be sure to update the submodules.
- Open Arduino IDE
- Visit
Tools
->Manage Libraries
- Search for
Paho
then install theArduinoMqtt
library, version1.5.1
or better
- Connect the board to your working machine with a USB cable.
- Enable Bootloader mode on the Developer Board:
- Press and hold the BOOT0 button underneath the Developer Board
- Press and hold the RST on the top of the Developer Board
- Release the RST on the top of the Developer Board
- Release the BOOT0 button to enable Bootloader mode
- Click Sketch > Upload to upload the example to the Developer Board
- Do not click
Upload Using Programmer
- Click the RST button when the sketch has finished uploading. Your sketch is now running on the device
If the board is in Bootloader mode the serial port won't be initialized and not available to monitor, see the troubleshooting section.
The LEDs on the Developer Board are set to function as the following:
- Red CHG LED - Lights up based on the battery charging level, will flicker dimly when no battery is connected.
- Yellow Status LED - lights up when the modem module is power on.
- Blue Network LED - lights up when the modem module is successfully registered to the mobile NB-IoT network.
- Red RST LED - lights up during the reset procedure. To place the module in firmware flashing mode, press the BOOT0 switch on the board when this LED lights up.
- WS2812 RGB LED - available for your application.
1.Sample
is the top-level file, it contains the sketch's setup() and loop() functions. You can uncomment one of the #include Sample*
directives, to enable a sample using a specific sensor. If you want to customize your sketch, you can do it directly here, or in the included modules.
-
SampleButton.h
,SampleGPS.h
,SampleTemperatureAndHumidity.h
andSampleUltrasonic.h
include the actual code for setting up and running samples using a button, GPS receiver, temperature/humidity sensor and ultrasonic proximity sensor respectively. -
config.h
is for you to set up your specific application.- un-comment out
#define USE_TLS_CLIENT_CERTIFICATES
,#define USE_TLS_USERNAME_PASSWORD
or#define USE_USERNAME_PASSWORD
to enable either TLS + certificates header (see below), the TLS + username/password, or username/password authentication respectively - Set
MQTT_BROKER_HOST
andMQTT_BROKER_PORT
to the location of your MQTT broker - Change
MQTT_KEEP_ALIVE
to 20 if your broker tends to reset connections on inactivity, you can adjust this keep alive interval to your needs - Set
MQTT_CLIENT_ID
to whatever you want your client ID to be, please note this must be unique across clients connected to your MQTT broker - Change
MQTT_PUBLISH_TOPIC
andMQTT_STATE_TOPIC
to the topics you want your sample to be publishing and listening to. If you want to go deeper, you can always define more topics to publish/subscribe to, no need to add them to theconfig.h
if you don't want to. - If you are using login/password authentication, set the credentials in
MQTT_LOGIN
andMQTT_PASSWORD
.
- un-comment out
-
tls_credentials.h
is for you to paste your TLS credentials, including device's certificate and private key (TLS_DEVICE_CERT
,TLS_DEVICE_PKEY
) and server's certificate authority certificate (TLS_SERVER_CA
). If you are using TLS + username/password authentication, you may just provide theTLS_SERVER_CA
certificate. -
modem.h
contains service procedures to initialize the modem on the AlfaKit. Refer to it if you're curious about what is happening under the hood. -
mqtt.h
contains shims to integrate with Paho MQTT client, and publishing/subscribing code. It is what you will want to hack on if you want to create more topics.
The core of Massive SDK for Arduino is the cross-platform SDK residing under src/massive-sdk
. For SARA-R410 and SARA-N410 this SDK supports plain UDP and TCP sockets (see OwlModemSocket
class for the interface). On top of this low-level interface you can build support for other application-level protocols.
-
U-Blox UDP datagram size limitation
- Problem: The U-Blox cellular module can receive up to 512 bytes of data in hex mode. Hence this is a limitation for UDP datagrams.
- Solution: partial solution would be to switch from the hex mode to binary mode. This shall double the amount of data received, yet it makes the code much more complex. So far 512 was a good upper limit, especially given the NB-IoT targets here, hence this wasn't explored.
-
Receiving the output
WARNING: Category 'Device' in library Wio LTE Arduino Library is not valid. Setting to 'Uncategorized'
in Arduino IDE.- Problem: Incorrect version of dfu-util. Using 0.8 or lower.
- Solution: Update dfu-util to 0.9+
- OSX: Type the following in a Terminal:
brew install dfu-util
- OSX: Type the following in a Terminal:
-
Unable to remove lithium battery from Developer Board.
- Problem: JST pings lock lithium battery into place.
- Solution: If the battery is pushed in a touch too far, it locks. Lift the pins from the JST connector and pull on the lithium battery cable or use a pair of needle nose pliers to get ahold of the connector. Be careful not to damage or puncture the battery as they can be dangerous if damaged. The JST connector has tabs that latch on and are not generally meant to be disconnected again.
-
No DFU capable USB device available
- Problem: Unable to upload firmware. Device is not in DFU mode.
DFU begin dfu-util 0.8 Copyright 2005-2009 Weston Schmidt, Harald Welte and OpenMoko Inc. Copyright 2010-2014 Tormod Volden and Stefan Schmidt This program is Free Software and has ABSOLUTELY NO WARRANTY Please report bugs to http://sourceforge.net/p/dfu-util/tickets/ dfu-util: Invalid DFU suffix signature dfu-util: A valid DFU suffix will be required in a future dfu-util release!!! dfu-util: No DFU capable USB device available DFU end
- Solution: Put Developer Board in DFU mode.
-
Can't connect to the network
- Problem: The device doesn't go online, blue LED is off, no data on the broker.
- Solution: Connecting to the network for the first time can take a minute or two. If the light doesn't go blue, try another location. You may not have cell coverage in your current location.