Espruino on RAK8212: Accessing the NB-IoT (NB1) modem

This blog post ist about how to communicate with the NB-IoT (NB1) modem on the Quectel BG96 module, and play around with some interesting AT commands, revealing information about the NB-IoT radio network and the provider.

The Nordic nRF52832 microcontroller on the RAK8212 board only has one hardware UART, which is many cases (like this case) is used to create a serial connection with components on the BG96 module. For this reason, you should not interface with the RAK8212 board using a serial connection over the USB cable, because if you do, your serial connection will go away as soon as the nRF52’s (single) UART is switched to establish this board-internal serial communication. However, the Espruino firmware is able to emulate a serial port over Bluetooth Low Enery (BLE) by software. Either your notebook or PC is already equipped with BLE communication, our you can get yourself a small BLE dongle for the USB port.

Please check the section “Requirements” on this Espruino page for more information about BLE:

I am using the Native Espruino IDE.

You can find some initial code for modem testing here:

We will use a slightly adapted code:

/* Example how to interface the modem using the "iTracker" and "AT" module. */

var at;
console.log("Connecting Cellular Modem ...");
require("iTracker").setCellOn(true, function (usart) {
  console.log("Cellular Modem connected.");
  at = require("AT").connect(usart);


function sendAtCommand(command) {
  var data = "";
  at.cmd(command + "\r\n", 1000, function cb(d) {
    if (d === undefined || d == "ERROR") {
      console.log("Error:", d);
    } else if (d == "OK") {
    else {
      data += (data ? "\n" : "") + d;
      return cb;

In the Espruino IDE, just connect to your RAK8212 module via Bluetooth LE, copy and paste this code to the right side of the IDE, and press the “Send to Espruino” button to transfer this JavaScript code to the RAM of the module.

What does this code do?

  • It internally “wires up” the nRF52’s UART with the UART of the BG96 module. For this, it uses a method of an Espruino module named “iTracker”.
  • It loads a utility module named “AT” that deals with non-blocking sending and receiving AT commands to modem-like devices over a serial line and tells this module which serial interface to use (“Serial1” on RAK8212).
  • It sends the “AT+GMR” command using the AT module and asynchronously collects the answer from the modem.

When uploading, the code will start to execute immediately and output something like

 ____                 _
|  __|___ ___ ___ _ _|_|___ ___
|  __|_ -| . |  _| | | |   | . |
|____|___|  _|_| |___|_|_|_|___|
1v99 (c) 2018 G.Williams
Espruino is Open Source. Our work is supported
only by sales of official boards and donations:
>Connecting Cellular Modem ...
Cellular Modem connected.

The AT command sent via the nRF52’s UART to the modem was “AT+GMR”.
The firmware version returned was BG96MAR02A05M1G.

A full list of AT commands of the Quectel BG96 module is publicly available. Just search for it on Quectel’s website.

One of the key advantages of Espruino is that we can use the JavaScript interpreter on the device interactively, so now let’s play around and try out some other AT commands:

Let’s use the JavaScript function sendAtCommand() to send some further AT commands:

Display Product Identification Information

Revision: BG96MAR02A05M1G



Creating a NB-IoT (NB1) connection

If you have a SIM card that allows to create NB-IoT (NB1) connections, the following sequence of AT commands can be used to check if you actually can use NB1 communication:

This example should work in Germany for Vodafone (values for 1NCE (Germany) in comment):

>sendAtCommand('AT+QCFG="band",0,0,80000,1'); // LTE Band 20 (1NCE: 80 for Band 8)
>sendAtCommand('AT+CGDCONT=1,"IP","vgesace.nb.iot"'); // "" for 1NCE
>sendAtCommand('AT+COPS=1,2,"26202",9'); // 26201 for 1NCE

It may take some minutes now for the modem to manually register at the network provider.
The modem LED should flash on-off-off-off periodically to indicate network search

With AT+CEREG?, you can check the current network registration status:

+CEREG: 2,5,"BB12","98","118F666",9

Status code 5 means that the modem has registered itself to the network in “roaming” modus. Check the specification of BG96 AT Commands for details about other status codes.
Two-byte tracking area code is “BB12”,
Four-byte E-UTRAN cell ID is “118F666”,
Access technology is LTE Cat NB1 (9).

Query some network information

+QNWINFO: "CAT-NB1","26202","LTE BAND 20",6290

So it acutally seems we have a NB1 connection using LTE Band 20.

Query the name of the registered network

+QSPN: "","Vodafone","DATA ONLY",0,"26202"

Query signal strength


+QCSQ: "CAT-NB1",80,-85,134,-6

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.


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:

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.


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:


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.


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.


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.


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


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:

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.

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


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

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:

Enable full functionality


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


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


Reset the module now to make the APN settings effective

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

+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”

+CEREG: 0,5

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


This IP actually matches the IP address reported in the 1NCE customer portal at


Create a UDP socket



Create a UDP socket connection to, port 20001


Send the string “0123456789”


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.


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


Disconnect the UDP socket


Close the UDP socket


Some furtherAT commands of interest:

Query the available mobile network operators

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


Query current network status

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


  • 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 for about €35. As this company is located in Germany, the development kit arrived just a few days after ordering.


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


+CFUN: 0


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

Revision: BC66NAR01A01


Request Manufacturer Identification

Revision: MTK_2625


Request Manufacturer Revision

Revision: BC66NAR01A01


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.


Firmware update was successful, firmware revision is now BC66NAR01A03_BETA0808

Revision: BC66NAR01A03_BETA0808


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 …


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.


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: .

Wiring it up …

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


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 .

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 .



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.