9
9
*/
10
10
11
11
#include " flxLoRaWANDigi.h"
12
+ #include < Flux/flxCoreEvent.h>
12
13
#include < Flux/flxNetwork.h>
13
14
#include < Flux/flxSerial.h>
14
15
#include < Flux/flxSettings.h>
20
21
#define kXBeeLRSerial Serial1
21
22
#define kXBeeLRBaud 9600
22
23
23
- // Our Development App EUI
24
- #define kDevelopmentAppEUI " 37D56A3F6CDCF0A5"
25
-
26
24
// Define a connection iteration value - exceed this, skip the connection
27
25
28
26
#define kMaxConnectionTries 3
@@ -130,12 +128,59 @@ void flxLoRaWANDigi::set_isEnabled(bool bEnabled)
130
128
disconnect ();
131
129
}
132
130
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
+ }
133
142
// ----------------------------------------------------------------
134
143
bool flxLoRaWANDigi::get_isEnabled (void )
135
144
{
136
145
return _isEnabled;
137
146
}
138
147
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
+
139
184
// ----------------------------------------------------------------
140
185
// Config the settings on the module. These settings are persistent, so only need to set once.
141
186
@@ -151,25 +196,33 @@ bool flxLoRaWANDigi::configureModule(void)
151
196
if (appEUI ().size () > 0 )
152
197
{
153
198
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 ." ));
155
202
}
156
203
flxLog_N_ (F (" ." ));
157
204
158
205
// App Key
159
206
if (appKey ().size () > 0 )
160
207
{
161
- flxLog_I (F (" Setting App Key: %s " ), appKey (). c_str ( ));
208
+ flxLog_N_ (F (" . setting App Key .. " ));
162
209
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 ." ));
164
213
}
165
214
166
215
flxLog_N_ (F (" ." ));
167
216
168
217
// Network Key
169
218
if (networkKey ().size () > 0 )
170
219
{
220
+ flxLog_N_ (F (" . setting Network Key .." ));
171
221
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
+ ;
173
226
}
174
227
flxLog_N_ (F (" ." ));
175
228
@@ -377,12 +430,6 @@ bool flxLoRaWANDigi::initialize(void)
377
430
// Our process messages job
378
431
_processJob.setup (" LoRaWAN Process" , kProcessMessagesTime , this , &flxLoRaWANDigi::processMessagesCB);
379
432
380
- #if defined(FLX_SPARKFUN_LORAWAN_APP_EUI)
381
- appEUI = FLX_SPARKFUN_LORAWAN_APP_EUI;
382
- #else
383
- appEUI = kDevelopmentAppEUI ;
384
- #endif
385
-
386
433
// Do we connect now?
387
434
388
435
// is it desired to delay the startup/connect call?
0 commit comments