novag / SlimLoRa

WIP, does NOT work yet. See https://github.com/novag/LoRa-ATtiny-Node for a working version made for the ATtiny85.
GNU Lesser General Public License v3.0
12 stars 1 forks source link

setPower function #1

Open clavisound opened 3 years ago

clavisound commented 3 years ago

First: thank you about your offer to write this library.

I think the LoRaWAN specs also need to control the power of the device.

I don't know if I will have the time, but I will try to port the function to your work, unless you are faster / have more time than me.

This is the PR for TinyLoRa. Also interesting the opition to setRegion during runtime. Adafruit too lazy to write an example and me, still testing with TTN V3. https://github.com/adafruit/TinyLoRa/pull/30

Happy coding.

novag commented 3 years ago

Hi clavisound,

thanks! Currently SlimLoRa defaults to 16 dBm and dynamically adjusts the output power when ADR is enabled.

If I am right in the EU in the 868 MHz band (which is the only band supported currently) a device is limited to 14dBm. So you have to make sure that your RF path has enough loss or your antenna is bad enough to run this legally. I should probably lower the default to 14 dBm in the future. Other than that I don't see where the LoRaWAN spec requires setting the tx power manually.

But a setPower function would be useful if you disable ADR or if you want to implement your own data rate and tx power adjustment functionality. If we implement a setPower function we should definitely enforce the legal limits of the different regions.

clavisound commented 3 years ago

dynamically adjusts the output power when ADR is enabled.

Didn’t noticed! I will re-read the code.

Currently I am testing my node with -80dbm. The node is next to antenna so it’s behaviour is ideal for testing.

Also didn’t noticed that supports only EU868.

I have mobile devices and I want to disable ADR (as LoRaWAN states) to send with lower power and SF when close to a GW. I call this “white zone”. Not implemented yet :-) Semtech calls it “blind adr”.

Take care.

clavisound commented 3 years ago

I examined your code about TxPower and I am confused because we use different calculation.

We both set the 4 MSB bytes for the PA_CONFIG register to 1 11110000 aka: 0xF0

TinyLoRa DataPower = (PaBoost << 7) + (MaxPower << 4) + OutputPower; (PaBoost = 1, MaxPower = 7 and shifted aka: 0xF0 https://github.com/adafruit/TinyLoRa/blob/dafdf918c9faaa69091365efdd4781a7e12ade76/TinyLoRa.cpp#L467

SlimLora https://github.com/novag/SlimLoRa/blob/6087542ee280df8e80fd51cf20219a48d67493b6/SlimLoRa.cpp#L812

But the calculation for the register is different as you can see. I use OutputPower = Tx_Power - 2 you use: 14 - tx_power * 2

So we have different values:

for power in `seq 2 15`; do echo -n "$power - Tiny: "; echo -n $(expr $power - 2); echo -n " Slim: "; echo $(expr 14 - $power \* 2); done
2 - Tiny: 0 Slim: 10
3 - Tiny: 1 Slim: 8
4 - Tiny: 2 Slim: 6
5 - Tiny: 3 Slim: 4
6 - Tiny: 4 Slim: 2
7 - Tiny: 5 Slim: 0
8 - Tiny: 6 Slim: -2
9 - Tiny: 7 Slim: -4
10 - Tiny: 8 Slim: -6
11 - Tiny: 9 Slim: -8
12 - Tiny: 10 Slim: -10
13 - Tiny: 11 Slim: -12
14 - Tiny: 12 Slim: -14
15 - Tiny: 13 Slim: -16

I think the right formula for slimLoRa is RfmWrite(RFM_REG_PA_CONFIG, 0xF0 | (tx_power - 2)); This is valid only for values >=2 and <=17dBm.

TinyLoRa setPower function, also support +20dBm and -80dBm (useful only if the node is next to the GW). https://github.com/adafruit/TinyLoRa/blob/dafdf918c9faaa69091365efdd4781a7e12ade76/TinyLoRa.cpp#L446

Have you verified that your power settings are fine?

If you can make the library ready to use with arduino I will test both formulas, although mine is tested.

novag commented 3 years ago

At least for the EU868 regional parameters it's the same.

The EU868 regional parameters encode the tx power according to the following table: 0 = Max EIRP 1 = Max EIRP - 2dB 2 = Max EIRP - 4dB 3 = Max EIRP - 6dB 4 = Max EIRP - 8dB 5 = Max EIRP - 10dB 6 = Max EIRP - 12dB 7 = Max EIRP - 14dB

with Max EIRP being +16dBm by default.

clavisound commented 3 years ago

Oh, I get it now. Sorry. You have right. I have to study the LoRaWAN protocol more.

for power in `seq 0 7`; do echo -n "ADR Req $power "; echo -n " Slim: "; echo -n $(expr 14 - $power \* 2); echo "dBm"; done
ADR Req 0  Slim: 14dBm
ADR Req 1  Slim: 12dBm
ADR Req 2  Slim: 10dBm
ADR Req 3  Slim: 8dBm
ADR Req 4  Slim: 6dBm
ADR Req 5  Slim: 4dBm
ADR Req 6  Slim: 2dBm
ADR Req 7  Slim: 0dBm

But in the case of +16 (0dB antenna) we want (16 - tx_power * 2) vs (14 - tx_power * 2). Right?

You prefer the setPower function like this mode (without +20dB and without -80dBm) or like TinyLoRa?