Closed linuxtrainer closed 5 years ago
Interestingly the very first receive packet will be displayed as it should, but from all following packets only crap is shown.
Based on this it might be the same issue of the FIFO buffer position being incorrectly reset. I released version 0.6.0 last night that contains this fix. Give this a try before we dig into this issue. Reopen if the problem persists.
Hey @linuxtrainer and @morganrallen, I'm working on a very similar idea for disaster radio's LoRaLayer2 library.
I have a strong feeling that what @linuxtrainer is trying to do is not possible with the arduino-LoRa library as is.
The problem lies with the onReceive callback. Inside of the function that ultimately handles the receive callback, onDio0Rise
, there is a reference to the global LoRa
class in which LoRa.handleDio0Rise()
is called, see LoRa.cpp line 715.
This means that any call to onReceive will not care if you read from a locally created LoRa object (in this case LoRaIn
), it will always read from the register of the global LoRa
object, even if you never setPins
or begin
that object.
This explains why the second example only reads the first message, because the register of LoraIn
is never being cleared and reset, so the subsequent reads are just reading the garbage in the remainder of the register.
Currently, the only "right" way (that I can see) to use two LoRa modules in the same sketch is with @linuxtrainer first example. Using the global LoRa
object as your receiver and an additional LoRa object as your transmitter. Even if you create a local LoRa object for your receiver and it appears to work, you are only disguising the fact that you are actually using the global object.
@morganrallen does my theory sound right? I'm interested to setup proper bi-directional communication on multiple LoRa modules, but I'm almost sure it will require forking this repo. I can open a new issue for that, since it maybe outside the scope of the original issue.
Good catch @paidforby, yes please open a new issue as this needs to be addressed. I just tried a quick test by removing Lora.
from that function call but it complains about calls to member functions without object.... So yeah, start a new issue and will discuss getting this fixed.
Thanks Grant!
I startet a project with two Lora-Moduls on one Arduino Pro Mini. One of the sx1278-Module should work as receiver and the other one should be the transmitter. A picture of the breadboard with the two LoRa-AI-Thinker-Ra-02-Modules can be seen here: https://raphuscucullatus.blogspot.com/2019/07/2-mal-sx1278-und-1-mal-atmega328p.html
If I use the following code, everthing works fine:
t if I use a second instance of the LoraClass, in my example named LoraIn, crap is posted by the LoraIn.read()-function called in the callback-function:
with the last sketch using LoRaIn, this is what can be seen in the Arduino Serial Monitor:
Interestingly the very first receive packet will be displayed as it should, but from all following packets only crap is shown. I know that not every packet will be received, as there is perhaps an interference between transmitter and incoming data, what sometimes happens. This sort of data lose is not the problem at the moment. This projekt is for educational purpose only, and the aim is one transmitter and one receiver on one arduino pro mini.
I am only interested whats the problem with two LoRaClass-Instances. Perhaps someone can help me? Thanks for answer and best regards!
Leo