Skip to content

File Transmision_NBIOT.h

FileList > firmware > Transmision_NBIOT.h

Go to the source code of this file

  • #include "Configuracion.h"
  • #include <Arduino.h>
  • #include <ArduinoJson.h>

Public Functions

Type Name
void ReiniciarDispositivo (void)
Restarts the microcontroller.
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 NOTOK 2
define OK 1
define RST 2
define SERIALTIMEOUT 3000
define SIM7020baud 115200
define SIM7020board Serial1
define TIMEOUTERR 3

Public Functions Documentation

function ReiniciarDispositivo

Restarts the microcontroller.

inline void ReiniciarDispositivo (
    void
) 

Used for cases where it is not possible to establish a connection to the server.


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 NOTOK

#define NOTOK `2`

define OK

#define OK `1`

define RST

#define RST `2`

define SERIALTIMEOUT

#define SERIALTIMEOUT `3000`

define SIM7020baud

#define SIM7020baud `115200`

define SIM7020board

#define SIM7020board `Serial1`

define TIMEOUTERR

#define TIMEOUTERR `3`


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