- Why do we need this NB_Generic library
- Changelog
- Prerequisites
- Installation
- Packages' Patches
- 1. For Adafruit nRF52840 and nRF52832 boards
- 2. For Teensy boards
- 3. For Arduino SAM DUE boards
- 4. For Arduino SAMD boards
- 5. For Adafruit SAMD boards
- 6. For Seeeduino SAMD boards
- 7. For STM32 boards
- 8. For RP2040-based boards using Earle Philhower arduino-pico core
- 9. For Portenta_H7 boards using Arduino IDE in Linux
- Libraries' Patches
- HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE
- Note for Platform IO using ESP32 LittleFS
- Reference
- Documentation
- Configuration Notes
- Examples
- Tools
- Example NBWebClient
- Debug Terminal Output Samples
- Debug
- Troubleshooting
- Issues
- TO DO
- DONE
- Contributions and Thanks
- Contributing
- License
- Copyright
Why do we need this NB_Generic library
This library is based on, modified, bug-fixed and improved from:
to add support to many boards besides Arduino MKR NB 1500
.
This NB_Generic library will finally provide these following features (certainly only if supported by the NB-IoT/LTE-M/GPRS modules)
- TCP Client (HTTP, HTTPS, MQTT, Blynk, WebSockets, ...)
- UDP data connections
- USSD (Sending USSD requests and decoding 7,8,16-bit responses)
- SMS (Sending and Receiving)
- u-blox LTE-M/NB-IoT Modems (SARA-R4xx, SARA-N4xx, but NOT SARA-N2xx).
- SIMCom LTE Modules (SIM7100E, SIM7500E, SIM7500A, SIM7600C, SIM7600E)
- SIMCom SIM7000E/A/G CAT-M1/NB-IoT Module
- SIMCom SIM7020E/A/G CAT-M1/NB-IoT Module
- Sequans Monarch LTE Cat M1/NB1 (VZM20Q)
This NB_Generic library currently supports these following boards:
-
nRF52 boards, such as AdaFruit Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox, etc.
-
SAM DUE
-
SAMD21
- Arduino MKR NB 1500
- Arduino SAMD21: ZERO, MKRs, NANO_33_IOT, etc.
- Adafruit SAMD21 (M0): ItsyBitsy M0, Feather M0, Feather M0 Express, Metro M0 Express, Circuit Playground Express, Trinket M0, PIRkey, Hallowing M0, Crickit M0, etc.
- Seeeduino: LoRaWAN, Zero, Femto M0, XIAO M0, Wio GPS Board, etc.
- SAMD51
- Adafruit SAMD51 (M4): Metro M4, Grand Central M4, ItsyBitsy M4, Feather M4 Express, Trellis M4, Metro M4 AirLift Lite, MONSTER M4SK Express, Hallowing M4, etc.
- Seeeduino: Wio Terminal, Grove UI Wireless
-
Teensy (4.1, 4.0, 3.6, 3.5, 3,2, 3.1, 3.0, LC)
-
ESP32 including ESP32-S2 (ESP32-S2 Saola, AI-Thinker ESP-12K, etc.)
-
ESP8266
-
STM32F/L/H/G/WB/MP1 boards (with 32+K Flash)
- Nucleo-144 (F429ZI, F767ZI, etc.)
- Nucleo-64
- Discovery
- Generic STM32F0, STM32F1, STM32F2, STM32F3, STM32F4, STM32F7 (with 64+K Flash): x8 and up
- STM32L0, STM32L1, STM32L4
- STM32G0, STM32G4
- STM32H7
- STM32WB
- STM32MP1
- LoRa boards
- 3-D printer boards
- Generic Flight Controllers
- Midatronics boards
- RP2040-based boards, such as NANO_RP2040_CONNECT, RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, using Arduino-mbed RP2040 core or Earle Philhower's arduino-pico core.
Arduino IDE 1.8.16+
for ArduinoTeensy core v1.55+
for Teensy (4.0, 3.6, 3.5, 3,2, 3.1, 3.0) boards andTeensy core v1.53+
for Teensy 4.1 boards using NativeEthernet.Arduino SAM DUE core v1.6.12+
for SAM DUE ARM Cortex-M3 boards.Arduino SAMD core 1.8.11+
for SAMD ARM Cortex-M0+ boards.Adafruit SAMD core 1.7.5+
for SAMD ARM Cortex-M0+ and M4 boards (Nano 33 IoT, etc.).Seeeduino SAMD core 1.8.1+
for SAMD21/SAMD51 boards (XIAO M0, Wio Terminal, etc.).Adafruit nRF52 v1.1.0+
for nRF52 boards such as Adafruit NRF52840_FEATHER, NRF52832_FEATHER, NRF52840_FEATHER_SENSE, NRF52840_ITSYBITSY, NRF52840_CIRCUITPLAY, NRF52840_CLUE, NRF52840_METRO, NRF52840_PCA10056, PARTICLE_XENON, NINA_B302_ublox, etc.ESP8266 Core 3.0.2+
for ESP8266-based boards. . To use ESP8266 core 2.7.1+ for LittleFS.ESP32 Core 2.0.0+
for ESP32-based boards.Arduino Core for STM32 v2.1.0+
for STM32 boards.Arduino mbed_rp2040 core 2.5.2+
for Arduino (Use Arduino Board Manager) RP2040-based boards, such as RASPBERRY_PI_PICO.Earle Philhower's arduino-pico core v1.9.5+
for RP2040-based boards such as RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040 and GENERIC_RP2040, etc.
The suggested way to install is to:
The best way is to use Arduino Library Manager
. Search for NB_Generic
, then select / install the latest version. You can also use this link for more detailed instructions.
- Navigate to NB_Generic page.
- Download the latest release
NB_Generic-main.zip
. - Extract the zip file to
NB_Generic-main
directory - Copy the whole
NB_Generic-main
folder to Arduino libraries' directory such as~/Arduino/libraries/
.
- Install VS Code
- Install PlatformIO
- Install NB_Generic library by using Library Manager. Search for NB_Generic in Platform.io Author's Libraries
- Use included platformio.ini file from examples to ensure that all dependent libraries will installed automatically. Please visit documentation for the other options and examples at Project Configuration File
To be able to compile, run and automatically detect and display BOARD_NAME on nRF52840/nRF52832 boards, you have to copy the whole nRF52 Packages_Patches directory into Adafruit nRF52 directory (~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0).
Supposing the Adafruit nRF52 version is 1.1.0. These files must be copied into the directory:
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/platform.txt
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/boards.txt
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/cores/nRF5/Udp.h
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/cores/nRF5/Print.h
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/cores/nRF5/Print.cpp
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/variants/NINA_B302_ublox/variant.h
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/variants/NINA_B302_ublox/variant.cpp
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/variants/NINA_B112_ublox/variant.h
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/variants/NINA_B112_ublox/variant.cpp
~/.arduino15/packages/adafruit/hardware/nrf52/1.1.0/cores/nRF5/Udp.h
Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z These files must be copied into the directory:
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/platform.txt
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/boards.txt
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Print.h
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Print.cpp
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B302_ublox/variant.h
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B302_ublox/variant.cpp
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B112_ublox/variant.h
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/variants/NINA_B112_ublox/variant.cpp
~/.arduino15/packages/adafruit/hardware/nrf52/x.yy.z/cores/nRF5/Udp.h
To be able to compile and run on Teensy boards, you have to copy the files in Packages_Patches for Teensy directory into Teensy hardware directory (./arduino-1.8.15/hardware/teensy/avr/boards.txt).
Supposing the Arduino version is 1.8.15. These files must be copied into the directory:
./arduino-1.8.15/hardware/teensy/avr/boards.txt
./arduino-1.8.15/hardware/teensy/avr/cores/teensy/Stream.h
./arduino-1.8.15/hardware/teensy/avr/cores/teensy3/Stream.h
./arduino-1.8.15/hardware/teensy/avr/cores/teensy4/Stream.h
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz These files must be copied into the directory:
./arduino-x.yy.zz/hardware/teensy/avr/boards.txt
./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy/Stream.h
./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy3/Stream.h
./arduino-x.yy.zz/hardware/teensy/avr/cores/teensy4/Stream.h
To be able to compile and run on SAM DUE boards, you have to copy the whole SAM DUE directory into Arduino sam directory (~/.arduino15/packages/arduino/hardware/sam/1.6.12).
Supposing the Arduino SAM core version is 1.6.12. This file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/sam/1.6.12/platform.txt
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/sam/x.yy.zz/platform.txt
To be able to compile, run and automatically detect and display BOARD_NAME on Arduino SAMD (Nano-33-IoT, etc) boards, you have to copy the whole Arduino SAMD Packages_Patches directory into Arduino SAMD directory (~/.arduino15/packages/arduino/hardware/samd/1.8.11).
Supposing the Arduino SAMD version is 1.8.11. Now only one file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/samd/1.8.11/platform.txt
Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/samd/x.yy.zz/platform.txt
Supposing the Arduino SAMD version is 1.8.9. These files must be copied into the directory:
~/.arduino15/packages/arduino/hardware/samd/1.8.9/platform.txt
~/.arduino15/packages/arduino/hardware/samd/1.8.9/cores/arduino/Arduino.h
Whenever a new version is installed, remember to copy these files into the new version directory. For example, new version is x.yy.z
These files must be copied into the directory:
~/.arduino15/packages/arduino/hardware/samd/x.yy.z/platform.txt
~/.arduino15/packages/arduino/hardware/samd/x.yy.z/cores/arduino/Arduino.h
This is mandatory to fix the notorious Arduino SAMD compiler error. See Improve Arduino compatibility with the STL (min and max macro)
...\arm-none-eabi\include\c++\7.2.1\bits\stl_algobase.h:243:56: error: macro "min" passed 3 arguments, but takes just 2
min(const _Tp& __a, const _Tp& __b, _Compare __comp)
Whenever the above-mentioned compiler error issue is fixed with the new Arduino SAMD release, you don't need to copy the Arduino.h
file anymore.
To be able to compile, run and automatically detect and display BOARD_NAME on Adafruit SAMD (Itsy-Bitsy M4, etc) boards, you have to copy the whole Adafruit SAMD Packages_Patches directory into Adafruit samd directory (~/.arduino15/packages/adafruit/hardware/samd/1.7.5).
Supposing the Adafruit SAMD core version is 1.7.5. This file must be copied into the directory:
~/.arduino15/packages/adafruit/hardware/samd/1.7.5/platform.txt
~/.arduino15/packages/adafruit/hardware/samd/1.7.5/cores/arduino/Print.h
~/.arduino15/packages/adafruit/hardware/samd/1.7.5/cores/arduino/Print.cpp
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:
~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/platform.txt
~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/cores/arduino/Print.h
~/.arduino15/packages/adafruit/hardware/samd/x.yy.zz/cores/arduino/Print.cpp
To be able to compile, run and automatically detect and display BOARD_NAME on Seeeduino SAMD (XIAO M0, Wio Terminal, etc) boards, you have to copy the whole Seeeduino SAMD Packages_Patches directory into Seeeduino samd directory (~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2).
Supposing the Seeeduino SAMD core version is 1.8.2. This file must be copied into the directory:
~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/platform.txt
~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/cores/arduino/Arduino.h
~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/cores/arduino/Print.h
~/.arduino15/packages/Seeeduino/hardware/samd/1.8.2/cores/arduino/Print.cpp
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:
~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/platform.txt
~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Arduino.h
~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Print.h
~/.arduino15/packages/Seeeduino/hardware/samd/x.yy.zz/cores/arduino/Print.cpp
To use LAN8720 on some STM32 boards
- Nucleo-144 (F429ZI, NUCLEO_F746NG, NUCLEO_F746ZG, NUCLEO_F756ZG)
- Discovery (DISCO_F746NG)
- STM32F4 boards (BLACK_F407VE, BLACK_F407VG, BLACK_F407ZE, BLACK_F407ZG, BLACK_F407VE_Mini, DIYMORE_F407VGT, FK407M1)
you have to copy the files stm32f4xx_hal_conf_default.h and stm32f7xx_hal_conf_default.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.1.0/system) to overwrite the old files.
Supposing the STM32 stm32 core version is 2.1.0. These files must be copied into the directory:
~/.arduino15/packages/STM32/hardware/stm32/2.1.0/system/STM32F4xx/stm32f4xx_hal_conf_default.h
for STM32F4.~/.arduino15/packages/STM32/hardware/stm32/2.1.0/system/STM32F7xx/stm32f7xx_hal_conf_default.h
for Nucleo-144 STM32F7.
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory:
~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/system/STM32F4xx/stm32f4xx_hal_conf_default.h
- `~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/system/STM32F7xx/stm32f7xx_hal_conf_default.h
To use Serial1 on some STM32 boards without Serial1 definition (Nucleo-144 NUCLEO_F767ZI, Nucleo-64 NUCLEO_L053R8, etc.) boards, you have to copy the files STM32 variant.h into STM32 stm32 directory (~/.arduino15/packages/STM32/hardware/stm32/2.1.0). You have to modify the files corresponding to your boards, this is just an illustration how to do.
Supposing the STM32 stm32 core version is 2.1.0. These files must be copied into the directory:
~/.arduino15/packages/STM32/hardware/stm32/2.1.0/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h
for Nucleo-144 NUCLEO_F767ZI.~/.arduino15/packages/STM32/hardware/stm32/2.1.0/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h
for Nucleo-64 NUCLEO_L053R8.
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz, these files must be copied into the corresponding directory:
~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/STM32F7xx/F765Z(G-I)T_F767Z(G-I)T_F777ZIT/NUCLEO_F767ZI/variant.h
~/.arduino15/packages/STM32/hardware/stm32/x.yy.zz/variants/STM32L0xx/L052R(6-8)T_L053R(6-8)T_L063R8T/NUCLEO_L053R8/variant.h
8. For RP2040-based boards using Earle Philhower arduino-pico core
To be able to automatically detect and display BOARD_NAME on RP2040-based boards (RASPBERRY_PI_PICO, ADAFRUIT_FEATHER_RP2040, GENERIC_RP2040, etc) boards, you have to copy the file RP2040 platform.txt into rp2040 directory (~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0).
Supposing the rp2040 core version is 1.4.0. This file must be copied into the directory:
~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0/platform.txt
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied into the directory:
~/.arduino15/packages/rp2040/hardware/rp2040/x.yy.zz/platform.txt
With core after v1.5.0, this step is not necessary anymore thanks to the PR Add -DBOARD_NAME="{build.board}" #136.
Some libraries, such as Adafruit DHT-sensor-library, require the definition of microsecondsToClockCycles(). To be able to compile and run on RP2040-based boards, you have to copy the files in RP2040 Arduino.h into rp2040 directory (~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0).
Supposing the rp2040 core version is 1.4.0. This file must be copied to replace:
~/.arduino15/packages/rp2040/hardware/rp2040/1.4.0/cores/rp2040/Arduino.h
Whenever a new version is installed, remember to copy this file into the new version directory. For example, new version is x.yy.zz This file must be copied to replace:
~/.arduino15/packages/rp2040/hardware/rp2040/x.yy.zz/cores/rp2040/Arduino.h
With core after v1.5.0, this step is not necessary anymore thanks to the PR Add defs for compatibility #142.
To be able to upload firmware to Portenta_H7 using Arduino IDE in Linux (Ubuntu, etc.), you have to copy the file portenta_post_install.sh into mbed_portenta directory (~/.arduino15/packages/arduino/hardware/mbed_portenta/2.5.2/portenta_post_install.sh).
Then run the following command using sudo
$ cd ~/.arduino15/packages/arduino/hardware/mbed_portenta/2.5.2
$ chmod 755 portenta_post_install.sh
$ sudo ./portenta_post_install.sh
This will create the file /etc/udev/rules.d/49-portenta_h7.rules
as follows:
# Portenta H7 bootloader mode UDEV rules
SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="035b", GROUP="plugdev", MODE="0666"
Supposing the ArduinoCore-mbed core version is 2.5.2. Now only one file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/mbed_portenta/2.5.2/portenta_post_install.sh
Whenever a new version is installed, remember to copy this files into the new version directory. For example, new version is x.yy.zz
This file must be copied into the directory:
~/.arduino15/packages/arduino/hardware/mbed_portenta/x.yy.zz/portenta_post_install.sh
To avoid dtostrf
compile error in some MQTT-related examples, fix the Adafruit_MQTT_Library
by copying the following file into the ~/Arduino/libraries/Adafruit_MQTT_Library
directory to overwrite the old file:
HOWTO Install esp32 core for ESP32-S2 (Saola, AI-Thinker ESP-12K) and ESP32-C3 boards into Arduino IDE
These are instructions demonstrating the steps to install esp32-s2/c3 core on Ubuntu machines. For Windows or other OS'es, just follow the the similar principles and steps.
-
Windows 10, follows these steps in Steps to install Arduino ESP32 support on Windows
-
Mac OS, follows these steps in Installation instructions for Mac OS
-
Fedora, follows these steps in Installation instructions for Fedora
-
openSUSE, follows these steps in Installation instructions for openSUSE
-
You can also try to add package_esp32_dev_index.json into Arduino IDE
File - Preferences - Additional Boards Manager URLs
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_dev_index.json
and have Board Manager auto-install the development esp32 core. For example : esp32 core v2.0.0-alpha1
If you're already successful in testing the core, after installing by using the above procedures, you don't need to follows the hereafter manual steps.
Assuming you already installed Arduino IDE ESP32 core and the installed directory is
/home/your_account/.arduino15/packages/esp32
First, copy the whole original esp32 core to another safe place. Then delete all the sub-directories of
/home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.4
Just use Arduino IDE Board Manager to install ESP32 Arduino Release 1.0.6 based on ESP-IDF v3.3.5. This official v1.06 core doesn't have esp32-s2/s3 support. You have to download and use the latest master branch.
As of April 16th 2021, the esp32-s2/c3 board support has been included in master branch of esp32 core. Download esp32 core, master branch in the zip format.
Copy all subdirectories of esp32 core into /home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.6
Download esp32-s2 Toolchain corresponding to your environment (linux-amd64, win64, etc.).
For example xtensa-esp32s2-elf-gcc8_4_0-esp-2020r3-linux-amd64.tar.gz
, then un-archive.
Download esptool int the zip
format:
esptool-3.0.zip
Copy whole xtensa-esp32s2-elf
directory into /home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools
Rename esptool-3.0
directory to esptool
Copy whole esptool
directory into /home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools
Download esp32-c3 Toolchain corresponding to your environment (linux-amd64, win64, etc.).
For exampleriscv32-esp-elf-gcc8_4_0-crosstool-ng-1.24.0-123-g64eb9ff-linux-amd64.tar.gz
, then un-archive.
Then using the similar steps as in
then copy whole riscv32-esp-elf
directory into /home/your_account/.arduino15/packages/esp32/hardware/esp32/1.0.6/tools
If you haven't installed a new version with WebServer.handleClient delay PR #4350 or haven't applied the above mentioned PR, you have to use the following patch.
To be able to run Config Portal on ESP32-S2 boards, you have to copy the files in esp32-s2 WebServer Patch directory into esp32-s2 WebServer library directory (~/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WebServer).
Supposing the esp32-s2 version is 1.0.4, these files WebServer.h/cpp
must be copied into the directory to replace:
~/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WebServer/src/WebServer.h
~/.arduino15/packages/esp32/hardware/esp32/1.0.4/libraries/WebServer/src/WebServer.cpp
That's it. You're now ready to compile and test for ESP32-S2 and ESP32-C3 now
From esp32 core v1.0.6+, LittleFS_esp32 v1.0.6
has been included and this step is not necessary anymore.
In Platform IO, to fix the error when using LittleFS_esp32 v1.0
for ESP32-based boards with ESP32 core v1.0.4- (ESP-IDF v3.2-), uncomment the following line
from
//#define CONFIG_LITTLEFS_FOR_IDF_3_2 /* For old IDF - like in release 1.0.4 */
to
#define CONFIG_LITTLEFS_FOR_IDF_3_2 /* For old IDF - like in release 1.0.4 */
It's advisable to use the latest LittleFS_esp32 v1.0.5+
to avoid the issue.
Thanks to Roshan to report the issue in Error esp_littlefs.c 'utime_p'
Currently, check Reference of MKRNB
This library enable you to do most of the operations you can do with a NB phone: place and receive voice calls, send and receive SMS, and connect to the internet over a GPRS network. The onboard NB-IoT/LTE-M/GPRS module, operates in 3G with a 2G fallback.
The NB-IoT/LTE-M/GPRS modem transfers data, received from a serial port, to the NB-IoT/LTE-M/GPRS network. The modem executes operations via a series of AT commands. The library abstracts low level communications between the modem and SIM card. It relies on the Serial library for communication between the modem and your board.
As the library enables multiple types of functionality, there are a number of different classes.
NB
class takes care of commands to the radio modem. This handles the connectivity aspects of the module and registers your system in the NB infrastructure. All of your NB-IoT/LTE-M/GPRS programs will need to include an object of this class to handle the necessary low level communication.NB_SMS
class manages Sending/Receiving SMS messages.GPRS
class manages connecting to the internet.NBClient
class includes implementations for a client, similar to the Ethernet and WiFi libraries.NBUDP
class enables UDP message to be sent and receivedNBModem
class facilitates diagnostic communication with the modem.NBScanner
class provides diagnostic information about the network and carrier.NBPIN
class provides utilities for communicating with the SIM card.
NB
class is the base class for all NB based functions to prepare communicating with the modem.
NB(bool debug = false);
debug
: bool (default FALSE) flag for turning on the debug mode. This will print out the AT commands from the modem.
/** Constructor
@param debug Determines debug mode
*/
NB(bool debug = false);
/** Start the NB IoT modem, attaching to the NB IoT or LTE Cat M1 network
@param pin SIM PIN number (4 digits in a string, example: "1234"). If
NULL the SIM has no configured PIN.
@param apn (optional) APN to use
@param restart Restart the modem. Default is TRUE. The modem receives
a signal through the Ctrl/D7 pin. If it is shut down, it will
start-up. If it is running, it will restart. Takes up to 10
seconds
@param synchronous If TRUE the call only returns after the Start is complete
or fails. If FALSE the call will return immediately. You have
to call repeatedly ready() until you get a result. Default is TRUE.
@return If synchronous, NB_NetworkStatus_t. If asynchronous, returns 0.
*/
NB_NetworkStatus_t begin(const char* pin = 0, bool restart = true, bool synchronous = true);
NB_NetworkStatus_t begin(const char* pin, const char* apn, bool restart = true, bool synchronous = true);
NB_NetworkStatus_t begin(const char* pin, const char* apn, const char* username, const char* password, bool restart = true, bool synchronous = true);
/** Check network access status
@return 1 if Alive, 0 if down
*/
int isAccessAlive();
/** Shutdown the modem (power off really)
@return true if successful
*/
bool shutdown();
/** Secure shutdown the modem (power off really)
@return always true
*/
bool secureShutdown();
/** Get last command status
@return returns 0 if last command is still executing, 1 success, >1 error
*/
int ready();
void setTimeout(unsigned long timeout);
unsigned long getTime();
unsigned long getLocalTime();
bool setTime(unsigned long const epoch, int const timezone = 0);
NB_NetworkStatus_t status();
NB_SMS
is the base class for all NB functions handling receiving and sending SMS messages.
NB_SMS(bool synch = true);
synch
: bool (default TRUE) flag for the SMS service to be synchronous
/** Constructor
@param synch Determines sync mode
*/
NB_SMS(bool synch = true);
/** Write a character in SMS message
@param c Character
@return size
*/
size_t write(uint8_t c);
/** Select SMS charset
@param charset Character set, one of "IRA" (default), "GSM", or "UCS2", reads from modem if null.
@return returns first char of charset identifier on success and 0 on error
*/
int setCharset(const char* charset = nullptr);
/** Begin a SMS to send it
@param to Destination
@return error command if it exists
*/
int beginSMS(const char* to);
/** Get last command status
@return returns 0 if last command is still executing, 1 success, >1 error
*/
int ready();
/** End SMS
@return error command if it exists
*/
int endSMS();
/** Check if SMS available and prepare it to be read
@return number of bytes in a received SMS
*/
int available();
/** Read sender number phone
@param number Buffer for save number phone
@param nlength Buffer length
@return 1 success, >1 error
*/
int remoteNumber(char* number, int nlength);
/** Read one char for SMS buffer (advance circular buffer)
@return byte
*/
int read();
/** Read a byte but do not advance the buffer header (circular buffer)
@return byte
*/
int peek();
/** Delete the SMS from Modem memory and process answer
*/
void flush();
/** Delete all read and sent SMS from Modem memory and process answer
*/
void clear(int flag = NB_SMS_CLEAR_READ_SENT);
GPRS
is the base class for all GPRS functions and is responsible for including the files that are part of the library that involve TCP, UDP and SSL communication.
GPRS();
none.
GPRS();
virtual ~GPRS();
/** Attach to GPRS/NB network
@return connection status
*/
NB_NetworkStatus_t networkAttach()
{
return attachGPRS();
};
/** Detach GPRS/NB network
@return connection status
*/
NB_NetworkStatus_t networkDetach(){ return detachGPRS(); };
/** Returns 0 if last command is still executing
@return 1 if success, >1 if error
*/
int ready();
/** Attach to GPRS service
@param synchronous Sync mode
@return connection status
*/
NB_NetworkStatus_t attachGPRS(bool synchronous = true);
/** Detach GPRS service
@param synchronous Sync mode
@return connection status
*/
NB_NetworkStatus_t detachGPRS(bool synchronous = true);
/** Get actual assigned IP address in IPAddress format
@return IP address in IPAddress format
*/
IPAddress getIPAddress();
void setTimeout(unsigned long timeout);
NB_NetworkStatus_t status();
NBClient
is the base class for all GPRS client based functions to create clients that can connect to servers and send and receive data.
It is not called directly, but invoked whenever you use a function that relies on it.
NBClient(bool synch = true);
synch
: bool (default TRUE) flag for the Client using synchronous mode
/** Constructor
@param synch Sync mode
*/
NBClient(bool synch = true);
/** Constructor
@param socket Socket
@param synch Sync mode
*/
NBClient(int socket, bool synch);
virtual ~NBClient();
/** Get last command status
@return returns 0 if last command is still executing, 1 success, >1 error
*/
virtual int ready();
/** Connect to server by IP address
@param (IPAddress)
@param (uint16_t)
@return returns 0 if last command is still executing, 1 success, 2 if there are no resources
*/
int connect(IPAddress, uint16_t);
int connectSSL(IPAddress, uint16_t);
/** Connect to server by hostname
@param host Hostname
@param port Port
@return returns 0 if last command is still executing, 1 success, 2 if there are no resources
*/
int connect(const char *host, uint16_t port);
int connectSSL(const char *host, uint16_t port);
/** Initialize write in request
@param sync Sync mode
*/
void beginWrite(bool sync = false);
/** Write a character in request
@param c Character
@return size
*/
size_t write(uint8_t c);
/** Write a characters buffer in request
@param buf Buffer
@return buffer size
*/
size_t write(const uint8_t *buf);
/** Write a characters buffer with size in request
@param (uint8_t*) Buffer
@param (size_t) Buffer size
@return buffer size
*/
size_t write(const uint8_t*, size_t);
/** Finish write request
@param sync Sync mode
*/
void endWrite(bool sync = false);
/** Check if connected to server
@return 1 if connected
*/
uint8_t connected();
operator bool();
/** Read from response buffer and copy size specified to buffer
@param buf Buffer
@param size Buffer size
@return bytes read
*/
int read(uint8_t *buf, size_t size);
/** Read a character from response buffer
@return character
*/
int read();
/** Check if exists a response available
@return 1 if exists, 0 if not exists
*/
int available();
/** Read a character from response buffer but does not move the pointer.
@return character
*/
int peek();
/** Flush response buffer
*/
void flush();
/** Stop client
*/
void stop();
virtual void handleUrc(const String& urc);
NBSSLClient
is the base class for all GPRS SSL client based functions to create clients that can connect to servers and send and receive data.
It is not called directly, but invoked whenever you use a function that relies on it.
NBSSLClient(bool synch = true);
synch
: bool (default TRUE) flag for the SSL Client using synchronous mode
NBSSLClient(bool synch = true);
NBSSLClient(const NBRootCert* myRCs, int myNumRCs, bool synch = true);
virtual ~NBSSLClient();
virtual int ready();
virtual int iterateCerts();
virtual int connect(IPAddress ip, uint16_t port);
virtual int connect(const char* host, uint16_t port);
NBModem
is the base class for functions facilitating diagnostic communication with the modem.
It is not called directly, but invoked whenever you use a function that relies on it.
NBModem();
none
/** Constructor */
NBModem();
/** Check modem response and restart it
*/
int begin();
/** Obtain modem IMEI (command AT)
@return modem IMEI number
*/
String getIMEI();
/** Obtain SIM card ICCID (command AT)
@return SIM ICCID number
*/
String getICCID();
NBScanner
is the base class for functions providing diagnostic information about the network and carrier.
It is not called directly, but invoked whenever you use a function that relies on it.
NBScanner(bool trace = false);
trace
: bool (default FALSE) flag. If TRUE, dumps all AT dialogue to Serial
/** Constructor
@param trace if true, dumps all AT dialogue to Serial
@return -
*/
NBScanner(bool trace = false);
/** begin (forces modem hardware restart, so we begin from scratch)
@return Always returns IDLE status
*/
NB_NetworkStatus_t begin();
/** Read current carrier
@return Current carrier
*/
String getCurrentCarrier();
/** Obtain signal strength
@return Signal Strength
*/
String getSignalStrength();
/** Search available carriers
@return A string with list of networks available
*/
String readNetworks();
NBPIN
is the base class for all NB based functions that deal with interacting with the PIN on the SIM card.
NBPIN();
none
/** Constructor */
NBPIN();
/** Check modem response and restart it
*/
void begin();
/** Check if PIN lock or PUK lock is activated
@return 0 if PIN lock is off, 1 if PIN lock is on, -1 if PUK lock is on, -2 if error exists
*/
int isPIN();
/** Check if PIN code is correct and valid
@param pin PIN code
@return 0 if is correct, -1 if is incorrect
*/
int checkPIN(String pin);
/** Check if PUK code is correct and establish new PIN code
@param puk PUK code
@param pin New PIN code
@return 0 if successful, otherwise return -1
*/
int checkPUK(String puk, String pin);
/** Change PIN code
@param old Old PIN code
@param pin New PIN code
*/
void changePIN(String old, String pin);
/** Change PIN lock status
@param pin PIN code
*/
void switchPIN(String pin);
/** Check if modem was registered in NB-IoT/LTE-M/GPRS network
@return 0 if modem was registered, 1 if modem was registered in roaming, -1 if error exists
*/
int checkReg();
/** Return if PIN lock is used
@return true if PIN lock is used, otherwise, return false
*/
bool getPINUsed();
/** Set PIN lock status
@param used New PIN lock status
*/
void setPINUsed(bool used);
NBUDP
is the base class for all NB based functions enabling UDP message to be sent and received.
NBUDP();
none
NBUDP(); // Constructor
virtual ~NBUDP();
virtual uint8_t begin(uint16_t); // initialize, start listening on specified port. Returns 1 if successful, 0 if there are no sockets available to use
virtual void stop(); // Finish with the UDP socket
// Sending UDP packets
// Start building up a packet to send to the remote host specific in ip and port
// Returns 1 if successful, 0 if there was a problem with the supplied IP address or port
virtual int beginPacket(IPAddress ip, uint16_t port);
// Start building up a packet to send to the remote host specific in host and port
// Returns 1 if successful, 0 if there was a problem resolving the hostname or port
virtual int beginPacket(const char *host, uint16_t port);
// Finish off this packet and send it
// Returns 1 if the packet was sent successfully, 0 if there was an error
virtual int endPacket();
// Write a single byte into the packet
virtual size_t write(uint8_t);
// Write size bytes from buffer into the packet
virtual size_t write(const uint8_t *buffer, size_t size);
using Print::write;
// Start processing the next available incoming packet
// Returns the size of the packet in bytes, or 0 if no packets are available
virtual int parsePacket();
// Number of bytes remaining in the current packet
virtual int available();
// Read a single byte from the current packet
virtual int read();
// Read up to len bytes from the current packet and place them into buffer
// Returns the number of bytes read, or 0 if none are available
virtual int read(unsigned char* buffer, size_t len);
// Read up to len characters from the current packet and place them into buffer
// Returns the number of characters read, or 0 if none are available
virtual int read(char* buffer, size_t len) { return read((unsigned char*)buffer, len); };
// Return the next byte from the current packet without moving on to the next byte
virtual int peek();
virtual void flush(); // Finish reading the current packet
// Return the IP address of the host who sent the current incoming packet
virtual IPAddress remoteIP();
// Return the port of the host who sent the current incoming packet
virtual uint16_t remotePort();
virtual void handleUrc(const String& urc);
Select one and only one NB module to use (true
) as follows:
//////////////////////////////////////////////
#if defined(ARDUINO_SAMD_MKRNB1500)
#define SerialNB SerialSARA
#define NB_RESETN SARA_RESETN
#define NB_PWR SARA_PWR_ON
#else
// Override the default (and certainly not good) pins and port
// Only for boards other than ARDUINO_SAMD_MKRNB1500
#define NB_RESETN (10u)
#define NB_PWR (11u)
#if ESP8266
// Using Software Serial for ESP8266, as Serial1 is TX only
#define NB_USING_SOFTWARE_SERIAL true
#else
// Optional Software Serial here for other boards, but not advised if HW Serial available
#define NB_USING_SOFTWARE_SERIAL false
#endif
#if NB_USING_SOFTWARE_SERIAL
#warning Using default SerialNB = SoftwareSerial
#define D8 (15)
#define D7 (13)
#include <SoftwareSerial.h>
SoftwareSerial swSerial(D7, D8); // (D7, D8, false, 256); // (RX, TX, false, 256);
#define SerialNB swSerial
#else
#warning Using default SerialNB = HardwareSerial Serial1
#define SerialNB Serial1
#endif // NB_USING_SOFTWARE_SERIAL
#warning You must connect the Modem correctly and modify the pins / Serial port here
#endif
//////////////////////////////////////////////
//////////////////////////////////////////////
#define NB_MODEM_SARAR4 true
//////////////////////////////////////////////
// Not supported yet
#define NB_MODEM_SIM7000 false
#define NB_MODEM_XBEE false
#define NB_MODEM_SEQUANS_MONARCH false
The unselected module #define
can be deleted or left as is (false
)
For example
// Only one #define with true is enough
#define NB_MODEM_UBLOX true
Select the corresponding Serial
port to use to communicate (sending AT conmmands and receiving responses) to NB module
Remember to connect the board and modem correspondingly.
#define SerialNB Serial1
For example, the u-blox SARA U201 requires a reset pin and another pin to control the low-power mode.
Those pins are named here in this library as NB_RESETN
and NB_PWR
.
Default NB_RESETN
pin is set as 10, and NB_PWR
as 11. You can override the default pin settings in the sketch as follows:
// Optional usage of NB_RESETN and NB_PWR. Need to be here only when true. Default is false
#define UBLOX_USING_RESET_PIN true
#define UBLOX_USING_LOW_POWER_MODE true
// Override the default (and certainly not good) pins and port
// Only for boards other than ARDUINO_SAMD_MKRNB1500
#define NB_RESETN (10u)
#define NB_PWR (11u)
Depending on the NB module, the pins' requirements are different. Please follow the instructions for the related NB module.
Example NBWebClient
1. File NBWebClient.ino
#include "defines.h"
// Please enter your sensitive data in the Secret tab or arduino_secrets.h
// PIN Number
const char PINNUMBER[] = SECRET_PINNUMBER;
// initialize the library instance
NBClient client;
GPRS gprs;
NB nbAccess;
// URL, path and port (for example: example.org)
char server[] = "arduino.cc"; //"example.org";
char path[] = "/asciilogo.txt"; //"/";
int port = 80; // port 80 is the default for HTTP
// BaudRate to communicate to NB-IoT modem. If be limit to max 115200 inside modem
unsigned long baudRateSerialNB = 115200;
void setup()
{
// initialize serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial);
delay(200);
Serial.print(F("\nStarting NBWebClient on ")); Serial.println(BOARD_NAME);
Serial.println(NB_GENERIC_VERSION);
#if ( defined(DEBUG_NB_GENERIC_PORT) && (_NB_GENERIC_LOGLEVEL_ > 4) )
MODEM.debug(DEBUG_NB_GENERIC_PORT);
#endif
// connection state
boolean connected = false;
// After starting the modem with NB.begin() using PINNUMBER
// attach to the GPRS network
while (!connected)
{
if ((nbAccess.begin(PINNUMBER) == NB_READY) && (gprs.attachGPRS() == GPRS_READY))
{
connected = true;
}
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, port))
{
Serial.println("connected");
// Make a HTTP request:
client.print("GET ");
client.print(path);
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
}
else
{
// if you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available())
{
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.available() && !client.connected())
{
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
//while(true) { delay(1); }
delay(1000);
}
}
2. File defines.h
#ifndef defines_h
#define defines_h
#define DEBUG_NB_GENERIC_PORT Serial
// Debug Level from 0 to 5. Level 5 is to print out AT commands and responses
#define _NB_GENERIC_LOGLEVEL_ 5
#define SECRET_PINNUMBER ""
//////////////////////////////////////////////
#if defined(ARDUINO_SAMD_MKRNB1500)
#define SerialNB SerialSARA
#define NB_RESETN SARA_RESETN
#define NB_PWR SARA_PWR_ON
#else
// Override the default (and certainly not good) pins and port
// Only for boards other than ARDUINO_SAMD_MKRNB1500
#define NB_RESETN (10u)
#define NB_PWR (11u)
#if ESP8266
// Using Software Serial for ESP8266, as Serial1 is TX only
#define NB_USING_SOFTWARE_SERIAL true
#else
// Optional Software Serial here for other boards, but not advised if HW Serial available
#define NB_USING_SOFTWARE_SERIAL false
#endif
#if NB_USING_SOFTWARE_SERIAL
#warning Using default SerialNB = SoftwareSerial
#define D8 (15)
#define D7 (13)
#include <SoftwareSerial.h>
SoftwareSerial swSerial(D7, D8); // (D7, D8, false, 256); // (RX, TX, false, 256);
#define SerialNB swSerial
#else
#warning Using default SerialNB = HardwareSerial Serial1
#define SerialNB Serial1
#endif // NB_USING_SOFTWARE_SERIAL
#warning You must connect the Modem correctly and modify the pins / Serial port here
#endif
//////////////////////////////////////////////
//////////////////////////////////////////////
#define NB_MODEM_SARAR4 true
//////////////////////////////////////////////
// Not supported yet
#define NB_MODEM_SIM7000 false
#define NB_MODEM_XBEE false
#define NB_MODEM_SEQUANS_MONARCH false
//////////////////////////////////////////////
// libraries
#include <NB_Generic_Main.h>
#endif //defines_h
Debug is enabled by default on Serial. Debug Level from 0 to 4. To disable, change the _NB_Generic_LOGLEVEL_
to 0
// Use this to output debug msgs to Serial
#define DEBUG_NB_GENERIC_PORT Serial
// Debug Level from 0 to 5. Level 5 is to print out AT commands and responses
#define _NB_GENERIC_LOGLEVEL_ 5
If you get compilation errors, more often than not, you may need to install a newer version of the board's core or this library version.
Sometimes, the library will only work if you update the board core to the newer or older version because some function compatibility.
Submit issues to: NB_Generic issues
- Bug Searching and Killing
- Support more types of NB-IoT/LTE-M/GPRS modules
- Add support to Adafruit SAMD21 (Itsy-Bitsy M0, Metro M0, Feather M0 Express, etc.).
- Add support to Adafruit SAMD51 (Itsy-Bitsy M4, Metro M4, Grand Central M4, Feather M4 Express, METRO_M4_AIRLIFT_LITE, PYBADGE_AIRLIFT_M4, etc.).
- Add support to Adafruit nRF52 ( Feather nRF52832, nRF52840 Express, BlueFruit Sense, Itsy-Bitsy nRF52840 Express, Metro nRF52840 Express, NINA_B302_ublox, NINA_B112_ublox, etc.).
- Add support to SAM DUE.
- Add support to Teensy.
- Add support to all STM32F/L/H/G/WB/MP1 having 64K+ Flash program memory.
- Add support to Seeeduino SAMD21/SAMD51 boards (SEEED_WIO_TERMINAL, SEEED_FEMTO_M0, SEEED_XIAO_M0, Wio_Lite_MG126, WIO_GPS_BOARD, SEEEDUINO_ZERO, SEEEDUINO_LORAWAN, SEEED_GROVE_UI_WIRELESS, etc.)
- Add support to ESP32 (including ESP32-S2) and ESP8266 (only using Hardware Serial)
- Support u-blox Sara R4xx NB-IoT/LTE-M modules (SARA-R404M, SARA-R410M, SARA-R412M, SARA-N410, etc)
- Based on and modified from from Arduino MKRNB library.Thanks to the great works of these MKRNB Library's Contributors
- Thanks to good work of Miguel Wisintainer for initiating, inspriring, working with, developing, debugging, testing and maintaining.
⭐️ Miguel Wisintainer |
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell other people about this library
- The library is licensed under The GNU Lesser General Public License (LGPL-3.0)
- Copyright (c) 2018 Arduino SA. All rights reserved.
- Copyright 2021- Khoi Hoang