Hi
I use LoRa in my system, I like to have a control ala wifi in my void loop():
if (WiFi.status() != WL_CONNECTED)
I use this library from Stuart Robinson, SX12XX-LoRa-master
I was thinking to do a if control:
if (LoRa.begin(NSS, NRESET, DIO0, LORA_DEVICE))
but this way the LoRa start each time the void loop runs, seems not to be a "smart" idea.
ChatGPT suggest to send a dummy package but that seems also to be a not so "smart" idea.
Is there a lora.status avaialble?
M
srnet
July 7, 2024, 8:11am
2
Completly unclear what you mean, more detail required.
If the LoRa device initialises, then its there to be used, you tell it what to do.
LoRa has no concept of being 'connected', it just sends and receives packets.
@srnet
Thanks for answer, to clarify
If lora module after started in setup() in a OK status, but after 6 months (or 1 h) stops working I wold like to restart it, from void loop().
For WiFI this can be done with
if (WiFi.status() != WL_CONNECTED)
so I was hoping there was a similar option like this
if (LoRa.status() != LoRa_CONNECTED)
srnet
July 7, 2024, 9:12am
4
Cant say I recall a LoRa device ever having stopped working, in the context of another LoRa.begin() being needed to make it work again.
If you follow the LoRa.begin() code in the library you will see it calls checkDevice() which does a test write and read of one of the LoRa device registers to see if its responding over the SPI bus.
So if you called LoRa.checkDevice() it will return true if the LoRa device is reponding and false if its not.
Thanks!
Do I then understand that library handles this automatically, and restart LoRa if FALSE?
I found in library:
bool checkDevice();
I tried this, as expected no success
if (!checkDevice() {
Serial.println("Starts LoRa ");
LoRa.begin(NSS, NRESET, DIO0, LORA_DEVICE)
}
'checkDevice' was not declared in this scope
So my question (same) is if is possible to get a reading in void loop() from LoRa that it is OK?
M
checkDevice is part of the class and hence you access it through the LoRa object that you did create. So it would be something like LoRa.checkDevice().
srnet
July 7, 2024, 9:45am
7
Try;
!LoRa.checkDevice()
And if you run LoRa.begin() you will need to run LoRa.setupLoRa() again too.
Depends what you mean by OK of course.
Thanks again, solution @srnet @sterretje
This is my library class
SX127XLT LoRa; // create a library class instance called LoRa
this works:
if (!LoRa.checkDevice()) {
Serial.println("Start LoRa againt");
LoRa.begin(NSS, NRESET, DIO0, LORA_DEVICE);
}
srnet
July 7, 2024, 11:35am
9
Modesty:
this works:
if (!LoRa.checkDevice()) {
Serial.println("Start LoRa againt");
LoRa.begin(NSS, NRESET, DIO0, LORA_DEVICE);
}
On its own it wont, LoRa.begin() resets the LoRa device so all the modem setups and calibration that are part of LoRa.setupLoRa() are lost.
Aha, yes, I must resatart all LoRa, ala this:
if (!LoRa.checkDevice()) {
Serial.println("Start LoRa againt");
restartLoRa(); // function
}