-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathSparkFun_u-blox_SARA-R5_Arduino_Library.h
1135 lines (1010 loc) · 51.2 KB
/
SparkFun_u-blox_SARA-R5_Arduino_Library.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
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Arduino library for the u-blox SARA-R5 LTE-M / NB-IoT modules with secure cloud, as used on the SparkFun MicroMod Asset Tracker
By: Paul Clark
October 19th 2020
Based extensively on the:
Arduino Library for the SparkFun LTE CAT M1/NB-IoT Shield - SARA-R4
Written by Jim Lindblom @ SparkFun Electronics, September 5, 2018
This Arduino library provides mechanisms to initialize and use
the SARA-R5 module over either a SoftwareSerial or hardware serial port.
Please see LICENSE.md for the license information
*/
#ifndef SPARKFUN_SARA_R5_ARDUINO_LIBRARY_H
#define SPARKFUN_SARA_R5_ARDUINO_LIBRARY_H
#if (ARDUINO >= 100)
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#ifdef ARDUINO_ARCH_AVR // Arduino AVR boards (Uno, Pro Micro, etc.)
#define SARA_R5_SOFTWARE_SERIAL_ENABLED // Enable software serial
#endif
#ifdef ARDUINO_ARCH_SAMD // Arduino SAMD boards (SAMD21, etc.)
#define SARA_R5_SOFTWARE_SERIAL_ENABLEDx // Disable software serial
#endif
#ifdef ARDUINO_ARCH_APOLLO3 // Arduino Apollo boards (Artemis module, RedBoard Artemis, etc)
#define SARA_R5_SOFTWARE_SERIAL_ENABLEDx // Disable software serial (no longer supported with v2 of Apollo3)
// Note: paulvha has provided software serial support for v2 of the Apollo3 / Artemis core.
// Further details are available at:
// https://github.com/paulvha/apollo3/tree/master/SoftwareSerial
#endif
#ifdef ARDUINO_ARCH_STM32 // STM32 based boards (Disco, Nucleo, etc)
#define SARA_R5_SOFTWARE_SERIAL_ENABLED // Enable software serial
#endif
#ifdef ARDUINO_ARCH_ESP32 // ESP32 based boards
// Check to see if ESP Software Serial has been included
// Note: you need to #include <SoftwareSerial.h> at the very start of your script,
// _before_ the #include <SparkFun_u-blox_SARA-R5_Arduino_Library.h>, for this to work.
// See SARA-R5_Example2_Identification_ESPSoftwareSerial for more details.
#if __has_include(<SoftwareSerial.h> )
#define SARA_R5_SOFTWARE_SERIAL_ENABLED // Enable software serial
#else
#define SARA_R5_SOFTWARE_SERIAL_ENABLEDx // Disable software serial
#endif
#endif
#ifdef ARDUINO_ARCH_ESP8266 // ESP8266 based boards
// Check to see if ESP Software Serial has been included
// Note: you need to #include <SoftwareSerial.h> at the very start of your script,
// _before_ the #include <SparkFun_u-blox_SARA-R5_Arduino_Library.h>, for this to work.
// See SARA-R5_Example2_Identification_ESPSoftwareSerial for more details.
#if __has_include(<SoftwareSerial.h> )
#define SARA_R5_SOFTWARE_SERIAL_ENABLED // Enable software serial
#else
#define SARA_R5_SOFTWARE_SERIAL_ENABLEDx // Disable software serial
#endif
#endif
#ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED
#include <SoftwareSerial.h> // SoftwareSerial.h is guarded. It is OK to include it twice.
#endif
#include <IPAddress.h>
#define SARA_R5_POWER_PIN -1 // Default to no pin
#define SARA_R5_RESET_PIN -1
// Timing
#define SARA_R5_STANDARD_RESPONSE_TIMEOUT 1000
#define SARA_R5_10_SEC_TIMEOUT 10000
#define SARA_R5_55_SECS_TIMEOUT 55000
#define SARA_R5_2_MIN_TIMEOUT 120000
#define SARA_R5_3_MIN_TIMEOUT 180000
#define SARA_R5_SET_BAUD_TIMEOUT 500
#define SARA_R5_POWER_OFF_PULSE_PERIOD 3200 // Hold PWR_ON low for this long to power the module off
#define SARA_R5_POWER_ON_PULSE_PERIOD 100 // Hold PWR_ON low for this long to power the module on (SARA-R510M8S)
#define SARA_R5_RESET_PULSE_PERIOD 23000 // Used to perform an abrupt emergency hardware shutdown. 23 seconds... (Yes, really!)
#define SARA_R5_POWER_OFF_TIMEOUT 40000 // Datasheet says 40 seconds...
#define SARA_R5_IP_CONNECT_TIMEOUT 130000
#define SARA_R5_POLL_DELAY 1
#define SARA_R5_SOCKET_WRITE_TIMEOUT 10000
#define SARA_R5_SECURITY_RESPONSE_TIMEOUT 10000
// ## Suported AT Commands
// ### General
const char SARA_R5_COMMAND_AT[] = "AT"; // AT "Test"
const char SARA_R5_COMMAND_ECHO[] = "E"; // Local Echo
const char SARA_R5_COMMAND_MANU_ID[] = "+CGMI"; // Manufacturer identification
const char SARA_R5_COMMAND_MODEL_ID[] = "+CGMM"; // Model identification
const char SARA_R5_COMMAND_FW_VER_ID[] = "+CGMR"; // Firmware version identification
const char SARA_R5_COMMAND_SERIAL_NO[] = "+CGSN"; // Product serial number
const char SARA_R5_COMMAND_IMEI[] = "+GSN"; // IMEI identification
const char SARA_R5_COMMAND_IMSI[] = "+CIMI"; // IMSI identification
const char SARA_R5_COMMAND_CCID[] = "+CCID"; // SIM CCID
const char SARA_R5_COMMAND_REQ_CAP[] = "+GCAP"; // Request capabilities list
// ### Control and status
const char SARA_R5_COMMAND_POWER_OFF[] = "+CPWROFF"; // Module switch off
const char SARA_R5_COMMAND_FUNC[] = "+CFUN"; // Functionality (reset, etc.)
const char SARA_R5_COMMAND_CLOCK[] = "+CCLK"; // Real-time clock
const char SARA_R5_COMMAND_AUTO_TZ[] = "+CTZU"; // Automatic time zone update
const char SARA_R5_COMMAND_TZ_REPORT[] = "+CTZR"; // Time zone reporting
// ### Network service
const char SARA_R5_COMMAND_CNUM[] = "+CNUM"; // Subscriber number
const char SARA_R5_SIGNAL_QUALITY[] = "+CSQ";
const char SARA_R5_EXT_SIGNAL_QUALITY[] = "+CESQ";
const char SARA_R5_OPERATOR_SELECTION[] = "+COPS";
const char SARA_R5_REGISTRATION_STATUS[] = "+CREG";
const char SARA_R5_EPSREGISTRATION_STATUS[] = "+CEREG";
const char SARA_R5_READ_OPERATOR_NAMES[] = "+COPN";
const char SARA_R5_COMMAND_MNO[] = "+UMNOPROF"; // MNO (mobile network operator) Profile
// ### SIM
const char SARA_R5_SIM_STATE[] = "+USIMSTAT";
const char SARA_R5_COMMAND_SIMPIN[] = "+CPIN"; // SIM PIN
// ### SMS
const char SARA_R5_MESSAGE_FORMAT[] = "+CMGF"; // Set SMS message format
const char SARA_R5_SEND_TEXT[] = "+CMGS"; // Send SMS message
const char SARA_R5_NEW_MESSAGE_IND[] = "+CNMI"; // New [SMS] message indication
const char SARA_R5_PREF_MESSAGE_STORE[] = "+CPMS"; // Preferred message storage
const char SARA_R5_READ_TEXT_MESSAGE[] = "+CMGR"; // Read message
const char SARA_R5_DELETE_MESSAGE[] = "+CMGD"; // Delete message
// V24 control and V25ter (UART interface)
const char SARA_R5_FLOW_CONTROL[] = "&K"; // Flow control
const char SARA_R5_COMMAND_BAUD[] = "+IPR"; // Baud rate
// ### Packet switched data services
const char SARA_R5_MESSAGE_PDP_DEF[] = "+CGDCONT"; // Packet switched Data Profile context definition
const char SARA_R5_MESSAGE_PDP_CONFIG[] = "+UPSD"; // Packet switched Data Profile configuration
const char SARA_R5_MESSAGE_PDP_ACTION[] = "+UPSDA"; // Perform the action for the specified PSD profile
const char SARA_R5_MESSAGE_PDP_CONTEXT_ACTIVATE[] = "+CGACT"; // Activates or deactivates the specified PDP context
const char SARA_R5_MESSAGE_ENTER_PPP[] = "D";
const char SARA_R5_NETWORK_ASSIGNED_DATA[] = "+UPSND"; // Packet switched network-assigned data
// ### GPIO
const char SARA_R5_COMMAND_GPIO[] = "+UGPIOC"; // GPIO Configuration
// ### IP
const char SARA_R5_CREATE_SOCKET[] = "+USOCR"; // Create a new socket
const char SARA_R5_CLOSE_SOCKET[] = "+USOCL"; // Close a socket
const char SARA_R5_CONNECT_SOCKET[] = "+USOCO"; // Connect to server on socket
const char SARA_R5_WRITE_SOCKET[] = "+USOWR"; // Write data to a socket
const char SARA_R5_WRITE_UDP_SOCKET[] = "+USOST"; // Write data to a UDP socket
const char SARA_R5_READ_SOCKET[] = "+USORD"; // Read from a socket
const char SARA_R5_READ_UDP_SOCKET[] = "+USORF"; // Read UDP data from a socket
const char SARA_R5_LISTEN_SOCKET[] = "+USOLI"; // Listen for connection on socket
const char SARA_R5_GET_ERROR[] = "+USOER"; // Get last socket error.
const char SARA_R5_SOCKET_DIRECT_LINK[] = "+USODL"; // Set socket in Direct Link mode
const char SARA_R5_SOCKET_CONTROL[] = "+USOCTL"; // Query the socket parameters
const char SARA_R5_UD_CONFIGURATION[] = "+UDCONF"; // User Datagram Configuration
const char SARA_R5_SECURE_SOCKET[] = "+USOSEC"; // SSL/TLS/DTLS mode configuration
// ### Ping
const char SARA_R5_PING_COMMAND[] = "+UPING"; // Ping
// ### HTTP
const char SARA_R5_HTTP_PROFILE[] = "+UHTTP"; // Configure the HTTP profile. Up to 4 different profiles can be defined
const char SARA_R5_HTTP_COMMAND[] = "+UHTTPC"; // Trigger the specified HTTP command
const char SARA_R5_HTTP_PROTOCOL_ERROR[] = "+UHTTPER"; // Retrieves the error class and code of the latest HTTP operation on the specified HTTP profile.
const char SARA_R5_MQTT_NVM[] = "+UMQTTNV";
const char SARA_R5_MQTT_PROFILE[] = "+UMQTT";
const char SARA_R5_MQTT_COMMAND[] = "+UMQTTC";
const char SARA_R5_MQTT_PROTOCOL_ERROR[] = "+UMQTTER";
// ### FTP
const char SARA_R5_FTP_PROFILE[] = "+UFTP";
const char SARA_R5_FTP_COMMAND[] = "+UFTPC";
const char SARA_R5_FTP_PROTOCOL_ERROR[] = "+UFTPER";
// ### GNSS
const char SARA_R5_GNSS_POWER[] = "+UGPS"; // GNSS power management configuration
const char SARA_R5_GNSS_ASSISTED_IND[] = "+UGIND"; // Assisted GNSS unsolicited indication
const char SARA_R5_GNSS_REQUEST_LOCATION[] = "+ULOC"; // Ask for localization information
const char SARA_R5_GNSS_GPRMC[] = "+UGRMC"; // Ask for localization information
const char SARA_R5_GNSS_REQUEST_TIME[] = "+UTIME"; // Ask for time information from cellular modem (CellTime)
const char SARA_R5_GNSS_TIME_INDICATION[] = "+UTIMEIND"; // Time information request status unsolicited indication
const char SARA_R5_GNSS_TIME_CONFIGURATION[] = "+UTIMECFG"; // Sets time configuration
const char SARA_R5_GNSS_CONFIGURE_SENSOR[] = "+ULOCGNSS"; // Configure GNSS sensor
const char SARA_R5_GNSS_CONFIGURE_LOCATION[] = "+ULOCCELL"; // Configure cellular location sensor (CellLocate®)
const char SARA_R5_AIDING_SERVER_CONFIGURATION[] = "+UGSRV"; // Configure aiding server (CellLocate®)
// ### File System
// TO DO: Add support for file tags. Default tag to USER
const char SARA_R5_FILE_SYSTEM_READ_FILE[] = "+URDFILE"; // Read a file
const char SARA_R5_FILE_SYSTEM_READ_BLOCK[] = "+URDBLOCK"; // Read a block from a file
const char SARA_R5_FILE_SYSTEM_DOWNLOAD_FILE[] = "+UDWNFILE"; // Download a file into the module
const char SARA_R5_FILE_SYSTEM_LIST_FILES[] = "+ULSTFILE"; // List of files, size of file, etc.
const char SARA_R5_FILE_SYSTEM_DELETE_FILE[] = "+UDELFILE"; // Delete a file
// ### File System
// TO DO: Add support for file tags. Default tag to USER
const char SARA_R5_SEC_PROFILE[] = "+USECPRF";
const char SARA_R5_SEC_MANAGER[] = "+USECMNG";
// ### URC strings
const char SARA_R5_READ_SOCKET_URC[] = "+UUSORD:";
const char SARA_R5_READ_UDP_SOCKET_URC[] = "+UUSORF:";
const char SARA_R5_LISTEN_SOCKET_URC[] = "+UUSOLI:";
const char SARA_R5_CLOSE_SOCKET_URC[] = "+UUSOCL:";
const char SARA_R5_GNSS_REQUEST_LOCATION_URC[] = "+UULOC:";
const char SARA_R5_SIM_STATE_URC[] = "+UUSIMSTAT:";
const char SARA_R5_MESSAGE_PDP_ACTION_URC[] = "+UUPSDA:";
const char SARA_R5_HTTP_COMMAND_URC[] = "+UUHTTPCR:";
const char SARA_R5_MQTT_COMMAND_URC[] = "+UUMQTTC:";
const char SARA_R5_PING_COMMAND_URC[] = "+UUPING:";
const char SARA_R5_REGISTRATION_STATUS_URC[] = "+CREG:";
const char SARA_R5_EPSREGISTRATION_STATUS_URC[] = "+CEREG:";
const char SARA_R5_FTP_COMMAND_URC[] = "+UUFTPCR:";
// ### Response
const char SARA_R5_RESPONSE_MORE[] = "\n>";
const char SARA_R5_RESPONSE_OK[] = "\nOK\r\n";
const char SARA_R5_RESPONSE_ERROR[] = "\nERROR\r\n";
const char SARA_R5_RESPONSE_CONNECT[] = "\r\nCONNECT\r\n";
#define SARA_R5_RESPONSE_OK_OR_ERROR nullptr
// CTRL+Z and ESC ASCII codes for SMS message sends
const char ASCII_CTRL_Z = 0x1A;
const char ASCII_ESC = 0x1B;
// NMEA data size - used by parseGPRMCString
#define TEMP_NMEA_DATA_SIZE 16
#define NOT_AT_COMMAND false
#define AT_COMMAND true
// The minimum memory allocation for responses from sendCommandWithResponse
// This needs to be large enough to hold the response you're expecting plus and URC's that may arrive during the timeout
#define minimumResponseAllocation 128
#define SARA_R5_NUM_SOCKETS 6
#define NUM_SUPPORTED_BAUD 6
const unsigned long SARA_R5_SUPPORTED_BAUD[NUM_SUPPORTED_BAUD] =
{
115200,
9600,
19200,
38400,
57600,
230400};
#define SARA_R5_DEFAULT_BAUD_RATE 115200
// Flow control definitions for AT&K
// Note: SW (XON/XOFF) flow control is not supported on the SARA_R5
typedef enum
{
SARA_R5_DISABLE_FLOW_CONTROL = 0,
SARA_R5_ENABLE_FLOW_CONTROL = 3
} SARA_R5_flow_control_t;
// The standard Europe profile should be used as the basis for all other MNOs in Europe outside of Vodafone
// and Deutsche Telekom. However, there may be changes that need to be applied to the module for proper
// operation with any given European MNO such as attach type, RAT preference, band selection, etc. Please
// consult with the preferred network provider.
typedef enum
{
MNO_INVALID = -1,
MNO_SW_DEFAULT = 0, // Undefined / regulatory
MNO_SIM_ICCID = 1,
MNO_ATT = 2, // AT&T
MNO_VERIZON = 3,
MNO_TELSTRA = 4,
MNO_TMO = 5, // T-Mobile US
MNO_CT = 6, // China Telecom
MNO_SPRINT = 8,
MNO_VODAFONE = 19,
MNO_NTT_DOCOMO = 20,
MNO_TELUS = 21,
MNO_SOFTBANK = 28,
MNO_DT = 31, // Deutsche Telekom
MNO_US_CELLULAR = 32,
MNO_SKT = 39,
MNO_GLOBAL = 90,
MNO_STD_EUROPE = 100,
MNO_STD_EU_NOEPCO = 101
} mobile_network_operator_t;
typedef enum
{
SARA_R5_ERROR_INVALID = -1, // -1
SARA_R5_ERROR_SUCCESS = 0, // 0
SARA_R5_ERROR_OUT_OF_MEMORY, // 1
SARA_R5_ERROR_TIMEOUT, // 2
SARA_R5_ERROR_UNEXPECTED_PARAM, // 3
SARA_R5_ERROR_UNEXPECTED_RESPONSE, // 4
SARA_R5_ERROR_NO_RESPONSE, // 5
SARA_R5_ERROR_DEREGISTERED, // 6
SARA_R5_ERROR_ZERO_READ_LENGTH, // 7
SARA_R5_ERROR_ERROR // 8
} SARA_R5_error_t;
#define SARA_R5_SUCCESS SARA_R5_ERROR_SUCCESS
typedef enum
{
SARA_R5_REGISTRATION_INVALID = -1,
SARA_R5_REGISTRATION_NOT_REGISTERED = 0,
SARA_R5_REGISTRATION_HOME = 1,
SARA_R5_REGISTRATION_SEARCHING = 2,
SARA_R5_REGISTRATION_DENIED = 3,
SARA_R5_REGISTRATION_UNKNOWN = 4,
SARA_R5_REGISTRATION_ROAMING = 5,
SARA_R5_REGISTRATION_HOME_SMS_ONLY = 6,
SARA_R5_REGISTRATION_ROAMING_SMS_ONLY = 7,
SARA_R5_REGISTRATION_EMERGENCY_SERV_ONLY = 8,
SARA_R5_REGISTRATION_HOME_CSFB_NOT_PREFERRED = 9,
SARA_R5_REGISTRATION_ROAMING_CSFB_NOT_PREFERRED = 10
} SARA_R5_registration_status_t;
struct DateData
{
uint8_t day;
uint8_t month;
unsigned int year;
};
struct TimeData
{
uint8_t hour;
uint8_t minute;
uint8_t second;
unsigned int ms;
uint8_t tzh;
uint8_t tzm;
};
struct ClockData
{
struct DateData date;
struct TimeData time;
};
struct PositionData
{
float utc;
float lat; // Degrees: +/- 90
float lon; // Degrees: +/- 180
float alt;
char mode;
char status;
};
struct SpeedData
{
float speed; // m/s
float cog; // Degrees
float magVar; // Degrees
};
struct operator_stats
{
uint8_t stat;
String shortOp;
String longOp;
unsigned long numOp;
uint8_t act;
};
typedef struct ext_signal_quality_ {
unsigned int rxlev;
unsigned int ber;
unsigned int rscp;
unsigned int enc0;
unsigned int rsrq;
unsigned int rsrp;
} signal_quality;
typedef enum
{
SARA_R5_TCP = 6,
SARA_R5_UDP = 17
} SARA_R5_socket_protocol_t;
typedef enum
{
SARA_R5_TCP_SOCKET_STATUS_INACTIVE,
SARA_R5_TCP_SOCKET_STATUS_LISTEN,
SARA_R5_TCP_SOCKET_STATUS_SYN_SENT,
SARA_R5_TCP_SOCKET_STATUS_SYN_RCVD,
SARA_R5_TCP_SOCKET_STATUS_ESTABLISHED,
SARA_R5_TCP_SOCKET_STATUS_FIN_WAIT_1,
SARA_R5_TCP_SOCKET_STATUS_FIN_WAIT_2,
SARA_R5_TCP_SOCKET_STATUS_CLOSE_WAIT,
SARA_R5_TCP_SOCKET_STATUS_CLOSING,
SARA_R5_TCP_SOCKET_STATUS_LAST_ACK,
SARA_R5_TCP_SOCKET_STATUS_TIME_WAIT
} SARA_R5_tcp_socket_status_t;
typedef enum
{
SARA_R5_MESSAGE_FORMAT_PDU = 0,
SARA_R5_MESSAGE_FORMAT_TEXT = 1
} SARA_R5_message_format_t;
typedef enum
{
SARA_R5_UTIME_MODE_STOP = 0,
SARA_R5_UTIME_MODE_PPS,
SARA_R5_UTIME_MODE_ONE_SHOT,
SARA_R5_UTIME_MODE_EXT_INT
} SARA_R5_utime_mode_t;
typedef enum
{
SARA_R5_UTIME_SENSOR_NONE = 0,
SARA_R5_UTIME_SENSOR_GNSS_LTE = 1,
SARA_R5_UTIME_SENSOR_LTE
} SARA_R5_utime_sensor_t;
typedef enum
{
SARA_R5_UTIME_URC_CONFIGURATION_DISABLED = 0,
SARA_R5_UTIME_URC_CONFIGURATION_ENABLED
} SARA_R5_utime_urc_configuration_t;
typedef enum
{
SARA_R5_SIM_NOT_PRESENT = 0,
SARA_R5_SIM_PIN_NEEDED,
SARA_R5_SIM_PIN_BLOCKED,
SARA_R5_SIM_PUK_BLOCKED,
SARA_R5_SIM_NOT_OPERATIONAL,
SARA_R5_SIM_RESTRICTED,
SARA_R5_SIM_OPERATIONAL
//SARA_R5_SIM_PHONEBOOK_READY, // Not reported by SARA-R5
//SARA_R5_SIM_USIM_PHONEBOOK_READY, // Not reported by SARA-R5
//SARA_R5_SIM_TOOLKIT_REFRESH_SUCCESSFUL, // Not reported by SARA-R5
//SARA_R5_SIM_TOOLKIT_REFRESH_UNSUCCESSFUL, // Not reported by SARA-R5
//SARA_R5_SIM_PPP_CONNECTION_ACTIVE, // Not reported by SARA-R5
//SARA_R5_SIM_VOICE_CALL_ACTIVE, // Not reported by SARA-R5
//SARA_R5_SIM_CSD_CALL_ACTIVE // Not reported by SARA-R5
} SARA_R5_sim_states_t;
#define SARA_R5_NUM_PSD_PROFILES 6 // Number of supported PSD profiles
#define SARA_R5_NUM_PDP_CONTEXT_IDENTIFIERS 11 // Number of supported PDP context identifiers
#define SARA_R5_NUM_HTTP_PROFILES 4 // Number of supported HTTP profiles
typedef enum
{
SARA_R5_HTTP_OP_CODE_SERVER_IP = 0,
SARA_R5_HTTP_OP_CODE_SERVER_NAME,
SARA_R5_HTTP_OP_CODE_USERNAME,
SARA_R5_HTTP_OP_CODE_PASSWORD,
SARA_R5_HTTP_OP_CODE_AUTHENTICATION,
SARA_R5_HTTP_OP_CODE_SERVER_PORT,
SARA_R5_HTTP_OP_CODE_SECURE,
SARA_R5_HTTP_OP_CODE_REQUEST_TIMEOUT,
SARA_R5_HTTP_OP_CODE_ADD_CUSTOM_HEADERS = 9
} SARA_R5_http_op_codes_t;
typedef enum
{
SARA_R5_HTTP_COMMAND_HEAD = 0,
SARA_R5_HTTP_COMMAND_GET,
SARA_R5_HTTP_COMMAND_DELETE,
SARA_R5_HTTP_COMMAND_PUT,
SARA_R5_HTTP_COMMAND_POST_FILE,
SARA_R5_HTTP_COMMAND_POST_DATA,
SARA_R5_HTTP_COMMAND_GET_FOTA = 100
} SARA_R5_http_commands_t;
typedef enum
{
SARA_R5_HTTP_CONTENT_APPLICATION_X_WWW = 0,
SARA_R5_HTTP_CONTENT_TEXT_PLAIN,
SARA_R5_HTTP_CONTENT_APPLICATION_OCTET,
SARA_R5_HTTP_CONTENT_MULTIPART_FORM,
SARA_R5_HTTP_CONTENT_APPLICATION_JSON,
SARA_R5_HTTP_CONTENT_APPLICATION_XML,
SARA_R5_HTTP_CONTENT_USER_DEFINED
} SARA_R5_http_content_types_t;
typedef enum
{
SARA_R5_MQTT_NV_RESTORE = 0,
SARA_R5_MQTT_NV_SET,
SARA_R5_MQTT_NV_STORE,
} SARA_R5_mqtt_nv_parameter_t;
typedef enum
{
SARA_R5_MQTT_PROFILE_CLIENT_ID = 0,
SARA_R5_MQTT_PROFILE_SERVERNAME = 2,
SARA_R5_MQTT_PROFILE_IPADDRESS,
SARA_R5_MQTT_PROFILE_USERNAMEPWD,
SARA_R5_MQTT_PROFILE_QOS = 6,
SARA_R5_MQTT_PROFILE_RETAIN,
SARA_R5_MQTT_PROFILE_TOPIC,
SARA_R5_MQTT_PROFILE_MESSAGE,
SARA_R5_MQTT_PROFILE_INACTIVITYTIMEOUT,
SARA_R5_MQTT_PROFILE_SECURE,
} SARA_R5_mqtt_profile_opcode_t;
typedef enum
{
SARA_R5_MQTT_COMMAND_INVALID = -1,
SARA_R5_MQTT_COMMAND_LOGOUT = 0,
SARA_R5_MQTT_COMMAND_LOGIN,
SARA_R5_MQTT_COMMAND_PUBLISH,
SARA_R5_MQTT_COMMAND_PUBLISHFILE,
SARA_R5_MQTT_COMMAND_SUBSCRIBE,
SARA_R5_MQTT_COMMAND_UNSUBSCRIBE,
SARA_R5_MQTT_COMMAND_READ,
SARA_R5_MQTT_COMMAND_RCVMSGFORMAT,
SARA_R5_MQTT_COMMAND_PING,
SARA_R5_MQTT_COMMAND_PUBLISHBINARY,
} SARA_R5_mqtt_command_opcode_t;
constexpr uint16_t MAX_MQTT_HEX_MSG_LEN = 512;
constexpr uint16_t MAX_MQTT_DIRECT_MSG_LEN = 1024;
typedef enum
{
SARA_R5_FTP_PROFILE_IPADDRESS = 0,
SARA_R5_FTP_PROFILE_SERVERNAME,
SARA_R5_FTP_PROFILE_USERNAME,
SARA_R5_FTP_PROFILE_PWD,
SARA_R5_FTP_PROFILE_ACCOUNT,
SARA_R5_FTP_PROFILE_TIMEOUT,
SARA_R5_FTP_PROFILE_MODE
} SARA_R5_ftp_profile_opcode_t;
typedef enum
{
SARA_R5_FTP_COMMAND_INVALID = -1,
SARA_R5_FTP_COMMAND_LOGOUT = 0,
SARA_R5_FTP_COMMAND_LOGIN,
SARA_R5_FTP_COMMAND_DELETE_FILE,
SARA_R5_FTP_COMMAND_RENAME_FILE,
SARA_R5_FTP_COMMAND_GET_FILE,
SARA_R5_FTP_COMMAND_PUT_FILE,
SARA_R5_FTP_COMMAND_GET_FILE_DIRECT,
SARA_R5_FTP_COMMAND_PUT_FILE_DIRECT,
SARA_R5_FTP_COMMAND_CHANGE_DIR,
SARA_R5_FTP_COMMAND_MKDIR = 10,
SARA_R5_FTP_COMMAND_RMDIR,
SARA_R5_FTP_COMMAND_DIR_INFO = 13,
SARA_R5_FTP_COMMAND_LS,
SARA_R5_FTP_COMMAND_GET_FOTA_FILE = 100
} SARA_R5_ftp_command_opcode_t;
typedef enum
{
SARA_R5_PSD_CONFIG_PARAM_PROTOCOL = 0,
SARA_R5_PSD_CONFIG_PARAM_APN,
//SARA_R5_PSD_CONFIG_PARAM_USERNAME, // Not allowed on SARA-R5
//SARA_R5_PSD_CONFIG_PARAM_PASSWORD, // Not allowed on SARA-R5
SARA_R5_PSD_CONFIG_PARAM_DNS1 = 4,
SARA_R5_PSD_CONFIG_PARAM_DNS2,
//SARA_R5_PSD_CONFIG_PARAM_AUTHENTICATION, // Not allowed on SARA-R5
//SARA_R5_PSD_CONFIG_PARAM_IP_ADDRESS, // Not allowed on SARA-R5
//SARA_R5_PSD_CONFIG_PARAM_DATA_COMPRESSION, // Not allowed on SARA-R5
//SARA_R5_PSD_CONFIG_PARAM_HEADER_COMPRESSION, // Not allowed on SARA-R5
SARA_R5_PSD_CONFIG_PARAM_MAP_TO_CID = 100
} SARA_R5_pdp_configuration_parameter_t;
typedef enum
{
SARA_R5_PSD_PROTOCOL_IPV4 = 0,
SARA_R5_PSD_PROTOCOL_IPV6,
SARA_R5_PSD_PROTOCOL_IPV4V6_V4_PREF,
SARA_R5_PSD_PROTOCOL_IPV4V6_V6_PREF
} SARA_R5_pdp_protocol_type_t;
typedef enum
{
SARA_R5_PSD_ACTION_RESET = 0,
SARA_R5_PSD_ACTION_STORE,
SARA_R5_PSD_ACTION_LOAD,
SARA_R5_PSD_ACTION_ACTIVATE,
SARA_R5_PSD_ACTION_DEACTIVATE
} SARA_R5_pdp_actions_t;
typedef enum
{
SARA_R5_SEC_PROFILE_PARAM_CERT_VAL_LEVEL = 0,
SARA_R5_SEC_PROFILE_PARAM_TLS_VER,
SARA_R5_SEC_PROFILE_PARAM_CYPHER_SUITE,
SARA_R5_SEC_PROFILE_PARAM_ROOT_CA,
SARA_R5_SEC_PROFILE_PARAM_HOSTNAME,
SARA_R5_SEC_PROFILE_PARAM_CLIENT_CERT,
SARA_R5_SEC_PROFILE_PARAM_CLIENT_KEY,
SARA_R5_SEC_PROFILE_PARAM_CLIENT_KEY_PWD,
SARA_R5_SEC_PROFILE_PARAM_PSK,
SARA_R5_SEC_PROFILE_PARAM_PSK_IDENT,
SARA_R5_SEC_PROFILE_PARAM_SNI,
} SARA_R5_sec_profile_parameter_t;
typedef enum
{
SARA_R5_SEC_PROFILE_CERTVAL_OPCODE_NO = 0,
SARA_R5_SEC_PROFILE_CERTVAL_OPCODE_YESNOURL,
SARA_R5_SEC_PROFILE_CERVTAL_OPCODE_YESURL,
SARA_R5_SEC_PROFILE_CERTVAL_OPCODE_YESURLDATE,
} SARA_R5_sec_profile_certval_op_code_t;
typedef enum
{
SARA_R5_SEC_PROFILE_TLS_OPCODE_ANYVER = 0,
SARA_R5_SEC_PROFILE_TLS_OPCODE_VER1_0,
SARA_R5_SEC_PROFILE_TLS_OPCODE_VER1_1,
SARA_R5_SEC_PROFILE_TLS_OPCODE_VER1_2,
SARA_R5_SEC_PROFILE_TLS_OPCODE_VER1_3,
} SARA_R5_sec_profile_tls_op_code_t;
typedef enum
{
SARA_R5_SEC_PROFILE_SUITE_OPCODE_PROPOSEDDEFAULT = 0,
} SARA_R5_sec_profile_suite_op_code_t;
typedef enum
{
SARA_R5_SEC_MANAGER_OPCODE_IMPORT = 0,
} SARA_R5_sec_manager_opcode_t;
typedef enum
{
SARA_R5_SEC_MANAGER_ROOTCA = 0,
SARA_R5_SEC_MANAGER_CLIENT_CERT,
SARA_R5_SEC_MANAGER_CLIENT_KEY,
SARA_R5_SEC_MANAGER_SERVER_CERT
} SARA_R5_sec_manager_parameter_t;
typedef enum
{
MINIMUM_FUNCTIONALITY = 0, // (disable both transmit and receive RF circuits by deactivating both CS and PS services)
FULL_FUNCTIONALITY = 1,
AIRPLANE_MODE = 4,
SIM_TOOLKIT_ENABLE_DEDICATED = 6,
SIM_TOOLKIT_DISABLE_DEDICATED = 7,
SIM_TOOLKIT_ENABLE_RAW = 9,
FAST_SAFE_POWER_OFF = 10,
//SILENT_RESET_WITHOUT_SIM = 15, // Not supported on SARA-R5
SILENT_RESET_WITH_SIM = 16
//MINIMUM_FUNCTIONALITY = 19, // Not supported on SARA-R5
//DEEP_LOW_POWER_STATE = 127 // Not supported on SARA-R5
} SARA_R5_functionality_t;
class SARA_R5 : public Print
{
public:
// Constructor
// The library will use the powerPin and resetPin (if provided) to power the module off/on and perform an emergency reset
// maxInitTries sets the maximum number of initialization attempts. .init is called by .begin.
SARA_R5(int powerPin = SARA_R5_POWER_PIN, int resetPin = SARA_R5_RESET_PIN, uint8_t maxInitTries = 9);
~SARA_R5();
// Begin -- initialize module and ensure it's connected
#ifdef SARA_R5_SOFTWARE_SERIAL_ENABLED
bool begin(SoftwareSerial &softSerial, unsigned long baud = 9600);
#endif
bool begin(HardwareSerial &hardSerial, unsigned long baud = 9600);
// Debug prints
void enableDebugging(Print &debugPort = Serial); //Turn on debug printing. If user doesn't specify then Serial will be used.
void enableAtDebugging(Print &debugPort = Serial); //Turn on AT debug printing. If user doesn't specify then Serial will be used.
// Invert the polarity of the power pin - if required
// Normally the SARA's power pin is pulled low and released to toggle the power
// But the Asset Tracker needs this to be pulled high and released instead
void invertPowerPin(bool invert = false);
SARA_R5_error_t modulePowerOff(void); // Graceful disconnect and shutdown using +CPWROFF.
void modulePowerOn(void); // Requires access to the PWR_ON pin
// Loop polling and polling setup - process URC's etc. from the module
// This function was originally written by Matthew Menze for the LTE Shield (SARA-R4) library
// See: https://github.com/sparkfun/SparkFun_LTE_Shield_Arduino_Library/pull/8
// It does the same job as ::poll but also processes any 'old' data stored in the backlog first
// It also has a built-in timeout - which ::poll does not
// Use this - it is way better than ::poll. Thank you Matthew!
bool bufferedPoll(void);
// This is the original poll function.
// It is 'blocking' - it does not return when serial data is available until it receives a `\n`.
// ::bufferedPoll is the new improved version. It processes any data in the backlog and includes a timeout.
// Retained for backward-compatibility and just in case you do want to (temporarily) ignore any data in the backlog
bool poll(void);
// Callbacks (called during polling)
void setSocketListenCallback(void (*socketListenCallback)(int, IPAddress, unsigned int, int, IPAddress, unsigned int)); // listen Socket, local IP Address, listen Port, socket, remote IP Address, port
// This is the original read socket callback - called when a +UUSORD or +UUSORF URC is received
// It works - and handles binary data correctly - but the remote IP Address and Port are lost for UDP connections
// setSocketReadCallbackPlus is preferred!
void setSocketReadCallback(void (*socketReadCallback)(int, String)); // socket, read data
void setSocketReadCallbackPlus(void (*socketReadCallbackPlus)(int, const char *, int, IPAddress, int)); // socket, read data, length, remoteAddress, remotePort
void setSocketCloseCallback(void (*socketCloseCallback)(int)); // socket
void setGpsReadCallback(void (*gpsRequestCallback)(ClockData time,
PositionData gps, SpeedData spd, unsigned long uncertainty));
void setSIMstateReportCallback(void (*simStateRequestCallback)(SARA_R5_sim_states_t state));
void setPSDActionCallback(void (*psdActionRequestCallback)(int result, IPAddress ip));
void setPingCallback(void (*pingRequestCallback)(int retry, int p_size, String remote_hostname, IPAddress ip, int ttl, long rtt));
void setHTTPCommandCallback(void (*httpCommandRequestCallback)(int profile, int command, int result));
void setMQTTCommandCallback(void (*mqttCommandRequestCallback)(int command, int result));
void setFTPCommandCallback(void (*ftpCommandRequestCallback)(int command, int result));
SARA_R5_error_t setRegistrationCallback(void (*registrationCallback)(SARA_R5_registration_status_t status,
unsigned int lac, unsigned int ci, int Act));
SARA_R5_error_t setEpsRegistrationCallback(void (*epsRegistrationCallback)(SARA_R5_registration_status_t status,
unsigned int tac, unsigned int ci, int Act));
// Direct write/print to cell serial port
virtual size_t write(uint8_t c);
virtual size_t write(const char *str);
virtual size_t write(const char *buffer, size_t size);
// General AT Commands
SARA_R5_error_t at(void);
SARA_R5_error_t enableEcho(bool enable = true);
String getManufacturerID(void);
String getModelID(void);
String getFirmwareVersion(void);
String getSerialNo(void);
String getIMEI(void);
String getIMSI(void);
String getCCID(void);
String getSubscriberNo(void);
String getCapabilities(void);
// Control and status AT commands
SARA_R5_error_t reset(void);
String clock(void);
// TODO: Return a clock struct
SARA_R5_error_t clock(uint8_t *y, uint8_t *mo, uint8_t *d,
uint8_t *h, uint8_t *min, uint8_t *s, int8_t *tz); // TZ can be +/- and is in increments of 15 minutes. -28 == 7 hours behind UTC/GMT
SARA_R5_error_t setClock(String theTime);
SARA_R5_error_t setClock(uint8_t y, uint8_t mo, uint8_t d,
uint8_t h, uint8_t min, uint8_t s, int8_t tz); // TZ can be +/- and is in increments of 15 minutes. -28 == 7 hours behind UTC/GMT
void autoTimeZoneForBegin(bool enable = true); // Call autoTimeZoneForBegin(false) _before_ .begin if you want to disable the automatic time zone
SARA_R5_error_t autoTimeZone(bool enable); // Enable/disable automatic time zone adjustment
SARA_R5_error_t setUtimeMode(SARA_R5_utime_mode_t mode = SARA_R5_UTIME_MODE_PPS, SARA_R5_utime_sensor_t sensor = SARA_R5_UTIME_SENSOR_GNSS_LTE); // Time mode, source etc. (+UTIME)
SARA_R5_error_t getUtimeMode(SARA_R5_utime_mode_t *mode, SARA_R5_utime_sensor_t *sensor);
SARA_R5_error_t setUtimeIndication(SARA_R5_utime_urc_configuration_t config = SARA_R5_UTIME_URC_CONFIGURATION_ENABLED); // +UTIMEIND
SARA_R5_error_t getUtimeIndication(SARA_R5_utime_urc_configuration_t *config);
SARA_R5_error_t setUtimeConfiguration(int32_t offsetNanoseconds = 0, int32_t offsetSeconds = 0); // +UTIMECFG
SARA_R5_error_t getUtimeConfiguration(int32_t *offsetNanoseconds, int32_t *offsetSeconds);
// Network service AT commands
int8_t rssi(void); // Receive signal strength
SARA_R5_error_t getExtSignalQuality(signal_quality& signal_quality);
SARA_R5_registration_status_t registration(bool eps = true);
bool setNetworkProfile(mobile_network_operator_t mno, bool autoReset = false, bool urcNotification = false);
mobile_network_operator_t getNetworkProfile(void);
typedef enum
{
PDP_TYPE_INVALID = -1,
PDP_TYPE_IP = 0,
PDP_TYPE_NONIP = 1,
PDP_TYPE_IPV4V6 = 2,
PDP_TYPE_IPV6 = 3
} SARA_R5_pdp_type;
SARA_R5_error_t setAPN(String apn, uint8_t cid = 1, SARA_R5_pdp_type pdpType = PDP_TYPE_IP); // Set the Access Point Name
SARA_R5_error_t getAPN(int cid, String *apn, IPAddress *ip, SARA_R5_pdp_type* pdpType = nullptr); // Return the apn and IP address for the chosen context identifier
SARA_R5_error_t getSimStatus(String* code);
SARA_R5_error_t setSimPin(String pin);
// SIM
// Status report Mode:
// Bit States reported
// 0 Reports the (U)SIM initialization status (<state>'s from 0 to 6 may be reported)
// 1 Reports the (U)SIM phonebook initialization status (<state>'s from 7 to 8 may be reported)
// 2 Reports the (U)SIM toolkit REFRESH proactive command execution result (<state>'s from 9 to 13 may be reported)
// Note: For the SARA-R5: <state>=7, 8, 9, 10, 11, 12 and 13 are not reported.
SARA_R5_error_t setSIMstateReportingMode(int mode);
SARA_R5_error_t getSIMstateReportingMode(int *mode);
typedef enum
{
L2P_DEFAULT,
L2P_PPP,
L2P_M_HEX,
L2P_M_RAW_IP,
L2P_M_OPT_PPP
} SARA_R5_l2p_t;
SARA_R5_error_t enterPPP(uint8_t cid = 1, char dialing_type_char = 0,
unsigned long dialNumber = 99, SARA_R5_l2p_t l2p = L2P_DEFAULT);
uint8_t getOperators(struct operator_stats *op, int maxOps = 3);
SARA_R5_error_t registerOperator(struct operator_stats oper);
SARA_R5_error_t automaticOperatorSelection();
SARA_R5_error_t getOperator(String *oper);
SARA_R5_error_t deregisterOperator(void);
// SMS -- Short Messages Service
SARA_R5_error_t setSMSMessageFormat(SARA_R5_message_format_t textMode = SARA_R5_MESSAGE_FORMAT_TEXT);
SARA_R5_error_t sendSMS(String number, String message);
SARA_R5_error_t getPreferredMessageStorage(int *used, int *total, String memory = "ME");
SARA_R5_error_t readSMSmessage(int location, String *unread, String *from, String *dateTime, String *message);
SARA_R5_error_t deleteSMSmessage(int location, int deleteFlag = 0); // Default to deleting the single message at the specified location
SARA_R5_error_t deleteReadSMSmessages(void) { return (deleteSMSmessage( 1, 1 )); }; // Delete all the read messages from preferred storage
SARA_R5_error_t deleteReadSentSMSmessages(void) { return (deleteSMSmessage( 1, 2 )); }; // Delete the read and sent messages from preferred storage
SARA_R5_error_t deleteReadSentUnsentSMSmessages(void) { return (deleteSMSmessage( 1, 3 )); }; // Delete the read, sent and unsent messages from preferred storage
SARA_R5_error_t deleteAllSMSmessages(void) { return (deleteSMSmessage( 1, 4 )); }; // Delete the read, sent, unsent and unread messages from preferred storage
// V24 Control and V25ter (UART interface) AT commands
SARA_R5_error_t setBaud(unsigned long baud);
SARA_R5_error_t setFlowControl(SARA_R5_flow_control_t value = SARA_R5_ENABLE_FLOW_CONTROL);
// GPIO
// GPIO pin map
typedef enum
{
GPIO1 = 16,
GPIO2 = 23,
GPIO3 = 24,
GPIO4 = 25,
GPIO5 = 42,
GPIO6 = 19
} SARA_R5_gpio_t;
// GPIO pin modes
typedef enum
{
GPIO_MODE_INVALID = -1,
GPIO_OUTPUT = 0,
GPIO_INPUT,
NETWORK_STATUS,
GNSS_SUPPLY_ENABLE,
GNSS_DATA_READY,
GNSS_RTC_SHARING,
JAMMING_DETECTION,
SIM_CARD_DETECTION,
HEADSET_DETECTION,
GSM_TX_BURST_INDICATION,
MODULE_STATUS_INDICATION,
MODULE_OPERATING_MODE_INDICATION,
I2S_DIGITAL_AUDIO_INTERFACE,
SPI_SERIAL_INTERFACE,
MASTER_CLOCK_GENRATION,
UART_INTERFACE,
WIFI_ENABLE,
RING_INDICATION = 18,
LAST_GASP_ENABLE,
EXTERNAL_GNSS_ANTENNA,
TIME_PULSE_GNSS,
TIME_PULSE_OUTPUT,
TIMESTAMP,
FAST_POWER_OFF,
LWM2M_PULSE,
HARDWARE_FLOW_CONTROL,
ANTENNA_TUNING,
EXT_GNSS_TIME_PULSE,
EXT_GNSS_TIMESTAMP,
DTR_MODE,
KHZ_32768_OUT = 32,
PAD_DISABLED = 255
} SARA_R5_gpio_mode_t;
SARA_R5_error_t setGpioMode(SARA_R5_gpio_t gpio, SARA_R5_gpio_mode_t mode, int value = 0);
SARA_R5_gpio_mode_t getGpioMode(SARA_R5_gpio_t gpio);
// IP Transport Layer
int socketOpen(SARA_R5_socket_protocol_t protocol, unsigned int localPort = 0); // Open a socket. Returns the socket number.
SARA_R5_error_t socketClose(int socket, unsigned long timeout = SARA_R5_2_MIN_TIMEOUT); // Close the socket
SARA_R5_error_t socketConnect(int socket, const char *address, unsigned int port); // TCP - connect to a remote IP Address using the specified port. Not required for UDP sockets.
SARA_R5_error_t socketConnect(int socket, IPAddress address, unsigned int port);
// Write data to the specified socket. Works with binary data - but you must specify the data length when using the const char * version
// Works with both TCP and UDP sockets - but socketWriteUDP is preferred for UDP and doesn't require socketOpen to be called first
SARA_R5_error_t socketWrite(int socket, const char *str, int len = -1);
SARA_R5_error_t socketWrite(int socket, String str); // OK for binary data
// Write UDP data to the specified IP Address and port.
// Works with binary data - but you must specify the data length when using the const char * versions
// If you let len default to -1, strlen is used to calculate the data length - and will be incorrect for binary data
SARA_R5_error_t socketWriteUDP(int socket, const char *address, int port, const char *str, int len = -1);
SARA_R5_error_t socketWriteUDP(int socket, IPAddress address, int port, const char *str, int len = -1);
SARA_R5_error_t socketWriteUDP(int socket, String address, int port, String str);
// Read data from the specified socket
// Call socketReadAvailable first to determine how much data is available - or use the callbacks (triggered by URC's)
// Works for both TCP and UDP - but socketReadUDP is preferred for UDP as it records the remote IP Address and port
// bytesRead - if provided - will be updated with the number of bytes actually read. This could be less than length!
SARA_R5_error_t socketRead(int socket, int length, char *readDest, int *bytesRead = nullptr);
// Return the number of bytes available (waiting to be read) on the chosen socket
// Uses +USORD. Valid for both TCP and UDP sockets - but socketReadAvailableUDP is preferred for UDP
SARA_R5_error_t socketReadAvailable(int socket, int *length);
// Read data from the specified UDP port
// Call socketReadAvailableUDP first to determine how much data is available - or use the callbacks (triggered by URC's)
// The remote IP Address and port are returned via *remoteIPAddress and *remotePort (if not nullptr)
// bytesRead - if provided - will be updated with the number of bytes actually read. This could be less than length!
SARA_R5_error_t socketReadUDP(int socket, int length, char *readDest, IPAddress *remoteIPAddress = nullptr, int *remotePort = nullptr, int *bytesRead = nullptr);
// Return the number of bytes available (waiting to be read) on the chosen UDP socket
SARA_R5_error_t socketReadAvailableUDP(int socket, int *length);
// Start listening for a connection on the specified port. The connection is reported via the socket listen callback
SARA_R5_error_t socketListen(int socket, unsigned int port);
// Place the socket into direct link mode - making it easy to transfer binary data. Wait two seconds and then send +++ to exit the link.
SARA_R5_error_t socketDirectLinkMode(int socket);
// Configure when direct link data is sent
SARA_R5_error_t socketDirectLinkTimeTrigger(int socket, unsigned long timerTrigger);
SARA_R5_error_t socketDirectLinkDataLengthTrigger(int socket, int dataLengthTrigger);
SARA_R5_error_t socketDirectLinkCharacterTrigger(int socket, int characterTrigger);
SARA_R5_error_t socketDirectLinkCongestionTimer(int socket, unsigned long congestionTimer);
// Use +USOCTL (Socket control) to query the socket parameters
SARA_R5_error_t querySocketType(int socket, SARA_R5_socket_protocol_t *protocol);
SARA_R5_error_t querySocketLastError(int socket, int *error);
SARA_R5_error_t querySocketTotalBytesSent(int socket, uint32_t *total);
SARA_R5_error_t querySocketTotalBytesReceived(int socket, uint32_t *total);
SARA_R5_error_t querySocketRemoteIPAddress(int socket, IPAddress *address, int *port);
SARA_R5_error_t querySocketStatusTCP(int socket, SARA_R5_tcp_socket_status_t *status);
SARA_R5_error_t querySocketOutUnackData(int socket, uint32_t *total);
// enable / disable socket securoty
SARA_R5_error_t socketSetSecure(int profile, bool secure, int secprofile = -1);
// Return the most recent socket error
int socketGetLastError();
// Return the remote IP Address from the most recent socket listen indication (socket connection)
// Use the socket listen callback to get the full address and port information
IPAddress lastRemoteIP(void);
// Ping
SARA_R5_error_t ping(String remote_host, int retry = 4, int p_size = 32, unsigned long timeout = 5000, int ttl = 32);
// HTTP
SARA_R5_error_t resetHTTPprofile(int profile); // Reset the HTTP profile. Note: The configured HTTP profile parameters are not saved in the non volatile memory.
SARA_R5_error_t setHTTPserverIPaddress(int profile, IPAddress address); // Default: empty string
SARA_R5_error_t setHTTPserverName(int profile, String server); // Default: empty string
SARA_R5_error_t setHTTPusername(int profile, String username); // Default: empty string
SARA_R5_error_t setHTTPpassword(int profile, String password); // Default: empty string
SARA_R5_error_t setHTTPauthentication(int profile, bool authenticate); // Default: no authentication
SARA_R5_error_t setHTTPserverPort(int profile, int port); // Default: 80
SARA_R5_error_t setHTTPcustomHeader(int profile, String header); // Default: format 0:Content-Type:application/json"
SARA_R5_error_t setHTTPsecure(int profile, bool secure, int secprofile = -1); // Default: disabled (HTTP on port 80). Set to true for HTTPS on port 443
// TO DO: Add custom request headers
SARA_R5_error_t getHTTPprotocolError(int profile, int *error_class, int *error_code); // Read the most recent HTTP protocol error for this profile
SARA_R5_error_t sendHTTPGET(int profile, String path, String responseFilename);
SARA_R5_error_t sendHTTPPOSTdata(int profile, String path, String responseFilename, String data, SARA_R5_http_content_types_t httpContentType);
SARA_R5_error_t sendHTTPPOSTfile(int profile, String path, String responseFilename, String requestFile, SARA_R5_http_content_types_t httpContentType);
SARA_R5_error_t nvMQTT(SARA_R5_mqtt_nv_parameter_t parameter);
SARA_R5_error_t setMQTTclientId(const String& clientId);
SARA_R5_error_t setMQTTserver(const String& serverName, int port);
SARA_R5_error_t setMQTTcredentials(const String& userName, const String& pwd);
SARA_R5_error_t setMQTTsecure(bool secure, int secprofile = -1);
SARA_R5_error_t connectMQTT(void);
SARA_R5_error_t disconnectMQTT(void);
SARA_R5_error_t subscribeMQTTtopic(int max_Qos, const String& topic);
SARA_R5_error_t unsubscribeMQTTtopic(const String& topic);
SARA_R5_error_t readMQTT(int* pQos, String* pTopic, uint8_t *readDest, int readLength, int *bytesRead);
SARA_R5_error_t mqttPublishTextMsg(const String& topic, const char * const msg, uint8_t qos = 0, bool retain = false);
SARA_R5_error_t mqttPublishBinaryMsg(const String& topic, const char * const msg, size_t msg_len, uint8_t qos = 0, bool retain = false);
SARA_R5_error_t mqttPublishFromFile(const String& topic, const String& filename, uint8_t qos = 0, bool retain = false);
SARA_R5_error_t getMQTTprotocolError(int *error_code, int *error_code2);
// FTP
SARA_R5_error_t setFTPserver(const String& serverName);
SARA_R5_error_t setFTPtimeouts(const unsigned int timeout, const unsigned int cmd_linger, const unsigned int data_linger);
SARA_R5_error_t setFTPcredentials(const String& userName, const String& pwd);
SARA_R5_error_t connectFTP(void);
SARA_R5_error_t disconnectFTP(void);
SARA_R5_error_t ftpGetFile(const String& filename);
SARA_R5_error_t getFTPprotocolError(int *error_code, int *error_code2);
// Configure security profiles
SARA_R5_error_t resetSecurityProfile(int secprofile);
SARA_R5_error_t configSecurityProfileString(int secprofile, SARA_R5_sec_profile_parameter_t parameter, String value);
SARA_R5_error_t configSecurityProfile(int secprofile, SARA_R5_sec_profile_parameter_t parameter, int value);
SARA_R5_error_t setSecurityManager(SARA_R5_sec_manager_opcode_t opcode, SARA_R5_sec_manager_parameter_t parameter, String name, String data);
// Packet Switched Data
// Configure the PDP using +UPSD. See SARA_R5_pdp_configuration_parameter_t for the list of parameters: protocol, APN, username, DNS, etc.
SARA_R5_error_t setPDPconfiguration(int profile, SARA_R5_pdp_configuration_parameter_t parameter, int value); // Set parameters in the chosen PSD profile
SARA_R5_error_t setPDPconfiguration(int profile, SARA_R5_pdp_configuration_parameter_t parameter, SARA_R5_pdp_protocol_type_t value); // Set parameters in the chosen PSD profile
SARA_R5_error_t setPDPconfiguration(int profile, SARA_R5_pdp_configuration_parameter_t parameter, String value); // Set parameters in the chosen PSD profile
SARA_R5_error_t setPDPconfiguration(int profile, SARA_R5_pdp_configuration_parameter_t parameter, IPAddress value); // Set parameters in the chosen PSD profile
SARA_R5_error_t performPDPaction(int profile, SARA_R5_pdp_actions_t action); // Performs the requested action for the specified PSD profile: reset, store, load, activate, deactivate
SARA_R5_error_t activatePDPcontext(bool status, int cid = -1); // Activates or deactivates the specified PDP context. Default to all (cid = -1)
SARA_R5_error_t getNetworkAssignedIPAddress(int profile, IPAddress *address); // Get the dynamic IP address assigned during PDP context activation
// GPS
typedef enum
{
GNSS_SYSTEM_GPS = 1,
GNSS_SYSTEM_SBAS = 2,
GNSS_SYSTEM_GALILEO = 4,
GNSS_SYSTEM_BEIDOU = 8,
GNSS_SYSTEM_IMES = 16,
GNSS_SYSTEM_QZSS = 32,
GNSS_SYSTEM_GLONASS = 64
} gnss_system_t;
typedef enum
{
GNSS_AIDING_MODE_NONE = 0,
GNSS_AIDING_MODE_AUTOMATIC = 1,
GNSS_AIDING_MODE_ASSISTNOW_OFFLINE = 2,
GNSS_AIDING_MODE_ASSISTNOW_ONLINE = 4,
GNSS_AIDING_MODE_ASSISTNOW_AUTONOMOUS = 8
} gnss_aiding_mode_t;
bool isGPSon(void);
SARA_R5_error_t gpsPower(bool enable = true,
gnss_system_t gnss_sys = GNSS_SYSTEM_GPS,
gnss_aiding_mode_t gnss_aiding = GNSS_AIDING_MODE_AUTOMATIC);
//SARA_R5_error_t gpsEnableClock(bool enable = true);
//SARA_R5_error_t gpsGetClock(struct ClockData *clock);
//SARA_R5_error_t gpsEnableFix(bool enable = true);
//SARA_R5_error_t gpsGetFix(float *lat, float *lon, unsigned int *alt, uint8_t *quality, uint8_t *sat);
//SARA_R5_error_t gpsGetFix(struct PositionData *pos);
//SARA_R5_error_t gpsEnablePos(bool enable = true);
//SARA_R5_error_t gpsGetPos(struct PositionData *pos);
//SARA_R5_error_t gpsEnableSat(bool enable = true);
//SARA_R5_error_t gpsGetSat(uint8_t *sats);
SARA_R5_error_t gpsEnableRmc(bool enable = true); // Enable GPRMC messages