Closed Terrence77 closed 8 months ago
Couple of points:
RADIOLIB_VERBOSE
, you need to have RADIOLIB_DEBUG
enabled as well.startTransmit
only starts the transmission. Once the transmittedFlag
flag is set, the transmission has finished. But you are not waiting for that, you got to sleep immediately after startTransmit
finishes. I suggest you take a better look at the examples, and the documentation.I also noted that I have to manually set transmittedFlag back to true for it to fall into if statement.
Not if you were using it correctly. I would suggest to start with unmodified example(s). Once you have that working, you can try to add sleep.
Thank you for those suggestions.
At your advice, I started over on the original example code and adding sleep work as it should.
I have some work to do on my wrapper class to get it working, but I have the underlying code that works.
Thank you for the great RadioLib.
For any interested here is the working code.
#include <RadioLib.h>
SX1262 radio = new Module(RADIOLIB_BUILTIN_MODULE);
int transmissionState = RADIOLIB_ERR_NONE;
volatile bool transmittedFlag = false;
void setFlag(void) {
transmittedFlag = true;
}
void setup() {
Serial.begin(9600);
Serial.print(F("[SX1262] Initializing ... "));
int state = radio.begin(908.0, 500.0, 10, 5, 0x12, 10, 8);
if (state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
Serial.println(state);
while (true);
}
radio.setPacketSentAction(setFlag);
Serial.print(F("[SX1262] Sending first packet ... "));
transmissionState = radio.startTransmit("Hello!");
}
int count = 0;
void loop() {
if(transmittedFlag) {
transmittedFlag = false;
if (transmissionState == RADIOLIB_ERR_NONE) {
Serial.println(F("transmission finished!"));
} else {
Serial.print(F("failed, code "));
Serial.println(transmissionState);
}
radio.finishTransmit();
radio.sleep();
delay(2500);
radio.standby();
Serial.print(F("Sending another packet ... "));
String str = "Hello! #" + String(count++);
Serial.println(str);
transmissionState = radio.startTransmit(str);
}
}
Glad you were able to resolve it!
When I put my radio to sleep and then wake it by using standby, it no longer sends a message, or I should say my receiver not longer receives the message.
platformio.ini file
BuildOptUser.h Set to verbose, but not much verbosity.
Output
Here is the code. I have tried all 3 stand by modes, but not luck I also noted that I have to manually set transmittedFlag back to true for it to fall into if statement.