Skip to content

File Transmision_NBIOT.cpp

FileList > firmware > Transmision_NBIOT.cpp

Go to the source code of this file

Implementation of functions for NB-IoT data transmission. More...

  • #include "Configuracion.h"
  • #include <ArduinoJson.h>
  • #include "Debug.h"
  • #include "Transmision_NBIOT.h"
  • #include "Alarma.h"

Public Attributes

Type Name
String co2 = "10"
CO2 value (initial example)
JsonDocument doc
JSON object.
String hexData
String that will contain the JSON data in hexadecimal format.
String hum = "70"
Humidity value (initial example)
String json_data
String that will contain the complete JSON payload.
String nox = "100"
NOx value (initial example)
String ppm1 = "100"
PM1.0 value (initial example)
String ppm10 = "100"
PM10.0 value (initial example)
String ppm25 = "100"
PM2.5 value (initial example)
String ppm4 = "100"
PM4.0 value (initial example)
const char * respuestas = { "", "OK", "NOTOK", "TIMEOUTERR", "RST"}
Array with the response types returned by the SIM7020 module.
String temp = "22"
Temperature value (initial example)
String voc = "15"
VOC value (initial example)

Public Functions

Type Name
bool SIM7020begin (void)
Initializes communication with the SIM7020 module.
byte SIM7020command (String command, String response1, String response2, unsigned long timeout, uint16_t repetitions)
Sends an AT command to the SIM7020 module and waits for a specific response.
String SIM7020read (void)
Reads messages sent by the SIM7020 module.
byte SIM7020waitFor (String response1, String response2, unsigned long timeOut)
Function that waits for a specific response with maximum time.
String jsonToHex (const JsonDocument & doc)
Converts a JSON object to a hexadecimal string.
void nbiot_enviar (void)
Transmits sensor data to the server.
void nbiot_inicializar (void)
Initializes the NB-IoT module (SIM7020).
void nbiot_paquete (void)
Creates the JSON payload with current sensor data.
void nbiot_transmitir (void)
Performs an HTTP POST request to the server.

Macros

Type Name
define DEBUG_LEVEL [**DEBUG\_NBIOT**](Debug_8h.md#define-debug_nbiot)
Redefinition of the debug level for this source file.
define DEBUG_TAG "NBIOT"
Tag when sending debug messages.

Detailed Description

This file contains global variable definitions and implementations of the functions declared in 'Transmision_NBIOT.h'.

Author:

[ALD-DSL/ATARI_RESEARCH_LAB]

Date:

[2024-07-22/2025-10-15]

Version:

2.0

Copyright:

GNU General Public License version 3 or later

Note:

This module is fundamental for connectivity and sending sensor-collected data to a remote monitoring platform.

Public Attributes Documentation

variable co2

CO2 value (initial example)

String co2;


variable doc

JSON object.

JsonDocument doc;


variable hexData

String that will contain the JSON data in hexadecimal format.

String hexData;


variable hum

Humidity value (initial example)

String hum;


variable json_data

String that will contain the complete JSON payload.

String json_data;


variable nox

NOx value (initial example)

String nox;


variable ppm1

PM1.0 value (initial example)

String ppm1;


variable ppm10

PM10.0 value (initial example)

String ppm10;


variable ppm25

PM2.5 value (initial example)

String ppm25;


variable ppm4

PM4.0 value (initial example)

String ppm4;


variable respuestas

Array with the response types returned by the SIM7020 module.

const char* respuestas[5];


variable temp

Temperature value (initial example)

String temp;


variable voc

VOC value (initial example)

String voc;


Public Functions Documentation

function SIM7020begin

Initializes communication with the SIM7020 module.

bool SIM7020begin (
    void
) 

Uses SIM7020 module-specific AT commands to detect if communication is correct and resets configuration to a predefined state.

Returns:

True if communication and configuration were successful


function SIM7020command

Sends an AT command to the SIM7020 module and waits for a specific response.

byte SIM7020command (
    String command,
    String response1,
    String response2,
    unsigned long timeout,
    uint16_t repetitions
) 

Parameters:

  • command The AT command to send.
  • response1 The expected response string to consider the command successful.
  • response2 String to search for if an "OK" response is not expected.
  • timeout Maximum wait time for the response in milliseconds.
  • repetitions Number of retries if the response is not as expected.

Returns:

OK if the response is as expected, NOTOK if not, TIMEOUTERR if timeout occurs.


function SIM7020read

Reads messages sent by the SIM7020 module.

String SIM7020read (
    void
) 

Returns:

String with the received message.


function SIM7020waitFor

Function that waits for a specific response with maximum time.

byte SIM7020waitFor (
    String response1,
    String response2,
    unsigned long timeOut
) 

Parameters:

  • response1 The expected response string to consider the command successful.
  • response2 String to search for if an "OK" response is not expected.
  • timeout Maximum wait time for the response in milliseconds.

Returns:

OK if the response is as expected, NOTOK if not, TIMEOUTERR if timeout occurs.


function jsonToHex

Converts a JSON object to a hexadecimal string.

String jsonToHex (
    const JsonDocument & doc
) 

Parameters:

  • doc The DynamicJsonDocument object to convert.

Returns:

String representing the JSON in hexadecimal format.


function nbiot_enviar

Transmits sensor data to the server.

void nbiot_enviar (
    void
) 

This is the main function for data transmission. Builds the JSON, converts it to hexadecimal and performs the HTTP POST request.


function nbiot_inicializar

Initializes the NB-IoT module (SIM7020).

void nbiot_inicializar (
    void
) 

Configures the serial port for communication with the module and executes a series of AT commands to ensure the module is operational and connected to the network.


function nbiot_paquete

Creates the JSON payload with current sensor data.

void nbiot_paquete (
    void
) 

Data is obtained from global variables and formatted into a JSON string.


function nbiot_transmitir

Performs an HTTP POST request to the server.

void nbiot_transmitir (
    void
) 

Uses SIM7020 module-specific AT commands to create an HTTP connection and send hexadecimal data as payload.


Macro Definition Documentation

define DEBUG_LEVEL

Redefinition of the debug level for this source file.

#define DEBUG_LEVEL `DEBUG_NBIOT`


define DEBUG_TAG

Tag when sending debug messages.

#define DEBUG_TAG `"NBIOT"`



The documentation for this class was generated from the following file firmware/Transmision_NBIOT.cpp