-
Notifications
You must be signed in to change notification settings - Fork 5
/
Sixfab_CellularIoT.h
673 lines (538 loc) · 14.2 KB
/
Sixfab_CellularIoT.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
/*
Sixfab_CellularIoT.h
-
Library for Sixfab Arduino CellularIoT Shield and
Sixfab Arduino CellularIoT Application Shield.
-
Created by Yasin Kaya (selengalp), july 13, 2018.
*/
#ifndef _SIXFAB_CELLULAR_H
#define _SIXFAB_CELLULAR_H
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#include "pins.h"
#endif
#include <stdio.h>
#include <string.h>
#include <Wire.h>
#include <SoftwareSerial.h>
#include <Sixfab_HDC1080.h>
#include <Sixfab_MMA8452Q.h>
// determine board type
// Arduino Geniuno / Uno or Mega
#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
#define GNSS Serial // 115200 baud rate
#define DEBUG Serial // 115200 baud rate
// Tinylab, Arduino Leonardo or Micro
#elif defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega16U4__)
#define GNSS Serial1 // 115200 baud rate
#define DEBUG Serial // 115200 baud rate
#endif
extern SoftwareSerial BG96_AT;
// enum for setMode function
enum {
AUTO_MODE = 0,
GSM_MODE,
CATM1_MODE,
CATNB1_MODE,
};
// Peripheral Pin Definations
#define USER_BUTTON 6
#define USER_LED 5
#define BG96_ENABLE 4
#define ALS_PT19_PIN A1
#define RELAY A0
#define BG96_POWERKEY A2
#define STATUS A3
#define AP_READY 7
#define RING_INDICATOR 8
// Constants
#define TIMEOUT 1000
#define IP_ADDRESS_LEN 30
#define DOMAIN_NAME_LEN 50
#define PORT_NUMBER_LEN 8
#define AT_COMM_LEN 100
#define AT_RESPONSE_LEN 100
#define DATA_COMPOSE_LEN 100
#define DATA_LEN_LEN 3
// LTE Bands
#define LTE_B1 "1"
#define LTE_B2 "2"
#define LTE_B3 "4"
#define LTE_B4 "8"
#define LTE_B5 "10"
#define LTE_B8 "80"
#define LTE_B12 "800"
#define LTE_B13 "1000"
#define LTE_B18 "20000"
#define LTE_B19 "40000"
#define LTE_B20 "80000"
#define LTE_B26 "2000000"
#define LTE_B28 "8000000"
#define LTE_B39 "4000000000" // catm1 only
#define LTE_CATM1_ANY "400A0E189F"
#define LTE_CATNB1_ANY "A0E189F"
#define LTE_NO_CHANGE "0"
// GSM Bands
#define GSM_NO_CHANGE "0"
#define GSM_900 "1"
#define GSM_1800 "2"
#define GSM_850 "4"
#define GSM_1900 "8"
#define GSM_ANY "f"
#define SCRAMBLE_ON "0"
#define SCRAMBLE_OFF "1"
class SixfabCellularIoT
{
public:
char compose[100];
char url[68];
char ip_address[IP_ADDRESS_LEN]; //ip address
char domain_name[DOMAIN_NAME_LEN]; // domain name
char port_number[PORT_NUMBER_LEN]; // port number
uint16_t timeout = TIMEOUT; // default timeout for function and methods on this library.
/*
Default constructer with no parameter
[no-return]
---
[no-param]
*/
SixfabCellularIoT();
/******************************************************************************************
*** Base Functions : Set or Clear Hardwares - Status Controls - Helper AT Functions *****
******************************************************************************************/
/*
Function for initializing module and peripherals
This function do things below:
* enables BG96 module
* sets pin directions
[no-return]
---
[no-param]
*/
void init(); // initialize
/*
Function for powering up BG96 module and all peripherals from voltage regulator
[no-return]
---
[no-param]
*/
void enable();
/*
Function for powering down BG96 module and all peripherals from voltage regulator
[no-return]
---
[no-param]
*/
void disable();
/*
Function for powering up or down BG96 module
[no-return]
---
[no-param]
*/
void powerUp();
/*
Function for getting modem status (is powered up?).
[return] : uint8_t modem status (0 : powered up) - (1: powered down)
---
[no-param]
*/
uint8_t getModemStatus();
/*
Function for sending AT [param #1] command to BG96.
[no-return]
---
[param #1] : const char* AT command word
*/
void sendATCommOnce(const char *);
/*
Function for sending AT [param #1] command to BG96. If the desired [param #2]
response isn't recevived, function resend the AT command wait a time as [timeout].
[return] : const char* response of AT command that received from bg96 modem
---
[param #1] : const char* AT command word
[param #2] : const char* AT desired_response word
[param #3] : const char* AT response word
*/
const char* sendATComm(const char *, const char *);
/*
Function for sending Data [param #1] to BG96. If the desired [param #2]
response isn't recevived, function resend the Data wait a time as [timeout].
[return] : const char* response of Data that received from bg96 modem
---
[param #1] : const char* Data word
[param #2] : const char* Data desired_response word
[param #3] : const char* Data response word
*/
const char* sendDataComm(const char *, const char *);
/*
Function for resetting bg96 module and all peripherals.
[no-return]
---
[no-param]
*/
void resetModule();
/*
Function to save configurations that be done in current session.
[no-return]
--
[no-param]
*/
void saveConfigurations();
/*
Function for getting IMEI number
[return] : const char* IMEI number
[no-param]
*/
const char* getIMEI();
/*
Function for getting firmware info
[return] : const char* firmware info
---
[no-param]
*/
const char* getFirmwareInfo();
/*
Function for getting hardware info
[return] : const char* hardware info
---
[no-param]
*/
const char* getHardwareInfo();
/*
Function for setting GSM Band
[no-return]
---
[param #1] : const char* GSM Band
*/
void setGSMBand(const char *);
/*
Function for setting Cat.M1 Band
[no-return]
---
[param #1] : const char * Cat.M1 LTE Band
*/
void setCATM1Band(const char *);
/*
Function for setting NB-IoT Band
[no-return]
---
[param #1] : const char * NB_IoT LTE Band
*/
void setNBIoTBand(const char *);
/*
Function for getting band configuration
[return] : const char* band configuration
---
[no-param]
*/
const char* getBandConfiguration();
/*
Function for setting scramble feature configuration
[no-return]
---
[param #1] : const char * Scramble on / off ( '0' is on, '1' is off)
*/
void setScrambleConf(const char *);
/*
Function for setting running mode.
[no-return]
---
[param #1] : mode selector
[MODE_AUTO] [0] --> Automatic *Priority Table (Cat.M1 -> Cat.NB1 -> GSM)
[MODE_GSM] [1] --> GSM
[MODE_CATM1] [2] --> Cat.M1
[MODE_CATNB1] [3] --> Cat.NB1 (NB-IoT)
*/
void setMode(uint8_t);
/*
Function for getting described ip address
[return] : const char* IP Address
---
[no-param]
*/
const char* getIPAddress();
/*
Function for setting desired ip address
[no-return]
---
[param #1] : char * desired ip address
*/
void setIPAddress(char *);
/*
Function for getting described domain name
[return] : const char* domain name
---
[no-param]
*/
const char* getDomainName();
/*
Function for setting desired domain name
[no-return]
---
[param #1] : char * desired domain name
*/
void setDomainName(char *);
/*
Function for getting described port number
[return] : const char* port number
---
[no-param]
*/
const char* getPort();
/*
Function for setting desired port number
[no-return]
---
[param #1] : char * desired port number
*/
void setPort(char *);
/*
Function for getting described timeout
[return] : uint16_t described timeout in ms
---
[no-param]
*/
uint16_t getTimeout();
/*
Function for setting desired timeot
[no-return]
---
[param #1] : uint16_t desired timeout in ms
*/
void setTimeout(uint16_t);
/******************************************************************************************
*** Network Service Functions ************************************************************
******************************************************************************************/
/*
Function for getting signal quality
[return] : const char* signal quality
---
[no-param]
*/
const char* getSignalQuality();
/*
Function for getting query network info
[return] : const char* query network info
---
[no-param]
*/
const char* getQueryNetworkInfo();
/*
Function for connecting to base station of operator
[no-return]
---
[no-param]
*/
void connectToOperator();
/******************************************************************************************
*** GNSS Functions ***********************************************************************
******************************************************************************************/
/*
Function for connecting to base station of operator
[no-return]
---
[no-param]
*/
void turnOnGNSS();
/*
Function for connecting to base station of operator
[no-return]
---
[no-param]
*/
void turnOffGNSS();
/*
Function for connecting to base station of operator
[return] : Fixed location. Lattitude and Longitude
---
[no-param]
*/
const char* getFixedLocation();
/******************************************************************************************
*** TCP & UDP Protocols Functions ********************************************************
******************************************************************************************/
/*
function for configurating and activating TCP context
[no-return]
---
[no-param]
*/
void activateContext();
/*
function for deactivating TCP context
[no-return]
---
[no-param]
*/
void deactivateContext();
/*
function for connecting to server via TCP
just buffer access mode is supported for now.
[no-return]
---
[no-param]
*/
void connectToServerTCP();
/*
Function for sending data via TCP protocol.
First use setIPAddress and setPort functions before
try to send data with this function.
[param #1] : const char* data word
*/
void sendDataTCP(const char *);
/*
Function for sending data to Sixfab Connect Platform
[no-return]
---
[param #1] : const char* server_url
[param #2] : const char* x-api-key
[param #3] : const char* data
*/
void sendDataSixfabConnect(const char *, const char *, const char * );
/*
Function for sending data to Sixfab Connect Platform
[no-return]
---
[param #1] : const char* event_name
[param #2] : const char* api-key
[param #3] : const char* data
*/
void sendDataIFTTT(const char *eventName, const char *api_key, const char *data );
/*
Function for sending data to Sixfab Connect Platform
[no-return]
---
[param #1] : const char* api-key
[param #2] : const char* data
*/
void sendDataThingspeak(const char *api_key, const char *data );
/*
// function for connecting to server via UDP
[no-return]
---
[no-param]
*/
void startUDPService();
/*
Function for sending data via UDP protocol.
First use setIPAddress and setPort functions before
try to send data with this function.
[param #1] : const char* data word
*/
void sendDataUDP(const char *);
/*
Function for closing server connection
[no-return]
---
[no-param]
*/
void closeConnection();
/*
Function for turning on LED.
[no-return]
---
[no-param]
*/
void turnOnUserLED();
/*
Function for turning off LED.
[no-return]
---
[no-param]
*/
void turnOffUserLED();
/*
Function for reading button position.
[return] : uint8_t button position 0 or 1
---
[no-param]
*/
uint8_t readUserButton();
/******************************************************************************************
*** Private Functions that be used in public methods, in order to ease the operations ****
******************************************************************************************/
/*
Function for clear command buffer #private param : compose[100].
[no-return]
---
[no-param]
*/
void clear_compose()
{
memset(compose,0,sizeof(compose));
}
};
// Sub class inheriting from Base Class(Parent)
class SixfabCellularIoTApp : public SixfabCellularIoT
{
public:
/*
Default constructer with no parameter
[no-return]
---
[no-param]
*/
SixfabCellularIoTApp();
/*
Function for initializing module and peripherals
This function do things below:
* enables BG96 module
* sets pin directions
[no-return]
---
[no-param]
*/
void init(); // initialize
/******************************************************************************************
*** Peripheral Devices' Functions : Read sensors - Set Relay and LEDs ********************
******************************************************************************************/
/*
Function for reading accelerometer values.
[no-return]
---
[param #1] : double* acceleration on x plane
[param #2] : double* acceleration on y plane
[param #y] : double* acceleration on z plane
*/
void readAccel(double*, double*, double*);
/*
Function for reading temperature.
[return] : double temperature (celcius)
---
[no-param]
*/
double readTemp();
/*
Function for reading humidity.
[return] : double humidity %x
---
[no-param]
*/
double readHum();
/*
Function for reading raw adc data from light sensor.
[return] : double light adc 0-1023
---
[no-param]
*/
double readLux();
/*
Function for turning on relay.
[no-return]
---
[no-param]
*/
void turnOnRelay();
/*
Function for turning off relay.
[no-return]
---
[no-param]
*/
void turnOffRelay();
};
#endif