Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f8f02cb

Browse files
committedDec 17, 2024·
added logic to trigger reboot and reconfigure for module if key/id changes; add more error/info messages on key/id setting
1 parent f6aee3f commit f8f02cb

File tree

2 files changed

+91
-18
lines changed

2 files changed

+91
-18
lines changed
 

‎sfeIoTNodeLoRaWAN/flxLoRaWANDigi.cpp

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010

1111
#include "flxLoRaWANDigi.h"
12+
#include <Flux/flxCoreEvent.h>
1213
#include <Flux/flxNetwork.h>
1314
#include <Flux/flxSerial.h>
1415
#include <Flux/flxSettings.h>
@@ -20,9 +21,6 @@
2021
#define kXBeeLRSerial Serial1
2122
#define kXBeeLRBaud 9600
2223

23-
// Our Development App EUI
24-
#define kDevelopmentAppEUI "37D56A3F6CDCF0A5"
25-
2624
// Define a connection iteration value - exceed this, skip the connection
2725

2826
#define kMaxConnectionTries 3
@@ -130,12 +128,59 @@ void flxLoRaWANDigi::set_isEnabled(bool bEnabled)
130128
disconnect();
131129
}
132130

131+
void flxLoRaWANDigi::update_system_config(void)
132+
{
133+
// Mark this module as not configured. This will force a reconfiguration at boot.
134+
_moduleConfigured = false;
135+
136+
// Save our settings
137+
flxSettings.save(this, true);
138+
139+
// Indicate that the system needs restart
140+
flxSendEvent(flxEvent::kSystemNeedsRestart);
141+
}
133142
//----------------------------------------------------------------
134143
bool flxLoRaWANDigi::get_isEnabled(void)
135144
{
136145
return _isEnabled;
137146
}
138147

148+
void flxLoRaWANDigi::set_app_eui(std::string appEUI)
149+
{
150+
_app_eui = appEUI;
151+
152+
// Indicate that the system needs restart
153+
update_system_config();
154+
}
155+
std::string flxLoRaWANDigi::get_app_eui(void)
156+
{
157+
return _app_eui;
158+
}
159+
160+
void flxLoRaWANDigi::set_app_key(std::string appKey)
161+
{
162+
_app_key = appKey;
163+
164+
// Indicate that the system needs restart
165+
update_system_config();
166+
}
167+
std::string flxLoRaWANDigi::get_app_key(void)
168+
{
169+
return _app_key;
170+
}
171+
172+
void flxLoRaWANDigi::set_network_key(std::string networkKey)
173+
{
174+
_network_key = networkKey;
175+
176+
// Indicate that the system needs restart
177+
update_system_config();
178+
}
179+
std::string flxLoRaWANDigi::get_network_key(void)
180+
{
181+
return _network_key;
182+
}
183+
139184
//----------------------------------------------------------------
140185
// Config the settings on the module. These settings are persistent, so only need to set once.
141186

@@ -151,25 +196,33 @@ bool flxLoRaWANDigi::configureModule(void)
151196
if (appEUI().size() > 0)
152197
{
153198
if (!_pXBeeLR->setLoRaWANAppEUI(appEUI().c_str()))
154-
flxLog_D(F("%s: Failed to set the App EUI"), name());
199+
flxLog_N_(F(". failed ."));
200+
else
201+
flxLog_N_(F(". success ."));
155202
}
156203
flxLog_N_(F("."));
157204

158205
// App Key
159206
if (appKey().size() > 0)
160207
{
161-
flxLog_I(F("Setting App Key: %s"), appKey().c_str());
208+
flxLog_N_(F(". setting App Key .."));
162209
if (!_pXBeeLR->setLoRaWANAppKey(appKey().c_str()))
163-
flxLog_D(F("%s: Failed to set the App Key"), name());
210+
flxLog_N_(F(". failed ."));
211+
else
212+
flxLog_N_(F(". success ."));
164213
}
165214

166215
flxLog_N_(F("."));
167216

168217
// Network Key
169218
if (networkKey().size() > 0)
170219
{
220+
flxLog_N_(F(". setting Network Key .."));
171221
if (!_pXBeeLR->setLoRaWANNwkKey(networkKey().c_str()))
172-
flxLog_W(F("%s: Failed to set the Network Key"), name());
222+
flxLog_N_(F(". failed ."));
223+
else
224+
flxLog_N_(F(". success ."));
225+
;
173226
}
174227
flxLog_N_(F("."));
175228

@@ -377,12 +430,6 @@ bool flxLoRaWANDigi::initialize(void)
377430
// Our process messages job
378431
_processJob.setup("LoRaWAN Process", kProcessMessagesTime, this, &flxLoRaWANDigi::processMessagesCB);
379432

380-
#if defined(FLX_SPARKFUN_LORAWAN_APP_EUI)
381-
appEUI = FLX_SPARKFUN_LORAWAN_APP_EUI;
382-
#else
383-
appEUI = kDevelopmentAppEUI;
384-
#endif
385-
386433
// Do we connect now?
387434

388435
// is it desired to delay the startup/connect call?

‎sfeIoTNodeLoRaWAN/flxLoRaWANDigi.h

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ flxDefineEventID(kLoRaWANSendStatus);
2222
// Event for received messages
2323
flxDefineEventID(kLoRaWANReceivedMessage);
2424

25+
// Our Development App EUI
26+
#define kDevelopmentAppEUI "37D56A3F6CDCF0A5"
27+
2528
class flxLoRaWANDigi : public flxActionType<flxLoRaWANDigi>
2629
{
2730
private:
@@ -30,14 +33,36 @@ class flxLoRaWANDigi : public flxActionType<flxLoRaWANDigi>
3033

3134
void reset_module(void);
3235

36+
void set_app_eui(std::string appEUI);
37+
std::string get_app_eui(void);
38+
std::string _app_eui;
39+
40+
void set_app_key(std::string appKey);
41+
std::string get_app_key(void);
42+
43+
std::string _app_key;
44+
45+
void set_network_key(std::string networkKey);
46+
std::string get_network_key(void);
47+
std::string _network_key;
48+
49+
void update_system_config(void);
50+
3351
public:
3452
// ctor
3553
flxLoRaWANDigi()
36-
: _wasConnected{false}, _isEnabled{true}, _delayedStartup{false}, _moduleInitialized{false}, _pXBeeLR{nullptr},
37-
_devEUI{'\0'}, _currentOffset{0}
54+
: _app_key{""}, _network_key{""}, _wasConnected{false}, _isEnabled{true}, _delayedStartup{false},
55+
_moduleInitialized{false}, _pXBeeLR{nullptr}, _devEUI{'\0'}, _currentOffset{0}
3856
{
3957
setName("LoRaWAN Network", "Digi LoRaWAN connection for the system");
4058
flux_add(this);
59+
60+
// default app EUI
61+
#if defined(FLX_SPARKFUN_LORAWAN_APP_EUI)
62+
_app_eui = FLX_SPARKFUN_LORAWAN_APP_EUI;
63+
#else
64+
_app_eui = kDevelopmentAppEUI;
65+
#endif
4166
}
4267

4368
// dtor
@@ -52,9 +77,10 @@ class flxLoRaWANDigi : public flxActionType<flxLoRaWANDigi>
5277
}
5378

5479
// Properties
55-
flxPropertyString<flxLoRaWANDigi> appEUI;
56-
flxPropertySecureString<flxLoRaWANDigi> appKey;
57-
flxPropertySecureString<flxLoRaWANDigi> networkKey;
80+
flxPropertyRWString<flxLoRaWANDigi, &flxLoRaWANDigi::get_app_eui, &flxLoRaWANDigi::set_app_eui> appEUI;
81+
flxPropertyRWSecureString<flxLoRaWANDigi, &flxLoRaWANDigi::get_app_key, &flxLoRaWANDigi::set_app_key> appKey;
82+
flxPropertyRWSecureString<flxLoRaWANDigi, &flxLoRaWANDigi::get_network_key, &flxLoRaWANDigi::set_network_key>
83+
networkKey;
5884

5985
flxPropertyRWBool<flxLoRaWANDigi, &flxLoRaWANDigi::get_isEnabled, &flxLoRaWANDigi::set_isEnabled> enabled;
6086
flxPropertyHiddenBool<flxLoRaWANDigi> _moduleConfigured = {false};

0 commit comments

Comments
 (0)
Please sign in to comment.