sandeepmistry / arduino-LoRa

An Arduino library for sending and receiving data using LoRa radios.
MIT License
1.61k stars 621 forks source link

Freeze on beginPacket() call #577

Open Haismd03 opened 2 years ago

Haismd03 commented 2 years ago

Hello everyone I found an issue using this library. When you try to call LoRaClass::beginPacket() in your code and your LoRa device is disconnected, it freezes your device. When i call LoRaClass::begin(), it obviously report an error, but my program still continue.

I looked into library and (by my amateur eye) found, that in LoRaClass::begin() there is an read statement that terminates the method, if data cannot be read. I suppose that LoRaClass::beginPacket() freezes, because it tries to write registers without making sure that the device is there. And it's probably waiting for response that just cannost come.

I quick modified the method: int LoRaClass::beginPacket(int implicitHeader) and added uint8_t version = readRegister(REG_VERSION); if (version != 0x12) { return 0; } at the beginning and it seems like it solved the problem.

(working on RPI pico, using earlephilhower core, programming on Arduino IDE 1.8.19)

EDIT: It solves problem, when LoRa is completely gone, but program still gets stuck if SPI remain connected, but VCC is disconnected.

Help would be appreciated