Closed savnik closed 6 years ago
A solution to this could be:
// "emulate" break condition
Serial1.flush();
Serial1.begin(300);
Serial1.write((uint8_t)0x00);
Serial1.flush();
delay(50);
// set baudrate
Serial1.begin(57600);
Serial1.write((uint8_t)0x55);
Serial1.flush();
That works for me with a hardware serial.
In the class, we don't use serial but Stream&
. This is so allow for interfacing that doesn't directly rely on a serial, let alone a serial implementation: Serial(N), SerialUSB, HardwareSerial, SoftwareSerial, AltSoftSerial, etc. So begin()
is not available.
Also, TheThingsNetwork
class does not declare and begin the serial at all, that's up to the caller. It would be weird to add it to a wake()
function I think.
BTW, are you using baudrate 300 intentionally?
Could be sufficient to make "void autoBaud();" a public function and call this function from code to wake up from sleep the module.
@savnik @alexbn71 please advise/test keeping in mind that TheThingsNetwork
library cannot call begin()
as it works with the abstract Stream
I know @johanstokking , in fact the function autoBaud() already defined in the library uses Stream object.
I've tested this change and it works... I moved autoBaud() into public functions section then used a call ttn.autoBaud(); to wake up the module before the expiry of the sleep time.
OK, can you file a PR? Maybe it's nice to still have a method wake()
that only calls autoBaud()
to keep the interface clean and to reserve ourselves the freedom to do other magic stuff in there
I perfectly agree with you, I do it...
Closed by #225
it's possible to call begin
casting the object as HardwareSerial
It's now done in PR #231
HardwareSerial *pLora = (HardwareSerial*) modemStream;
// Send a 0 at lower speed to be sure always received
// as a character a 57600 baud rate
pLora->flush();
pLora->begin(2400);
pLora->write((uint8_t) 0x00);
pLora->flush();
This should be done in the sketch, we can't put this in the library as we can't assert modemStream
is a HardwareSerial
A wake function to wake the device from sleep. From the data sheet this function is described as: