Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to receive LoRa packets with SF 12 #10

Closed
IoTThinks opened this issue Jan 22, 2024 · 9 comments
Closed

Failed to receive LoRa packets with SF 12 #10

IoTThinks opened this issue Jan 22, 2024 · 9 comments
Labels
bug Something isn't working

Comments

@IoTThinks
Copy link
Contributor

Hi all,
I have tested to send packet from Sandeep's Arduino LoRa (ESP32) to SMotlag's LoRa (STM32).
When SF = 7, STM32 can receive packets from ESP32.
However, when SF=12, then STM32 does not receive packets from ESP32.

Compare the set Spreading Factor function, I guess this library misses the part to set LDO (Low data optimization).
This library
https://github.com/SMotlaq/LoRa/blob/master/LoRa/LoRa.c#L184

Sandeep's library
https://github.com/sandeepmistry/arduino-LoRa/blob/master/src/LoRa.cpp#L573

RadioLib's library
https://github.com/jgromes/RadioLib/blob/master/src/modules/SX127x/SX1278.cpp#L188

Have you tested the receiving with SF12?
Thanks a lot.

@SMotlaq
Copy link
Owner

SMotlaq commented Jan 22, 2024

Thanks for bringing this issue to my attention. I apologize for the confusion caused by the missing Low Data Optimization (LDO) setting in my LoRa library. I understand that this feature is important for reliable data transmission when using a Spreading Factor (SF) of 12.

I've now added the necessary code to set the LDO in the LoRa library. You can find the updated code in the following commit:

0bf5cb7

The changes include the addition of two new functions: LoRa_setLowDaraRateOptimization and LoRa_setAutoLDO. These functions allow you to enable/disable LDO and set the LDO flag for your specific use case.

Unfortunately I couldn't test the updated library with SF12. Please check these new functions and tell me the result.

Thanks again for bringing this to my attention, and I apologize for any inconvenience caused. If you have any further questions or concerns, please don't hesitate to reach out 🌹

@SMotlaq SMotlaq added the bug Something isn't working label Jan 22, 2024
@IoTThinks
Copy link
Contributor Author

I have attempted to creat a fix. But not successful yet.

Let me test your patch tomorrow morning.

@IoTThinks
Copy link
Contributor Author

I tested just now.
The fix works for SF7-10 and SF12.
SF11 seems not working yet. Still show wrong data for SF11.

image

@SMotlaq
Copy link
Owner

SMotlaq commented Jan 23, 2024

Thanks. Would you mind sending your code please?

@IoTThinks
Copy link
Contributor Author

IoTThinks commented Jan 24, 2024

My code is not working yet.

Let me debug and try to fix for sf11 based on your fix yesterday.

Hope to complete by this Friday.

Will update you and creat pull request if success.

@IoTThinks
Copy link
Contributor Author

IoTThinks commented Jan 25, 2024

I think there is still missing code here and there comparing to RadioLib and ArduinoLoRa.
However, this is a dirty trick.
SF7-11 should not have LDO on. SF12 should have LDO on.
((1 << _LoRa->spredingFactor) / ((double)BW[_LoRa->bandWidth] will return 16.3... so it will larger than 16.

So Arduino-LoRa uses "long" so after debugging, I guess it would trim down to 16.
image

So my suggested fix is to change this line

LoRa_setLowDaraRateOptimization(_LoRa, ((1 << _LoRa->spredingFactor) / ((double)BW[_LoRa->bandWidth])) >= 16.0);

To the below.
Note the (long) and =

LoRa_setLowDaraRateOptimization(_LoRa, (long)((1 << _LoRa->spredingFactor) / ((double)BW[_LoRa->bandWidth])) > 16.0);

My STM32L0 with this fix is able to receive SF7-12 packets from Arduino-LoRa now.
image

@SMotlaq
Copy link
Owner

SMotlaq commented Jan 27, 2024

Hi again,

Thanks for your suggestion to fix the issue. I agree that changing the line to use long and > operator would fix the issue.

Would you be willing to make this change in your forked repository and send a pull request? This way, we can keep the changes in your repository and I can merge them into the main repository.

If you're not comfortable making the changes yourself, I can certainly do it myself. However, I'd like to give you the opportunity to make the changes and get credit for your contribution.

Let me know either way, and we can move forward with the fix.

Thanks again!

@IoTThinks
Copy link
Contributor Author

IoTThinks commented Jan 27, 2024

Ok, let me create a pull request tomorrow.

@IoTThinks
Copy link
Contributor Author

I created a Pull Request.
To close this issue.
Thanks a lot for your effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants