Requirements and setup
Before we try anything with the module, we must make sure that the PLC fulfills certain requirements.
First of all, install Industrial Shield's librpiplc library following the instructions from the repository. When cloning the repository, you have to replace <tagname> with the desired librpiplc verion. For this blog, we installed v3.0.0.
Next, we must make sure that the config.txt file is set up correctly. To do this, first open /boot/config.txt with your preferred text editor, in this case we use nano:
Use your arrow keys to reach the bottom of the file, and make sure you have these lines set up like this:
You can now close the text editor. If you opened the file using nano, you can close it by pressing Ctrl+X. If nano asks you for confirmation before closing, type Y to confirm and then press Enter to keep the same filename.
Testing
With everything configured correctly, we can begin testing the module to ensure that everything is working correctly.
Depending on where the module was installed, the commands to use will be a bit different. The module can either be in slot 1 or slot 2, with slot 1 being just besides the ethernet port. Follow the testing instructions according to where the module is installed:
Testing the LoRa module
Enable the LoRa module by setting the reset pin to high. You'll also need the model and version of your RPIPLC to replace [RPIPLC_Version] and [RPIPLC_Model].
With the reset pin set to high, we can now test the LoRa module itself. We will need two terminals for this, one to send data to the module and another one to recieve its response.
In the first terminal, open the port with a baudrate of 57600, which is the default baudrate of the module. In case of any errors, you can try to use a different baudrate.
(it's important to incluede raw -echo, or you could encounter issues)
Now, leave the port listening with cat:
Go to the second terminal. We will ask the module for its version to confirm that we can communicate with it:
If everything went well, you should see something like "RN2483 1.0.5 Oct 31 2018 15:06:52" in the first terminal, which should still be listening for any incoming data. To stop it from listening, you can press Ctrl+C.
Test communication between two LoRa modules
Now you can set up a second RPIPLC with the LoRa module and try to communicate with it. On the second RPIPLC you'll have to repeat the same setup steps we did on the first RPIPLC, and also enable the reset pin and open the port at the same baudrate.
After that, you have to set the frequency that the modules will use to send and recieve messages. If you have the RN2483A LoRa module, you can either use European (868MHz) or Asian (433MHz) frequencies. If instead you have the RN2903 LoRa module, you have to set the frequency to the American one (915MHz). In this case we ue the European one:
We prepare one of the RPIPLCs to recieve messages:
And then send the message from the other RPIPLC with:
Upon succesful communication, you should see something like
'radio_rx 0ABC' in the recieving RPIPLC's terminal.
Useful commands and further documentation
You can send LoRa commands by following this structure:
Where [COMMAND] will be the actual LoRa command itself. Here are some useful examples you can use:
- mac pause: Pause the LoRaWAN stack functionality and allow transceiver
- radio rx 0: Listen for data.
- radio tx ABC: Send a message (ABC).
- radio set freq [FREQUENCY]: Set the frequency of the radio transceiver.
You can also find further documentation on LoRa here:
Testing the LoRa module
Enable the LoRa module by setting the reset pin to high. You'll also need the model and version of your RPIPLC to replace [RPIPLC_Version] and [RPIPLC_Model]. If you are using a librpiplc version older than v3.0.0, EXP2_RST will instead be named EXP1_RST_2.
With the reset pin set to high, we can now test the LoRa module itself. We will need two terminals for this, one to send data to the module and another one to recieve its response.
In the first terminal, open the port with a baudrate of 57600, which is the default baudrate of the module. In case of any errors, you can try to use a different baudrate.
(it's important to incluede raw -echo, or you could encounter issues)
Now, leave the port listening with cat:
Go to the second terminal. We will ask the module for its version to confirm that we can communicate with it:
If everything went well, you should see something like "RN2483 1.0.5 Oct 31 2018 15:06:52" in the first terminal, which should still be listening for any incoming data. To stop it from listening, you can press Ctrl+C.
Test communication between two LoRa modules
Now you can set up a second RPIPLC with the LoRa module and try to communicate with it. On the second RPIPLC you'll have to repeat the same setup steps we did on the first RPIPLC, and also enable the reset pin and open the port at the same baudrate.
After
that, you have to set the frequency that the modules will use to send
and recieve messages. If you have the RN2483A LoRa module, you can
either use European (868MHz) or Asian (433MHz) frequencies. If instead
you have the RN2903 LoRa module, you have to set the frequency to the
American one (915MHz). In this case we ue the European one:
We prepare one of the RPIPLCs to recieve messages:
And then send the message from the other RPIPLC with:
Upon succesful communication, you should see something like
'radio_rx 0ABC' in the recieving RPIPLC's terminal.
Useful commands and further documentation
You can send LoRa commands by following this structure:
Where [COMMAND] will be the actual LoRa command itself. Here are some useful examples you can use:
- mac pause: Pause the LoRaWAN stack functionality and allow transceiver
- radio rx 0: Listen for data.
- radio tx ABC: Send a message (ABC).
- radio set freq [FREQUENCY]: Set the frequency of the radio transceiver.
You can also find further documentation on LoRa here:
LoRa module on Raspberry PI