Espruino on RAK8212: Getting started

The RAK8212 is a versatile developer board ideally suited for prototyping IoT use-cases. LTE NB-IoT is one option to send telemetry data to a IoT platform or receive configuration data and firmware updates over the air.

iTracker-BG96-Remote-Positioning-Sensor-Node-Module-NBIoT-GPS-Tracker-Module-BLE-Bluetooth-5-0-GPRS

The board already includes a lot of sensors to play around with and cover a lot of typical IoT use-cases:

The NB-IoT connectivity is provided by the Quectel BG96 module.

Espruino is an open-source JavaScript interpreter for various microcontrollers (including the RAK8212) created 2012 by Gordon Williams. As JavaScript is used for programming the IoT use-cases and the applications can easily be pushed to the device using a Web IDE, Espruino is an ideal companion for the RAK8212.

In the following sections I try to help you (the reader) to get started with setting up Espruino on a RAK8212 module on a Windows PC.

Wiring up the J-Link Adapter

For initial flashing of the Espruino firmware you need a J-Link Adapter. This adapter has to support the Serial Wire Debug (SWD) interface.
Check the documentation of your J-Link adapter for the SWD connector pinout.
For Segger J-Link adapters, one source of information could be here: https://www.segger.com/products/debug-probes/j-link/technology/interface-description/

Connect the connector pins of the J-Link adapter with the related pin headers on the RAK8212 adapter board.

Connector SWD pinout | RAK8212 header pin label
VTref                | VDD
SWDIO                | SWDIO
SWCLK                | SWCLK
RESET                | RESET
GND                  | GND

When finished, attach J-Link adapter to the Windows PC using the USB cable.

jlink-wired-up

Download the Espruino firmware

You can download the Espruino firmware for the RAK8212 module on Espruino’s download page.

Under “Find a binary” choose the board “iTracker RAK8212”.

Download cutting edge build espruino_1v99_RAK8212.hex
Make sure to “save the link as” a file, and not get the firmware displayed in the browser and saving it from the browser.

Flash the Espruino firmware

Download, install and start Nordic nRFgo Studio on the Windows PC.

Then we select “nRF5x programing” in the Device Manager panel, and the following UI will be shown in front of us:

nrfgo_flash1

Press button “Erase all” to erase the firmware which had been programmed into the RAK8212 module before.

Select notepad tab “Program Application”, locate the file espruino_1v99_RAK8212.hex and press button “Program”. Flashing the firmware may take some minutes.

nrfgo_flash2

In the “Log” section on the bottom of the nRFgo Studio application, there should now be a statement like “Application espruino_1v99_RAK8212.hex programmed successfully.”

Set up serial terminal session

As you have plugged in the USB connector cable of the RAK8212 adapter board into your PC, a COM port should have been assigned to the serial interface. You can find out the assigned COM port using the Windows Device Manager. In my case, the COM port is COM19.

rak8212_adapter_board_com_port

Setup a serial connection to this COM port using the terminal application “putty”.
Enter the COM port name as “Serial line”, 9600 as “Speed” and “Serial” as “Connection type”.
Press the “Open” button to start the serial terminal session.

putty_setup

After pressing the RESET button the the RAK8212 adapter board, you should get an output in the terminal as follows:

espruino_terminal_start_banner

You now no longer need the J-Link adapter and can remove it from the RAK8212 adapter board.

Set up Web IDE

Download the Espruino Web IDE for the Chrome browser following the instructions here: https://www.espruino.com/Web+IDE

Run Espruino Web IDE from Chrome’s home screen (or the App Launcher).
Click the orange Connect/Disconnect icon in the Top Left.

You should be asked for the right COM port to use now. If everything goes well, the Web IDE will connect to your RAK8212.

espruino_web_ide_1
You can now start to play with some JavaScript examples and send them down pressing the button “Send to Espruino”.

espruino_web_ide_2

Now have fun with trying out some example programs and get familar with JavaScript programming in Espruino!

Advertisements

LTE NB-IoT: Send and receive a UDP message with Quectel BC66

Now that the firmware was updated to revision BC66NAR01A03_BETA0808 I managed to find out how to send a UDP message and receive a response message indication. The Quectel support informed that the “BC66 is not finally released” and there are a lot of hints about features being “preliminary” in the documentation. So, in the end, I had to collect information from different resources, which is currently really a pain point in my opinion.

Again, I used the terminal application “putty” on channel A at a baud rate of 115200 bps.
You have to press the on/off button to wake the module from sleeping.

A note to the NB-IoT SIM card provided by 1NCE: There is a 6-digit pin printed on the backside of the credit card sized SIM card holder. This is a little bit confusing, because I never got error messages regarding that the SIM card is locked. The 1NCE support stated:

“Wir haben Ihre SIM-Karte bereits vorab aktiviert. Eine Eingabe ihrer SIM-Pin ist in keinem Fall notwendig”

Good to know that 🙂

Following you find a list of AT commands that I used to send and receive a UDP message. On a PC visible to the internet I started a small UDP echo server written in Python. A good example can be found here: https://pythontic.com/modules/socket/udp-client-server-example

Enable full functionality

AT+CFUN=1
OK

Set default APN for PDP (only required once, is stored in NVRAM)
Provider: 1NCE

AT+QCGDEFCONT="IP","iot.1nce.net"
OK

Set to automatically report network registration status, when the module is
registered on the network, a URC will be reported.

AT+CEREG=1
OK

Reset the module now to make the APN settings effective

AT+QRST=1
F1: 0000 0000
V0: 0000 0000 [0001]
00: 0006 000C
01: 0000 0000
U0: 0000 0001 [0000]
T0: 0000 00B4
Leaving the BROM

If the module has not registered with the network before, this process can actually take minutes. You can check with

AT+CEREG?
+CEREG: 0,2

The “2” means, that the module is currently trying to attach or searching an operator to register to. “1” means registered to “home network” and “5” means the module is registered in a “roaming network”

AT+CEREG?
+CEREG: 0,5

Once registered, it should only take some seconds to get an IP address from the network

AT+CGPADDR?
+CGPADDR: 1,100.68.216.1

This IP actually matches the IP address reported in the 1NCE customer portal at https://portal.1nce.com/portal/customer/sims

1nce_status

Create a UDP socket

AT+QSOC=1,2,1
+QSOC=0

OK

Create a UDP socket connection to 134.3.23.128, port 20001

AT+QSOCON=0,20001,"134.3.23.128"
OK

Send the string “0123456789”

AT+QSOSEND=0,10,30313233343536373839
OK

If the UDP message manages to get to the UDP server and back (UDP messages may get lost), you should get the following “unsolicited result code” (URC), indicating that 16 bytes were received by the module.

+QSONMI=0,16

That’s an issue and possibly a bug. I would have expected something like

+QSONMI=0,16,30313233343536373839404142434445

Disconnect the UDP socket

AT+QSODIS=0
OK

Close the UDP socket

AT+QSOCL=0
OK

Some furtherAT commands of interest:

Query the available mobile network operators

AT+COPS?
+COPS: 0,2,"26201",9
           |       +-- NB-IoT 
           +---------- Operator is MCC=262/MNC=01 --> T-Mobile/Telekom

OK

Query current network status

AT+QENG=0
+QENG: 0,3740,0,156,"1D6E105",-78,-4,-74,15,8,"D325",0,
                    |                       | +-- Tracking Area Code (?)
                    |                       +---- Serving cell band
                    +---------------------------- Serving cell (hex) 
OK

Conclusion

  • This module currently seems to be immature. The documentation is a mess, and it isn’t even possible to send and receive a UDP message in a communication round trip.
  • T-Mobile’s IoT Network is available, even though I don’t live in an area of high population density.
  • Would be interesting if someone is able to locate this network cell “1D6E105”. I couldn’t find it.
  • With Quectel OpenCPU, it is possible to write a small application and flash it directly into the module. So there is no longer the need to have a separate MCU. This seems very innovative for me. I will probably try out if I can write such a custom application that reads an external sensor and periodically sends the sensor values via NB-IoT.
  • Please leave me a comment if you like to give feedback or share insight.

LTE NB-IoT: First steps with Quectel BC66

Narrowband IoT (NB-IoT) is a Low Power Wide Area Network (LPWAN) radio technology.
NB-IoT focuses specifically on indoor coverage (deep penetration), low cost, long battery life, and high connection density. NB-IoT uses a subset of the LTE standard, but limits the bandwidth to a single narrow-band of 200kHz.

With the Quectel BC66, I decided to try out one of the radio modules that clearly focuses on NB-IoT and does not provide any other 2.5G standards. I purchased a BC66-DVK development kit at https://www.tekmodul.de/produkt/bc66-dvk/ for about €35. As this company is located in Germany, the development kit arrived just a few days after ordering.

IMG_4197

From the “new” narrowband IoT carrier 1nce I got two NB-IoT SIM cards for free.

As described in the BC66-TE-B User Guide, I connected the development kit via a Micro USB cable to the PC and configured the terminal application “putty” to a baud rate of 115200 bps. After pressing the on/off button, the module actually woke up from sleep:

F1: 0000 0000
V0: 0000 0000 [0001]
00: 0006 000C
01: 0000 0000
U0: 0000 0001 [0000]
T0: 0000 00B4
Leaving the BROM


*MATREADY: 1

+CFUN: 0

+CPIN: READY

Time to get some information about the module. There is a preliminary “BC66 AT Commands Manual” (2018-04-23) that provides information on that (ask Quectel Customer Support for it).

Display Product Identification Information

ATI
Quectel_Ltd
Quectel_BC66
Revision: BC66NAR01A01

OK

Request Manufacturer Identification

AT+CGMI
Quectel_Ltd
Quectel_BC66
Revision: MTK_2625

OK

Request Manufacturer Revision

AT+CGMR
Revision: BC66NAR01A01

OK

After having some issues with verifying the PIN code on the SIM card I contacted the Quectel support staff, and they recommended to do a firmware update, as the BC66 is still in development process and I possibly had a rather outdated firmware on my module. The support sent me a link to an update program and gave instructions.

fw_update

Firmware update was successful, firmware revision is now BC66NAR01A03_BETA0808

ATI
Quectel_Ltd
Quectel_BC66
Revision: BC66NAR01A03_BETA0808

OK

Check the next blog posts to find out how the story goes on …

LoRa Gateway Antenna Upgrade

My self-assembled LoRa Gateway used to have an inexpensive SMA antenna, which actually did not fit to the “professional” casing with its prepared openings for Type-N connectors. And having plans to install the gateway somewhere outdoor sooner or later, I decided to upgrade the antenna. I ordered the following parts:

Here are some pictures how the installation looks now …

img_3493img_3491

And what about the effect?

I did some measurements before and after replacing the old antenna using the TTN Mapper app on iPhone and a LoRaWAN node based on the Adafruit Feather 32u4 with LoRa. On two measurement points in a distance of 1280m and 748m I measured the signal strengh two times.

Result: With the new antenna, the signal strengh improved from -117dBm to -112dBm

You will have to decide on your own if this gain of about 5 dBm actually justifies the purchase of such a more “professional” antenna. I think if you just want to play around and get experience, then an inexpensive SMA antenna is good enough. But if you actually plan to place the gateway outdoor, then maybe you should consider to do what I did.

ttnmapper

STM32 Microcontroller and LoRa Breakout Board

Another popular approach to build LoRa nodes is to use inexpensive but powerful 32-bit microcontrollers (like the STM32 family) in combination with a LoRa RF transceiver (like the Semtech SX1276).

To make it easier to build prototypes, there are vendors that provide modules that fit onto a breadboard, like the Adafruit RFM9X LoRa Packet Radio Breakout Board.

Sure, if you build your prototypes without a breadboard, you can also use the cheaper variant of directly using a HOPERF RFM95W Transceiver Module.

I am using a STM32F103C8. I don’t go into details about programming and flashing for the STM32 family of microprocessors. Pleaser refer to this page, which is a good starting point: http://wiki.stm32duino.com .

Wiring it up …

To communicate with the STM32 microcontroller, I use a FTDI USB-to-Serial interface cable.

stm32_adafruit_rfm9x_lora_Steckplatine

Next to the SPI interface of the RFM9x, also the data ports G0 and G1 are connected to the STM32.

The LoRaWAN stack …

Again we use the Arduino LMIC communication stack from https://github.com/matthijskooijman/arduino-lmic .

You need to adapt the pin mapping as follows:

const lmic_pinmap lmic_pins = { 
 .nss = PA4, 
 .rxtx = LMIC_UNUSED_PIN, 
 .rst = PB0, 
 .dio = {PA3, PB5, LMIC_UNUSED_PIN}, 
};

Use the ttn-otaa example to connect to The Things Network.

That’s it.

Please also check this interesting project, that uses similar components and software: CitizenSensorA low budget battery powered LoRa node to smart up your city at https://github.com/orangewaylab/CitizenSensor .

IMG_3488

 

Assembly of LoRa Gateway finished

Open issues

  • I don’t use a special antenna. This one has a SMA connector and I bought it together with the LoRa board from the Imst webshop. Would be nice to have an antenna with a Type N connector, as there are already fitting openings in the metal case.
  • To get rid of an additional power supply cable, I added a cheap passive PoE injector and splitter. In an outdoor installation, this should be better an active PoE solution.

Assembling my own LoRa Gateway

The christmas holidays are coming, and I decided to dive a little deeper into LoRaWAN, The Things Network, the LoRa Nodes and the data processing and visualization in the backend.

But all of the above is hard if there is no LoRa Gateway in the neighborhood 😬.

So I decided to assembly my own LoRa Gatway using the following components:

I couldn’t wait to start assembling the gateway, but unfortunately, I had no female-to-female jumper cable at hand, so I improvised with a breadboard.

The Things Network  Community Zürich provides instructions for assembling the components and for setting up the software: From zero to LoRaWAN network in a weekend. This was all I needed to follow to get the gateway up and running.

There are still many decision to make:

  • Use a simple backplane to connect Raspberry Pi with the iC880A-SPI board instead to use these jumper cables (already decided)
  • Outdoor or indoor installation? The casing says “outdoor”.
  • Outdoor scenario: External WiFi antenna or ethernet cable?
  • Outdoor scenario: Is the antenna sufficient, or do I need something more “professional” (expensive) ?
  • Outdoor scenario: 250V or 5V power cable or Power over Ethernet (PoE) solution?