Skip to content

Commit d52554d

Browse files
committed
added the ability to set the lorawan *class* for the module
1 parent 5986a79 commit d52554d

File tree

3 files changed

+52
-4
lines changed

3 files changed

+52
-4
lines changed

sfeIoTNodeLoRaWAN/flxLoRaWANDigi.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,10 @@ void flxLoRaWANDigi::set_isEnabled(bool bEnabled)
130130

131131
void flxLoRaWANDigi::update_system_config(void)
132132
{
133+
// have we setup the system yet -- if not, skip this
134+
if (_pXBeeLR == nullptr)
135+
return;
136+
133137
// Mark this module as not configured. This will force a reconfiguration at boot.
134138
_moduleConfigured = false;
135139

@@ -181,6 +185,36 @@ std::string flxLoRaWANDigi::get_network_key(void)
181185
return _network_key;
182186
}
183187

188+
void flxLoRaWANDigi::set_lora_class(uint8_t loraClass)
189+
{
190+
if (_lora_class == loraClass)
191+
return;
192+
193+
_lora_class = loraClass;
194+
195+
// push the update to the module
196+
(void)setupLoRaWANClass();
197+
}
198+
199+
uint8_t flxLoRaWANDigi::get_lora_class(void)
200+
{
201+
return _lora_class;
202+
}
203+
//----------------------------------------------------------------
204+
// method to capture setting the module class
205+
bool flxLoRaWANDigi::setupLoRaWANClass(void)
206+
{
207+
if (!_isEnabled || _pXBeeLR == nullptr)
208+
return false;
209+
210+
bool status = _pXBeeLR->setLoRaWANClass(kLoRaWANClasses[_lora_class][0]);
211+
if (!status)
212+
flxLog_W(F("%s: Error setting the LoRaWAN Class to `%s`"), name(), kLoRaWANClasses[_lora_class]);
213+
else
214+
flxLog_D(F("%s: Set the LoRaWAN Class to `%s`"), name(), kLoRaWANClasses[_lora_class]);
215+
216+
return status;
217+
}
184218
//----------------------------------------------------------------
185219
// Config the settings on the module. These settings are persistent, so only need to set once.
186220

@@ -374,8 +408,7 @@ bool flxLoRaWANDigi::connect(void)
374408
return false;
375409
}
376410
// We are connected -- make sure the class is set.
377-
if (!_pXBeeLR->setLoRaWANClass('C'))
378-
flxLog_D(F("%s: Failed to set the LoRaWAN Class"), name());
411+
(void)setupLoRaWANClass();
379412

380413
flxSerial.textToGreen();
381414
flxLog_N(F("Connected!"));
@@ -436,6 +469,8 @@ bool flxLoRaWANDigi::initialize(void)
436469
flxRegister(appKey, "Application Key", "The LoRaWAN Application Key");
437470
flxRegister(networkKey, "Network Key", "The LoRaWAN Network Key");
438471

472+
flxRegister(loraWANClass, "LoRaWAN Class", "The LoRaWAN operating class");
473+
439474
// our hidden module initialized property
440475
flxRegister(_moduleConfigured, "mod-config");
441476

sfeIoTNodeLoRaWAN/flxLoRaWANDigi.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,15 @@ class flxLoRaWANDigi : public flxActionType<flxLoRaWANDigi>
4848

4949
void update_system_config(void);
5050

51+
void set_lora_class(uint8_t);
52+
uint8_t get_lora_class(void);
53+
uint8_t _lora_class;
54+
5155
public:
5256
// ctor
5357
flxLoRaWANDigi()
54-
: _app_key{""}, _network_key{""}, _wasConnected{false}, _isEnabled{true}, _delayedStartup{false},
55-
_moduleInitialized{false}, _pXBeeLR{nullptr}, _devEUI{'\0'}, _currentOffset{0}
58+
: _app_key{""}, _network_key{""}, _lora_class{2}, _wasConnected{false}, _isEnabled{true},
59+
_delayedStartup{false}, _moduleInitialized{false}, _pXBeeLR{nullptr}, _devEUI{'\0'}, _currentOffset{0}
5660
{
5761
setName("LoRaWAN Network", "Digi LoRaWAN connection for the system");
5862
flux_add(this);
@@ -83,6 +87,9 @@ class flxLoRaWANDigi : public flxActionType<flxLoRaWANDigi>
8387
networkKey;
8488

8589
flxPropertyRWBool<flxLoRaWANDigi, &flxLoRaWANDigi::get_isEnabled, &flxLoRaWANDigi::set_isEnabled> enabled;
90+
91+
flxPropertyRWUInt8<flxLoRaWANDigi, &flxLoRaWANDigi::get_lora_class, &flxLoRaWANDigi::set_lora_class> loraWANClass =
92+
{2, {{kLoRaWANClasses[0], 0}, {kLoRaWANClasses[1], 1}, {kLoRaWANClasses[2], 2}}};
8693
flxPropertyHiddenBool<flxLoRaWANDigi> _moduleConfigured = {false};
8794

8895
// input params/functions
@@ -121,12 +128,15 @@ class flxLoRaWANDigi : public flxActionType<flxLoRaWANDigi>
121128
bool sendData(uint8_t tag, const uint8_t *data, size_t len);
122129
bool flushBuffer(void);
123130

131+
static constexpr const char *kLoRaWANClasses[3] = {"A", "B", "C"};
132+
124133
private:
125134
void connectionStatusCB(void);
126135
bool setupModule(void);
127136
bool configureModule(void);
128137
void reconnectJobCB(void);
129138
void processMessagesCB(void);
139+
bool setupLoRaWANClass(void);
130140

131141
// send our payload buffer
132142
bool sendPayload(const uint8_t *payload, size_t len);

sfeIoTNodeLoRaWAN/sfeIoTNodeLoRaWANAbout.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ void sfeIoTNodeLoRaWAN::displayAppStatus(bool useInfo)
8484
if (_loraWANConnection.isConnected())
8585
{
8686
flxLog__(logLevel, "%cDevice EUI: %s", pre_ch, _loraWANConnection.deviceEUI());
87+
flxLog__(logLevel, "%cOperating Class: '%s'", pre_ch,
88+
_loraWANConnection.kLoRaWANClasses[_loraWANConnection.loraWANClass()]);
8789
}
8890
flxLog_N("");
8991
if (!useInfo)
@@ -167,6 +169,7 @@ void sfeIoTNodeLoRaWAN::displayAppStatus(bool useInfo)
167169
else
168170
flxLog_N("%.2f (ms)", _logger.getLogRate());
169171

172+
flxLog_N("");
170173
flxLog__(logLevel, "%cJSON Buffer - Size: %dB Max Used: %dB", pre_ch, jsonBufferSize(), _fmtJSON.getMaxSizeUsed());
171174
flxLog__(logLevel, "%cSerial Output: %s", pre_ch, kLogFormatNames[serialLogType()]);
172175
flxLog_N("%c Baud Rate: %d", pre_ch, serialBaudRate());

0 commit comments

Comments
 (0)