How arduino-libraries/mkrnb works
Project type and purpose
• This is an Arduino library (“MKRNB”) that provides a high-level C++ API for the MKR NB 1500 board to communicate over NarrowBand IoT (NB-IoT) or LTE Cat M1 networks.
• It is not a standalone application but a reusable connectivity library with example sketches showing how to use its public APIs.
File structure
• Top-level directories:
• src/ ← library implementation (C++ classes)
• examples/ ← Arduino sketches demonstrating library use cases
• docs/ ← detailed API documentation and usage guides
• .github/ ← CI workflows (compile examples, spell check, etc.)
• Key source files in src/:
• NBModem.* ← core AT-command modem interface
• NBClient.*, NBSSLClient.* ← TCP/SSL client implementations
• NBUdp.* ← UDP datagram support
• NB_SMS.* ← SMS send/receive
• NBScanner.*, NBPIN.* ← network scanning and SIM PIN management
• NBFileUtils.* ← file/flash-based utilities
• utility/ ← root certificates and socket buffering
• Configuration: library.properties for Arduino IDE integration, keywords.txt for syntax highlighting.
README for additional insights
• Reinforces that the library abstracts NB-IoT / LTE Cat M1 connectivity behind a uniform API.
• Examples in README link to reference docs on arduino.cc.
Main components
a. User Application Layer
• Arduino Sketch (one of the examples or any user-written .ino)
b. Library Public API Layer
• High-level classes: GPRS, NB, NBClient, NBSSLClient, NBUdp, NB_SMS, NBScanner, NBPIN
c. Core Modem Interface Layer
• NBModem: translates method calls into AT commands over serial/UART
• Modem.cpp / Modem.h: shared low-level communication routines
d. Hardware Abstraction / Board Layer
• SAMD21 MCU (runs Arduino core)
• u-blox SARA R4/N4 modem chip (handles radio protocols)
e. Network Layer
• Cellular network (NB-IoT or LTE Cat M1)
f. External Services
• TCP/UDP servers (HTTP, MQTT, NTP servers, custom backends)
• SMSC for SMS send/receive
• TLS certificate authorities for SSL validation
g. Utility Components
• Root certificate store (utility/NBRootCerts.h)
• Socket buffer management (utility/NBSocketBuffer.*)
Relationships and interactions
• The Arduino sketch invokes public API methods (e.g., begin(), connect(), sendSMS()).
• Public API classes call into NBModem to issue AT commands via Serial1 (UART).
• NBModem sends/receives AT commands to/from the u-blox chip.
• The hardware modem transmits IP packets over the cellular network.
• Remote services respond over the same path, with data bubbled back up through NBModem → public API → user sketch.
• For SSL/TLS, NBSSLClient wraps NBClient and negotiates a secure channel using built-in certificates.
Architectural patterns and design principles
• Layered architecture: clear separation between user code, API, modem driver, hardware, network, and external services.
• Dependency inversion: high-level classes depend on an abstract modem interface rather than concrete wires.
• Single Responsibility: each class/module handles one aspect (e.g., SMS, UDP, SSL) of communication.
• Utility modules isolate common functionality (buffering, cert store).
Detailed but concise
• Every public API class or hardware element critical to connectivity is represented.
• Data flow from application code down to bits on the air and back.