ricaun / LoRaNow

LoRaNow Library is a simple LoRa Node <> Gateway communication protocol.
http://loranow.com/
MIT License
63 stars 21 forks source link

Possibility to set the TxPower #15

Open TRudolphi opened 3 years ago

TRudolphi commented 3 years ago

I wanted to have the possibility to set the TxPower of my sensors so nearby nodes can be set to a lower power to save the batteries. I changed in my local copy of LoRaNow the following to add this (the sf was already in the lib, but I set it in the text for orientation):

LoRaNow.h:

define LORANOW_DEFAULT_SF 7

#define LORANOW_DEFAULT_POWER 10

class LoRaNowClass : public Stream { private: uint8_t sf = LORANOW_DEFAULT_SF; uint8_t txpower = LORANOW_DEFAULT_POWER;

void setSpreadingFactor(int _sf); void setTxPower(uint8_t _power );

LoRaNow.cpp: void LoRaNowClass::setSpreadingFactor(int _sf) { sf = _sf; }

void LoRaNowClass::setTxPower(uint8_t _power ) { txpower = _power; }

void LoRaNowClass::txMode() { LORANOW_DEBUG_PRINT(millis());LORANOW_DEBUG_PRINTLN("[ln] txMode"); LoRa.idle(); LoRa.setFrequency(frequency); LoRa.setSpreadingFactor(sf); LoRa.setTxPower(txpower);

== Maybe this addition is also handy for other users.