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