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:
| Name | Size | Function |
|---|---|---|
| txHeaderTo | 1 byte | Address of the destination node. Use 0xFF for broadcast. |
| txHeaderFrom | 1 byte | Address of the sender node. |
| txHeaderId | 1 byte | ID from the header. |
| txHeaderFlags | 1 byte | Flags from the header. |
| Message | Max 251 bytes | The 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.
| Function | Values | Default | Example |
|---|---|---|---|
setFrequency() | 433050000 to 434790000 Hz, or 863000000 to 870000000 Hz | 868000000 Hz | LoRa.setFrequency(864050000); |
setSpreadingFactor() | 7 to 12 | 12 | LoRa.setSpreadingFactor(7); |
setTxPower() | -3 to 15 | 13 | LoRa.setTxPower(2); |
setSignalBandwidth() | 125, 250 or 500 kHz | 125 | LoRa.setSignalBandwidth(250); |
setCodingRate4() | 5, 6, 7, 8 or 9 | 5 | LoRa.setCodingRate4(8); |
setPreambleLength() | 0 to 65535 | 0 | LoRa.setPreambleLength(100); |
setSyncWord() | 0x00 to 0xFF | 0x12 | LoRa.setSyncWord(0x10); |
Choose the frequency and transmit power that your local regulation allows. Discover the LoRa PLCs at www.industrialshields.com.
There are no comments for now.