Hi, I am only asking this question to help me understand my sketch (my lora is working great).
The code:
while (!LoRa.begin(866E6)) {
Serial.println(“.”);
delay(500); }
Says “If the lora module does not send a response on frequency 866 then print “.” and then wait half a second and try again”
But how is the lora module initialized (turned on) in the first place ?
Hi David.
When it checks if LoRa is initialized, it is initializing the LoRa module at the same time. It needs to run the LoRa.begin(866) command first to check if its state is true or false.
You see this approach often to initialize sensors.
What you need to understand is that if you have the LoRa.begin() method, even if it has a ! or an if statement before it, it is already running the command.
So, here’s what it does:
- runs LoRa.begin(866E6);
- negation of the result of the previous command !LoRa.begin(866E6) –> if it initializes successfully returns true—with the negation becomes false; if it doesn’t initialize properly returns false—with the negation becomes true;
- checks the state of !LoRa.begin(866E6). If it is true (it means it didn’t initialize properly), it will print the dots. If it is false (it means it initialized properly), it won’t run the if statement.
I hope this is clear.
Regards,
Sara