Skip to Content

The Industrial Shields LoRa library: installation and functions

The Industrial Shields LoRa library

The Arduino and ESP32 PLCs with LoRa use the same API, based on the RadioHead library. That keeps the code compatible between modules, not only across Industrial Shields LoRa PLCs but with any RadioHead-compatible module. Arduino-based LoRa PLCs incorporate the RFM95 module and ESP32-based PLCs the RN2483. They are very different in how they talk to the CPU, but the libraries developed by Industrial Shields make managing them simple.

Message format

Every message of a RadioHead module has this structure:

NameSizeFunction
txHeaderTo1 byteAddress of the destination node. Use 0xFF for broadcast.
txHeaderFrom1 byteAddress of the sender node.
txHeaderId1 byteID from the header.
txHeaderFlags1 byteFlags from the header.
MessageMax 251 bytesThe message itself.

The LoRa.recv() function checks that the message is correct and parses it. This lets several nodes share the same channel while only the addressed node processes each packet. Note that, by default, the address in the header is not authentication: do not use it as a security mechanism, and do not send sensitive data in clear text.

Main functions

begin()

Initialises the module with its default configuration. Returns true if successful, false otherwise.

LoRa.begin();

available()

Checks whether the reception buffer has an unread message. Call recv() afterwards to read it. Returns true if a message is available.

LoRa.available();

send()

Sends len bytes starting from the array message. Returns true if the message was sent.

LoRa.send(message, len);

recv()

Reads a message from the reception buffer. Call it after LoRa.available() returns true, so you know there is a message pending. The message is stored in the buf array and len is updated with the length of the message read. Returns true if successful.

LoRa.recv(buf, len);

Radio configuration

The RN2483 module can be configured after LoRa.begin() with these functions. The RFM95 library also provides them, but the default parameters differ; see the documentation of the RadioHead library. All of them return true if successful. Every node of a link must use the same frequency, spreading factor, bandwidth, coding rate and sync word.

setFrequency() takes the frequency in hertz, as a whole number: 868 MHz is 868000000, not 868 or 868.0.

FunctionValuesDefaultExample
setFrequency()433050000 to 434790000 Hz, or 863000000 to 870000000 Hz868000000 HzLoRa.setFrequency(864050000);
setSpreadingFactor()7 to 1212LoRa.setSpreadingFactor(7);
setTxPower()-3 to 1513LoRa.setTxPower(2);
setSignalBandwidth()125, 250 or 500 kHz125LoRa.setSignalBandwidth(250);
setCodingRate4()5, 6, 7, 8 or 95LoRa.setCodingRate4(8);
setPreambleLength()0 to 655350LoRa.setPreambleLength(100);
setSyncWord()0x00 to 0xFF0x12LoRa.setSyncWord(0x10);

Choose the frequency and transmit power that your local regulation allows. Discover the LoRa PLCs at www.industrialshields.com.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.