Skip to main content

title

The world's first laptop with built-in LoRaWAN?

Using the Microchip RN2483 PICtail to connect to The Things Network

The Internet of Things (IoT) is growing increasingly popular, and with it, demand for connectivity. Traditional WiFi, wired Ethernet and cellular have been around for some time and are suitable for many connected devices, but when requirements include low power consumption, low cost and long range, there are now other solutions available.

Enter LoRaWAN (Long Range Wide Area Network), a wireless system that can be used with license-exempt spectrum to achieve incredible range, with a low cost of adoption. More detailed information on LoRaWAN can be found on the LoRa Alliance website, and in a recent post by Andrew Back.

title

Image source: thethingsnetwork.org

Also included in Andrew's post is information about The Things Network, a working prototype of a free and open data network. This allows users to connect nodes to LoRaWAN gateways which provide connectivity to the internet.

With a LoRaWAN gateway nearby, I thought it would be cool to have a mobile development platform upon which to experiment further with The Things Network.

In this post we will build such a solution using the Pi-Top, a Raspberry Pi based laptop, and a LoRaWAN compatibleMicrochip RN2483 development board.

Ease of development

title

The RN2483 is a self-contained module (880-6821) , and while some have made basic breakout boards, we chose to start with a plug and play development board (904-8468) for simple prototyping.

Useful features of this particular board include two SMA connectors for either 433MHz or 868MHz operation, with corresponding antennas, and an on-board USB-UART allowing for direct USB connection to a computer. Note that not all frequencies are available in all countries.

title

It was decided that the system would be tested first using the USB connection, before going on to connect the module directly to the serial port on the Raspberry Pi GPIO header.

Back to basics

title

In place of the OS supplied with the Pi-Top, and in order to provide a more familiar environment, a fresh install of Raspbian was loaded. This gave an opportunity to try out the most popular distribution for the Pi on the Pi-Top. The most recent version of Raspbian (at time of writing, 2016-03-18-raspbian-jessie.zip), was downloaded and written to an SD card.

Before removing the original Pi-Top SD card I checked for evidence of any Pi-Top-specific packages that would prove useful to add to a stock Raspbian install. Though the stock version works with the Pi-Top as-is, there are several useful improvements such as screen brightness control and battery monitoring that come with installation of these Pi-Top specific packages.

To add these to Raspbian, follow the steps below on the Pi:

  • navigate to /etc/apt/sources.list.d :

    • $ cd /etc/apt/sources.list.d

  • make a new file named pi-top.list :

    • $ sudo nano pi-top.list

  • add the following line:

    • deb http://apt.pi-top.com/raspbian/ jessie main

  • save the file and close the editor

  • get the required public key:

  • Add the key to the APT keyring

    • $ sudo apt-key add apt.pi-top.com.gpg.key

  • Ensure the Pi is up to date:

    • $ sudo apt-get update

    • $ sudo apt-get upgrade

  • install Pi-Top specific packages:

    • sudo apt-get install pt-battery pt-hub-controller

Whilst the above steps are not essential, your Raspbian is now more Pi-Top friendly. With this done, we can move on to testing the RN2483 module.

Serial communication

title

Connect the RN2483 development board to the Pi with the USB cable provided. To determine the correct serial port, the following command can be used:

$ dmesg | grep tty

This searches for 'tty' in the output from dmesg and we quickly ascertained that ttyACM0 was the serial port on the newly-inserted USB device.

Note that our module has the 1.0.0 firmware installed and should you need to update or change the firmware on your device, see here for more information.

For this section it is assumed you are comfortable with the use of terminal emulators such as Minicom or gtkterm. We will use Minicom, which can be installed on the Pi-Top with the following command:

  • $ sudo apt-get install minicom

And launched with the appropriate serial port and baud rate:

  • $ minicom -D /dev/ttyACM0 -b 57600

title

Referring to the RN2483 command reference user guide found here, a command was sent to retrieve version information from the board: 'sys get ver'. The module responds by printing information and we can see the link is working.Note that the guide advises enabling CR and LF in the terminal emulator settings, though we found this was not sufficient. After hitting return, nothing seemed to be happening. Following discussion on The Things Network forum, user kersing suggested using ctrl-M and ctrl-J to send a command instead, which seemed to solve the problem.

The following commands set up the module:

  • Ensure the module is reset and restarted:

    • sys reset

  • Set the network session key, in this case the default Things Network key

    • mac set nwkskey 2B7E151628AED2A6ABF7158809CF4F3C

  • Set the application session key, in this case the same key as the network session key, which is useful for initial testing:

    • mac set appskey 2B7E151628AED2A6ABF7158809CF4F3C

  • <p(Note that this allows anybody to see the payload on The Things Network's RESTful API, available here. However, if you have a privacy-sensitive application, you could use a private key.)
  • Set the unique network device address – you will have to use something different andnote that this was simply chosen for testing. It is recommended that you reserve address space on the Things Network Wiki:

    • mac set devaddr 90000009

  • Disable adaptive data rate:

    • mac set adr off

  • Save all changes above to user EEPROM:

    • mac save

  • Tell RN2483 module to attempt to connect to configured network:

    • mac join abp

  • Send a payload of '68656c6c6f576f726c64' ('helloWorld' in hexadecimal):

    • mac tx uncnf 1 68656c6c6f576f726c64

If this all worked correctly, it should now be possible to navigate to the RESTful API and see the payload: http://thethingsnetwork.org/api/v0/nodes/90000009/ (note that the section in bold will require changing to your chosen device address).

It is worth emphasising the importance of using the correct application session key. Using the default Things Network key is suitable for testing purposes but it is advisable that you make use of your own private key in production. First of all, it means the message payload is no longer available in plaintext on the public RESTful API. Secondly, it ensures message integrity: it prevents others from spoofing your devices/payloads, which would be possible if the application session key was known.

title

With the module functioning correctly and able to send packets to the network, we can switch to using the Pi's on-board serial UART rather than the development board's own USB-UART.

Serial on the Pi 3

title

The latest version of the Raspberry Pi allocates the main on-board UART to the Bluetooth Low Energy (BLE) module, and some modification is needed before it can be swapped and used on the GPIO header, as in previous revisions of the Pi.

More thorough information is available in this forum thread, but in brief, it is possible to switch the BLE to using the 'mini-UART', and restore UART0 to the GPIO header, thus making it accessible once again. This is a compromise and may impact BLE performance, but is suitable for our purposes. The following steps were taken to implement this change:

  • Ensure the firmware is up to date:

    • $ sudo rpi-update

  • Edit config.txt:

    • $ sudo nano /boot/config.txt

  • Add the following line at the end:

    • dtoverlay=pi3-miniuart-bt

  • Save and exit the editor.

  • Edit cmdline.txt and remove the following: 'console=serial0,115200':

    • $ sudo nano /boot/cmdline.txt

  • Save and exit the editor.

Reboot the system and you should now have UART0 TX + RX broken out to GPIO14 + GPIO15 (physical pins 8 and 10 on the Pi3).

Adding LoRaWAN to the Pi-Top

title

The Pi-Top has a compartment that houses the Pi, custom Pi-Top hub and has plenty of free space. By default it is recommended that the Pi is mounted to the right hand side of the case, to allow for access to the USB ports.

By shifting the Pi to a somewhat more centralised location within the Pi-Top, it is possible to mount the LoRaWAN module in such a way that allows for the 868MHz aerial to be connected through the access port in the side of the case. Whilst making it a touch less convenient to connect USB peripherals, it is still possible by accessing the Pi through the easily removable compartment cover.

This is a great solution for now, but it should also be possible to use a simpler breakout board for the RN2483 module, since we no longer require the USB-UART interface and other features of the development board we are using. This would free up a bit more room inside the Pi-Top and reduce cost.

title

A cable was made to connect the Pi-Top hub board and RN2483 development module, using 2mm pitch header pins and female jumper leads. A sensible precaution when adding wires to the Pi is powering down the system, in case of a slip or incorrect connection. Only 4 wires are needed, 3.3v, GND, TX + RX. Remember that TX at the Pi end needs to connect to RX at the module end, and vice versa! Information on the GPIO header on the Pi-Top hub board can be found here.

With everything connected up, the Pi was booted. It should now be possible to connect to the RN2483 module using the serial port ttyAMA0 rather than ttyACM0 as before. Taking this into account, try running Minicom or your preferred terminal emulator to check that all works as before.

LoRaWAN hacking in the field

title

The portability of the Pi-Top combined with access to the Pi's GPIO and space for extra hardware is a great platform ripe for modification. Indeed it was a relatively simple process to add the RN2483 development board and build a flexible, all-in-one tool for LoRaWAN and The Things Network development.

We have demonstrated transmitting messages from direct serial commands within a terminal emulator, but next steps would be to script or automate this, for example from within Python. This code by Marten Vijn may help to get you started.

title

In the meantime, we shall continue to enjoy our bright green hacking machine!

maker, hacker, doer
DesignSpark Electrical Logolinkedin