-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommands.h
785 lines (751 loc) · 18.6 KB
/
Commands.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
#include <stdio.h>
#include <string.h>
void i2cScan(char*);
void displayTime();
void sendLux();
void sendBME680(bool);
void sendBME280(bool);
void sendPA();
void sendHTU21D();
void sendTH();
void sendLPP(char*);
void sendMsg(char*);
void sendPing(char*);
float calcAlt(float);
void handleHelp(char *);
void whoami(char *);
void handleP2P(char *);
void handleFreq(char *);
void handleBW(char *);
void handleSF(char *);
void handleCR(char *);
void handleTX(char *);
void handleLux(char *);
void handleTH(char *);
void handlePA(char *);
void handleBME(char *);
void handleALT(char *);
void handleMSL(char *);
void handleRTC(char *);
void handleAutoPing(char *);
void handleAES(char *);
void handleOCP(char *);
void handlePongBack(char *);
void handleSerial1(char *);
void handleSendMsg(char *);
void handleOLED(char *);
void sleepCPU(char*);
void sleepAll(char*);
void sleepLoRa(char*);
void handleDelay(char*);
void decodeLPP(char *, uint8_t);
bool needAES = false, needJSON = false, pongBack = false, autoPing = true;
uint32_t apPeriod = 30000, lastPing;
char pwd[32];
uint8_t OCP_value = 0x38;
int cmdCount = 0;
struct myCommand {
void (*ptr)(char *); // Function pointer
char name[12];
char help[48];
};
myCommand cmds[] = {
{handleHelp, "help", "Shows this help."},
{i2cScan, "i2c", "Scans the I2C bus."},
#ifdef __RAKBLE_H__
{whoami, "whoami", "Gets the BLE broadcast name."},
#endif
{sendPing, "ping", "Sends a ping."},
{handleP2P, "p2p", "Shows the P2P settings."},
{handleFreq, "fq", "Gets/sets the working frequency."},
{handleBW, "bw", "Gets/sets the working bandwidth."},
{handleSF, "sf", "Gets/sets the working spreading factor."},
{handleCR, "cr", "Gets/sets the working coding rate."},
{handleTX, "tx", "Gets/sets the working TX power."},
{handleLux, "lux", "Gets the ambient light."},
{handleTH, "th", "Gets the temperature and humidity."},
{handlePA, "pa", "Gets the atmospheric pressure."},
{handleBME, "bme", "Gets data (T/H/Pa) from a BME680."},
{handleALT, "alt", "Computes altitude."},
{handleMSL, "msl", "Gets/sets the MSL pressure."},
{sendLPP, "lpp", "Sends a Cayenne packet."},
{handleRTC, "rtc", "Gets/sets datetime."},
{handleAES, "aes", "AES-related commands."},
{handleOCP, "ocp", "Gets/sets OCP value."},
{handleAutoPing, "ap", "autoping 0/x seconds."},
{handlePongBack, "pb", "Gets/sets pong back."},
{handleSerial1, "s1", "Enables/disables Serial1."},
{handleSendMsg, "send", "Sends a custom P2P packet."},
{handleOLED, "oled", "Gets/sets OLED on/off status."},
{sleepCPU, "cpu", "sleep/cpu"},
{sleepAll, "all", "sleep/all"},
{sleepLoRa, "lora", "sleep/lora"},
{handleDelay, "sDelay", "Sets the sleep time."},
{handleHelp, "help", "Shows this help."},
};
void sleepAll(char *param) {
Serial.printf("Sleep/all for %d secs\n", (sleepDelay / 1000));
api.system.sleep.all(sleepDelay);
Serial.println("back");
// api.system.reboot();
}
void sleepLoRa(char *param) {
Serial.printf("Sleep/lora for %d secs\n", (sleepDelay / 1000));
api.system.sleep.lora(sleepDelay);
Serial.println("back");
// api.system.reboot();
}
void sleepCPU(char *param) {
Serial.printf("Sleep/cpu for %d secs\n", (sleepDelay / 1000));
api.system.sleep.cpu(sleepDelay);
Serial.println("back");
// api.system.reboot();
}
void handleDelay(char*param) {
int value;
int i = sscanf(param, "/%*s %d", &value);
if (i == -1) {
// no parameters
Serial.printf("Current delay: %d s\n", (sleepDelay / 1e3));
return;
} else {
// sf xxxx set SF
if (value < 1 || value > 30) {
Serial.printf("Invalid value: %d\n", value);
return;
}
sleepDelay = value * 1000;
}
}
void handleOLED(char *param) {
if (hasOLED) {
uint8_t i = sscanf(param, "/oled off");
if (i > -1) {
switchOLED(false);
return;
}
i = sscanf(param, "/oled on");
if (i > -1) {
switchOLED(true);
oledLastOn = millis();
return;
}
uint8_t value;
i = sscanf(param, "/oled %d", &value);
if (i > -1) {
if (i == 0) switchOLED(false);
else if (i == 0) {
switchOLED(true);
oledLastOn = millis();
}
return;
}
sprintf(msg, "OLED: %s\n", oledON ? "on" : "off");
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
}
}
void handleSendMsg(char *param) {
memset(msg, 0, 128);
uint8_t i = sscanf(param, "/send %s", msg);
if (i > -1) {
sendMsg(msg);
} else {
Serial.println("No OLED...");
}
}
void handleOCP(char *param) {
uint16_t value;
int i = sscanf(param, "/ocp %d", &value);
if (i == 1) {
// 60 to 140
if (value < 60) value = 60;
else if (value > 140) value = 140;
value *= 10;
OCP_value = value / 25;
// SX126xWriteRegister(0x08e7, OCP_value);
sprintf(msg, "OCP = 0x%2x [%d]", OCP_value, (value / 10));
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
} else {
sprintf(msg, "OCP = 0x%2x [%d]", OCP_value, (OCP_value * 2.5));
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
}
}
void handlePongBack(char *param) {
uint8_t value;
int i = sscanf(param, "/pb %d", &value);
if (i == 1) {
// 0 or 1..n OFF or ON
sprintf(msg, "pb %s [%d]", (value == 0) ? "off" : "on", value);
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
pongBack = (value > 0);
} else {
sprintf(msg, "pong %s", pongBack ? "on" : "off");
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
}
}
void handleSerial1(char *param) {
uint8_t value;
int i = sscanf(param, "/s1 %d", &value);
if (i == 1) {
// 0 or 1..n OFF or ON
sprintf(msg, "s1 %s [%d]", (value == 0) ? "off" : "on", value);
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
needSerial1 = (value > 0);
if (needSerial1) Serial1.begin(115200, RAK_CUSTOM_MODE);
else Serial1.end();
} else {
sprintf(msg, "Serial1 %s", needSerial1 ? "on" : "off");
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
}
}
void handleAutoPing(char *param) {
uint8_t value;
uint8_t i = sscanf(param, "/ap %d", &value);
if (i == 1) {
// 0 OFF or xx ON
sprintf(msg, "ap %s [%d]", (value == 0) ? "off" : "on", value);
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
autoPing = (value > 0);
apPeriod = 1000 * value;
lastPing = millis();
} else {
i = sscanf(param, "/ap off");
if (i > -1) {
sprintf(msg, "Set ap off");
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
autoPing = false;
return;
}
sprintf(msg, "ap %s [%d]", autoPing ? "on" : "off", (apPeriod / 1000));
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
}
}
void handleAES(char *param) {
int i = sscanf(param, "/aes off");
if (i == 0) {
// OFF
sprintf(msg, "aes OFF");
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
needAES = false;
return;
}
i = sscanf(param, "/aes %s", msg);
if (i > -1) {
// ON with pwd
i = strlen(msg);
if (i != 16) {
// AES128 pwd len = 16 bytes
// Later we will accept hex string 010203 etc of 32 bytes
sprintf(msg, "wrong aes pwd length!");
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
needAES = false;
return;
}
memcpy(pwd, msg, 16);
sprintf(msg, "aes ON!");
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
needAES = true;
return;
}
}
void handleHelp(char *param) {
Serial.printf("Available commands: %d\n", cmdCount);
for (int i = 0; i < cmdCount; i++) {
sprintf(msg, " . /%s: %s", cmds[i].name, cmds[i].help);
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
}
}
#ifdef __RAKBLE_H__
void whoami(char* param) {
sprintf(msg, "Broadcast name: %s", api.ble.settings.broadcastName.get());
Serial.println(msg);
sendToBle(api.ble.settings.broadcastName.get());
if (hasOLED) {
displayScroll("Broadcast name:");
displayScroll( api.ble.settings.broadcastName.get());
}
return;
}
#endif
void handleP2P(char *param) {
float f0 = myFreq / 1e6, f1 = api.lorawan.pfreq.get() / 1e6;
// check stored value vs real value
sprintf(msg, "P2P frequency: %.3f/%.3f MHz\n", f0, f1);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "Fq: %.3f MHz\n", f1);
displayScroll(msg);
}
sprintf(msg, "P2P SF: %d\n", sf);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
displayScroll(msg);
}
sprintf(msg, "P2P bandwidth: %d KHz\n", bw);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "BW: %d KHz", bw);
displayScroll(msg);
}
sprintf(msg, "P2P C/R: 4/%d\n", (cr + 5));
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
displayScroll(msg);
}
sprintf(msg, "P2P TX power: %d\n", txPower);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "TX power: %d", txPower);
displayScroll(msg);
}
}
void handleFreq(char *param) {
float value;
int i = sscanf(param, "/fq %f", &value);
if (i == -1) {
// no parameters
sprintf(msg, "P2P frequency: %.3f MHz\n", (myFreq / 1e6));
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "Fq: %.3f MHz\n", (myFreq / 1e6));
displayScroll(msg);
}
return;
} else {
// fq xxx.xxx set frequency
value = atof(param + 4);
// for some reason sscanf returns 0.000 as value...
if (value < 150.0 || value > 960.0) {
// sx1262 freq range 150MHz to 960MHz
// Your chip might not support all...
sprintf(msg, "Invalid frequency value: %.3f\n", value);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
return;
}
myFreq = value * 1e6;
api.lorawan.precv(0);
// turn off reception
sprintf(msg, "Set P2P frequency to %3.3f: %s MHz\n", (myFreq / 1e6), api.lorawan.pfreq.set(myFreq) ? "Success" : "Fail");
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
api.lorawan.precv(65533);
if (hasOLED) {
sprintf(msg, "New freq: %.3f", myFreq);
displayScroll(msg);
}
return;
}
}
void handleBW(char*param) {
int value;
int i = sscanf(param, "/%*s %d", &value);
if (i == -1) {
// no parameters
sprintf(msg, "P2P bandwidth: %d KHz\n", bw);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "BW: %d KHz", bw);
displayScroll(msg);
}
return;
} else {
// bw xxxx set BW
if (value > 9) {
sprintf(msg, "Invalid BW value: %d\n", value);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
return;
}
bw = myBWs[value];
api.lorawan.precv(0);
// turn off reception
sprintf(msg, "Set P2P bandwidth to %d/%d: %s\n", value, bw, api.lorawan.pbw.set(bw) ? "Success" : "Fail");
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
api.lorawan.precv(65533);
if (hasOLED) {
sprintf(msg, "New BW: %d", bw);
displayScroll(msg);
}
return;
}
}
void handleSF(char*param) {
int value;
int i = sscanf(param, "/%*s %d", &value);
if (i == -1) {
// no parameters
sprintf(msg, "P2P SF: %d\n", sf);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "SF: %d", sf);
displayScroll(msg);
}
return;
} else {
// sf xxxx set SF
if (value < 5 || value > 12) {
sprintf(msg, "Invalid SF value: %d\n", value);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
return;
}
sf = value;
api.lorawan.precv(0);
// turn off reception
sprintf(msg, "Set P2P spreading factor to %d: %s\n", sf, api.lorawan.psf.set(sf) ? "Success" : "Fail");
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
api.lorawan.precv(65533);
if (hasOLED) {
sprintf(msg, "SF set to %d", sf);
displayScroll(msg);
}
return;
}
}
void handleCR(char*param) {
int value;
int i = sscanf(param, "/%*s %d", &value);
if (i == -1) {
// no parameters
sprintf(msg, "P2P CR: 4/%d\n", (cr + 5));
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "CR: 4/%d", (cr + 5));
displayScroll(msg);
}
return;
} else {
// sf xxxx set SF
if (value < 5 || value > 8) {
sprintf(msg, "Invalid CR value: %d\n", value);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
return;
}
cr = value - 5;
api.lorawan.precv(0);
// turn off reception
sprintf(msg, "Set P2P coding rate to %d: %s\n", cr, api.lorawan.pcr.set(cr) ? "Success" : "Fail");
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
api.lorawan.precv(65533);
if (hasOLED) {
sprintf(msg, "CR set to 4/%d", (cr + 5));
displayScroll(msg);
}
return;
}
}
void handleTX(char*param) {
int value;
int i = sscanf(param, "/%*s %d", &value);
if (i == -1) {
// no parameters
sprintf(msg, "P2P TX power: %d\n", txPower);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "Tx pwr: %d", txPower);
displayScroll(msg);
}
return;
} else {
// sf xxxx set SF
if (value < 5 || value > 22) {
sprintf(msg, "Invalid TX power value: %d\n", value);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
return;
}
txPower = value;
api.lorawan.precv(0);
// turn off reception
sprintf(msg, "Set P2P Tx power to %d: %s\n", cr, api.lorawan.ptp.set(txPower) ? "Success" : "Fail");
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
api.lorawan.precv(65533);
if (hasOLED) {
sprintf(msg, "Tx pwr set to %d", txPower);
displayScroll(msg);
}
return;
}
}
void handleTH(char *param) {
bool hasSomething = false;
if (hasTH) {
sendTH();
hasSomething = true;
}
if (hasHTU21D) {
sendHTU21D();
hasSomething = true;
}
if (hasBME680) {
sendBME680(false);
hasSomething = true;
} else if (hasBME280) {
sendBME280(false);
hasSomething = true;
}
if (!hasSomething) {
sprintf(msg, "No Temp/Humidity module installed!");
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
}
}
void handlePA(char *param) {
if (hasPA) sendPA();
else Serial.println("No RAK1902 module installed!");
}
void handleBME(char *param) {
if (hasBME680) sendBME680(true);
else if (hasBME280) sendBME280(true);
else Serial.println("No BMEx80 module installed!");
}
void handleALT(char *param) {
float pressure = 0.0;
if (hasPA) {
float alt = calcAlt(HPa);
sprintf(msg, "1902: %.2f m", alt);
Serial.println(msg);
if (hasOLED) displayScroll(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
}
if (hasBME680) {
ClosedCube_BME680_Status status = bme680.readStatus();
float alt = calcAlt(bme680.readPressure());
sprintf(msg, "bme: %.2f m", alt);
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
} else if (hasBME280) {
float alt = calcAlt(bme280.getPressure() / 100.0);
sprintf(msg, "bme: %.2f m", alt);
Serial.println(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) displayScroll(msg);
}
}
void handleMSL(char *param) {
float value;
int i = sscanf(param, "/msl %f", &value);
if (i == -1) {
// no parameters
sprintf(msg, "Current MSL: %.3f HPa\n", MSL);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "MSL: %.3f HPa\n", MSL);
displayScroll(msg);
}
return;
} else {
// msl xxx.xxx set MSL
value = atof(param + 5);
// for some reason sscanf returns 0.000 as value...
if (value > 900.0 && value < 1100.0) {
MSL = value;
sprintf(msg, "MSL set to: %.2f HPa\n", MSL);
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
if (hasOLED) {
sprintf(msg, "New MSL: %.2f HPa", MSL);
displayScroll(msg);
}
} else {
Serial.printf("Incorrect MSL: %.2f", value);
}
return;
}
}
void handleLux(char *param) {
if (has1903 || hasBH1750) sendLux();
else Serial.println("No light sensor installed!");
}
void handleRTC(char* param) {
if (!hasDS3231M && !hasRAK12002) {
sprintf(msg, "No RTC module installed!");
Serial.print(msg);
#ifdef __RAKBLE_H__
sendToBle(msg);
#endif
return;
}
// Variables to hold parsed date/time
// Use sscanf() to parse the date/time into component variables
if (hasDS3231M) {
unsigned int tokens, year, month, day, hour, minute, second;
tokens = sscanf(param, "%*s %u-%u-%u %u:%u:%u;", &year, &month, &day, &hour, &minute, &second);
if (tokens != 6) {
displayTime();
return;
}
DS3231M.adjust(DateTime(year, month, day, hour, minute, second));
// Adjust the RTC date/time
#ifdef __RAKBLE_H__
sendToBle("Date / Time set.");
#endif
displayTime();
return;
} else {
// hasRAK12002
unsigned int tokens, year, month, dayOfWeek, day, hour, minute, second;
tokens = sscanf(param, "%*s %u/%u/%u %u %u:%u:%u;", &year, &month, &day, &dayOfWeek, &hour, &minute, &second);
//Serial.printf("tokens: %d\n", tokens);
if (tokens != 7) {
// Check to see if it was parsed correctly
displayTime();
return;
} else {
rak12002.setTime(year, month, dayOfWeek, day, hour, minute, second);
// Adjust the RTC date/time
#ifdef __RAKBLE_H__
sendToBle("Date / Time set.");
#endif
Serial.println(F("Date / Time set to:"));
displayTime();
}
}
}
/*
if (cmd[1] == '>' && cmd[2] == ' ') {
sendMsg(cmd + 3);
return;
}
*/
void evalCmd(char *str, char *fullString) {
char strq[12];
for (int i = 0; i < cmdCount; i++) {
sprintf(strq, "%s?", cmds[i].name);
if (strcmp(str, cmds[i].name) == 0 || strcmp(strq, str) == 0) {
cmds[i].ptr(fullString);
return;
}
}
}
void handleCommands(char *str1) {
char kwd[32];
int i = sscanf(str1, "/%s", kwd);
if (i > 0) evalCmd(kwd, str1);
else handleHelp("");
oledLastOn = millis();
}