2
2
// https://github.com/gonzalocasas/arduino-uno-dragino-lorawan/blob/master/LICENSE
3
3
// Based on examples from https://github.com/matthijskooijman/arduino-lmic
4
4
// Copyright (c) 2015 Thomas Telkamp and Matthijs Kooijman
5
+ // Modified by github FGCDAM user https://github.com/fcgdam
5
6
6
7
#include < Arduino.h>
7
8
#include " lmic.h"
@@ -92,6 +93,7 @@ void onEvent (ev_t ev) {
92
93
display.drawString (0 , 20 , " Received DATA." );
93
94
for ( i = 0 ; i < LMIC.dataLen ; i++ )
94
95
TTN_response[i] = LMIC.frame [LMIC.dataBeg +i];
96
+
95
97
TTN_response[i] = 0 ;
96
98
display.drawString (0 , 32 , String (TTN_response));
97
99
}
@@ -140,26 +142,58 @@ void setup() {
140
142
pinMode (LEDPIN,OUTPUT);
141
143
142
144
// reset the OLED
143
- pinMode (OLED_RESET,OUTPUT);
144
- digitalWrite (OLED_RESET, LOW);
145
- delay (50 );
146
- digitalWrite (OLED_RESET, HIGH);
147
-
148
- display.init ();
149
- display.flipScreenVertically ();
150
- display.setFont (ArialMT_Plain_10);
151
-
152
- display.setTextAlignment (TEXT_ALIGN_LEFT);
145
+ pinMode (OLED_RESET,OUTPUT);
146
+ digitalWrite (OLED_RESET, LOW);
147
+ delay (50 );
148
+ digitalWrite (OLED_RESET, HIGH);
149
+
150
+ display.init ();
151
+ display.flipScreenVertically ();
152
+ display.setFont (ArialMT_Plain_10);
153
+
154
+ display.setTextAlignment (TEXT_ALIGN_LEFT);
155
+
156
+ display.drawString (0 , 0 , " Init!" );
157
+ display.display ();
158
+
159
+ if ( DEVADDR == 0x00 ) { // Device is misconfigured with an invalid or not defined device id.
160
+ int i = 0 ;
161
+
162
+ while ( true ) {
163
+ display.clear ();
164
+ display.drawString (0 , 0 , " INIT FAILED! " );
165
+ display.drawString (0 , 9 , " Device ID is not SET!" );
166
+
167
+ display.drawString (0 , 18 , " Invalid TTN settings!" );
168
+ display.drawString (0 , 27 , " Set NWSKEY and APPSKEY!" );
169
+
170
+ display.drawString ( 0 , 36 , " Correct and reset." );
171
+
172
+ display.drawString ( 0 , 45 , " Waiting for user action..." );
173
+ if ( i == 0 )
174
+ display.drawString ( 0 , 54 , " ." );
175
+ else
176
+ display.drawString ( 0 , 54 , " *" );
177
+ i++;
178
+ i = i % 2 ;
179
+ display.display ();
180
+ delay ( 1000 );
181
+ }
153
182
154
- display.drawString (0 , 0 , " Init!" );
155
- display.display ();
183
+ }
156
184
157
185
// LMIC init
158
186
os_init ();
159
187
188
+ display.drawString (0 , 8 , " LMIC was initiated!" );
189
+ display.display ();
190
+
160
191
// Reset the MAC state. Session and pending data transfers will be discarded.
161
192
LMIC_reset ();
162
193
194
+ display.drawString (0 , 16 , " LMIC reset -> OK!" );
195
+ display.display ();
196
+
163
197
// Set up the channels used by the Things Network, which corresponds
164
198
// to the defaults of most gateways. Without this, only three base
165
199
// channels from the LoRaWAN specification are used, which certainly
@@ -181,6 +215,9 @@ void setup() {
181
215
// devices' ping slots. LMIC does not have an easy way to define set this
182
216
// frequency and support for class B is spotty and untested, so this
183
217
// frequency is not configured here.
218
+ display.drawString (0 , 24 , " LMIC setChannels -> OK!" );
219
+ display.display ();
220
+
184
221
185
222
// Set static session parameters.
186
223
LMIC_setSession (0x1 , DEVADDR, NWKSKEY, APPSKEY);
@@ -195,6 +232,19 @@ void setup() {
195
232
// LMIC_setDrTxpow(DR_SF11,14);
196
233
LMIC_setDrTxpow (DR_SF9,14 );
197
234
235
+ display.drawString (0 , 32 , " LMIC setup -> OK!" );
236
+ display.display ();
237
+
238
+ for ( int i = 0 ; i < 5 ; i++ ) {
239
+ delay ( 1000 );
240
+
241
+ display.drawString (0 +i*8 , 50 , " ." );
242
+ display.display ();
243
+ }
244
+
245
+ Serial.println (" LMIC setup done." );
246
+ Serial.println (" Starting transmit job." );
247
+
198
248
// Start job
199
249
do_send (&sendjob);
200
250
}
0 commit comments