Skip to content

Module Core

The Core module is a directory that contains other submodules. These modules perform generic functions, such as controlling the internal clock, controlling opmodes, and other basic tasks.

Core/At

Use the Serial module to send AT commands to a modem. With this library we control the SIM868 communication modem and any other that requires sending and receiving AT commands.

It has three main methods, at::send() and at::searchLine() and at::read(). Please read the comments of every method on the source code

Configuration options for At module are descrbied at Serial Ports, in macros prefixed with SERIAL_AT

Example Codes

// Typical "AT" command should return OK on first line among other data in the
// following lines
at::send("AT");
if (at::searchLine(1, "OK", 500)) {
  // the modem has return a valid response
}

// global::buffer will contain the string "OK"
echo::info("result", global::buffer());

Using read()

at::send("AT");
at::read();
// global::buffer will contain all the response of the sent command
echo::info("result", global::buffer());

Core/CLI

Core/CMD

Core/Delay

The Arduino delay() or Mbed OS wait_us() method is used and therefore it is a blocking operation. Try to reduce its use and if necessary use short stops of hundreds of milliseconds.

Availabe delay methods by time:

// milliseconds
_delay::__(unsigned long NUMBER);

// microseconds
_delay::_(unsigned long NUMBER);

// seconds
_delay::s(unsigned long NUMBER);

Core/Echo

Used to display different types of messages on the debug serial port

Examples:

// echo::TYPE(mixed title, mixed value);
// mixed = any data type accepted by Arduino Serial or Mbed OS Serial

echo::info("Info message");
// -> print "[I] 1607126591945 Info message"

int x = 20;
echo::info("X is", x);
// -> print "[I] 1607126591947 X is: 20"

echo::warn(F("Warn message"));
// -> print "[W] 1607126594871 Warn message"

echo::error("Error message");
// -> print "[E] 1607126597380 Error message"

echo::verbose(F("Verbose message"), F("Extend info messages"));
// -> print "[V] 1607126599928 Verbose message: extend info messages"

The 4 methods accept 1 or 2 parameters. When using Arduino, the parameters are sent to the Serial.print() and Serial.println() methods, using a C++ template. Mbed Os implementation is pending.

The message shows the type of log ([I]), a timestamp in seconds the texts, which in case of being 2 parameters will be separated with a colon (:).

Info

The Debugging section explains how to configure the serial output to see echo messages.

Warning

Whenever you want to print text strings (char arrays) you can use Arduino's F() macro to avoid RAM consumption.

Core/Device

It is in charge of storing the name and id of the device. These are two important pieces of information to make the connection to the remote server or to identify the device in a BLE connection.

The device name and ID are also used in the provisioning process to register the devices in the cloud. Both values can be set manually from conf-user.h

#define DEVICE_NAME "TEL_0102"  // device name, for humans
#define DEVICE_ID ""            // device id, for machines

The device ID can be left blank ("" ) if a communication modem such as ESP32(WiFI) or SIM868(GPRS) is used, Rhomb.IoT will read the MAC or IMEI addresses and use them as identifiers.

It is displayed at the beginning of the output debug, after a restart:

------------------------------------
RHOMB.IOT - The Modular IoT Firmware
       version 0.1.0

[...]
[I] 0 SET new device ID: 4245060915  <--- (extracted from ESP32 MAC Address)

To change the values at execution time use this methods:

// Only accept charr array
// Both methods return false if the string is not valid: empty or too long.
device::setName("TRK005");
device::setId("2182471");

// Both methos return false if name or id are empty
device::hasName();
device::hasId();

Core/Errors

Display errors generated at runtime.

Core/FreeRam

Core/Global

Contain a global buffer as char array with a size fixed in conf-user.h with the macro BUFFER_SIZE.

strcpy(global::buffer, "Put data in the global buffer");
global::clearBuffer();

You can use this store as a temp buffer to save anything, but caution, this is a global bar, after set a value for the buffer use it fast and don't call other methods than can overwrite the value.

Core/Names

Contains all the macro definitions to identify all the modules. It is an important file when you are configuring the conf-user.h, many configuration values require definitions from names.h you may need to take a look at this when configuring your device.

Core/opmode

Operational modes control the flow of the application. Each opmode performs some tasks through a callback defined in the opmode.h file

  • OPMODE_BOOT: opmode.h::boot() | Configured by default as the first mode after reset. It is in charge of initializing all the modules and set the normal opmode.
  • OPMODE_NORMAL: opmode.h::normal() | The boot opmode will change to normal. All work is done in this mode. Sensor data is read, messages are created and transmitted.
  • OPMODE_LOW: opmode.h::low() | It performs the same functions as the normal opmode but at longer intervals and by activating the sleep mode whenever possible. Some modules may be ordered to stop working when this mode is activated.
  • OPMODE_SLEEP: opmode.h::sleep() | The microcontroller goes into sleep mode and stops working. This is usually reached via the BATT module, when a low battery charge is reported. You can also activate this mode manually when you want to save battery power, for example during the night.
  • OPMODE_FATAL_ERROR: opmode.h::fatal() | An error prevents rhomb.IoT from working. Visual alarms such as LED flashes or LCD messages are activated. This can be reached when a slave module is wrongly placed or a configuration parameter is not correct.

Core/Prototypes

Core/Puf

Puf is the library in charge of managing the system's events, using an event-oriented programming model such as Publisher/Subscriber. You can find more details in the section Event Driven With Puf

You can also download the library as an independent project at Github

Core/Sync

It contains the Waterfall and Each modules used to execute function sets (tasks) in an orderly manner. The code is fine (documented) and you can find more information and examples in the rhio-devkit and rhio-sync repositories.

The opmode.h file uses sync::waterfall() to initialize all Rhomb.IoT modules.

The gps-l86.h file uses sync::each() to make selective calls to the functions that return GPS data.

Core/Tempo

Controls the internal clock to return a time stamp in seconds.

By default it counts the seconds that have passed since the last reset, but some communication modules have used NTP services to synchronize the clock for and display the seconds from 1-1-1970.

Tempo updates its internal clock using the TimeISR module, which takes care of updating the seconds using an ISR function adapted to each microcontroller.

// Call to millis() on Arduino or Time on Mbed OS
unsigned long mcuTime();

// return the current timestamp in seconds
unsigned long get();

// Set a new timestamp
uint8_t set(unsigned long timestamp);

// add seconds (useful to add time offsets after sleep)
uint8_t add(unsigned long seconds);

Los relojes Tick1 y Tick2 se controlan a trav├ęs de Tempo.

Core/Utils

Comments