@@ -37,6 +37,8 @@ SARA_R5::SARA_R5(int powerPin, int resetPin, uint8_t maxInitTries)
37
37
_pingRequestCallback = NULL ;
38
38
_httpCommandRequestCallback = NULL ;
39
39
_mqttCommandRequestCallback = NULL ;
40
+ _registrationCallback = NULL ;
41
+ _epsRegistrationCallback = NULL ;
40
42
_debugAtPort = NULL ;
41
43
_debugPort = NULL ;
42
44
_printDebug = false ;
@@ -566,6 +568,41 @@ bool SARA_R5::processURCEvent(const char *event)
566
568
return true ;
567
569
}
568
570
}
571
+ { // URC: +A
572
+ int status = 0 ;
573
+ unsigned int lac = 0 , ci = 0 , Act = 0 ;
574
+ int scanNum = sscanf (event, " +CREG: %d,\" %4x\" ,\" %4x\" ,%d" , &status, &lac, &ci, &Act);
575
+ if (scanNum == 4 )
576
+ {
577
+ if (_printDebug == true )
578
+ _debugPort->println (F (" processReadEvent: CREG" ));
579
+
580
+ if (_registrationCallback != NULL )
581
+ {
582
+ _registrationCallback ((SARA_R5_registration_status_t)status, lac, ci, Act);
583
+ }
584
+
585
+ return true ;
586
+ }
587
+ }
588
+ { // URC: +CEREG
589
+ int status = 0 ;
590
+ unsigned int tac = 0 , ci = 0 , Act = 0 ;
591
+ int scanNum = sscanf (event, " +CEREG: %d,\" %4x\" ,\" %4x\" ,%d" , &status, &tac, &ci, &Act);
592
+ if (scanNum == 4 )
593
+ {
594
+ if (_printDebug == true )
595
+ _debugPort->println (F (" processReadEvent: CEREG" ));
596
+
597
+ if (_epsRegistrationCallback != NULL )
598
+ {
599
+ _epsRegistrationCallback ((SARA_R5_registration_status_t)status, tac, ci, Act);
600
+ }
601
+
602
+ return true ;
603
+ }
604
+ }
605
+
569
606
return false ;
570
607
}
571
608
@@ -670,6 +707,33 @@ void SARA_R5::setMQTTCommandCallback(void (*mqttCommandRequestCallback)(int comm
670
707
_mqttCommandRequestCallback = mqttCommandRequestCallback;
671
708
}
672
709
710
+ SARA_R5_error_t SARA_R5::setRegistrationCallback (void (*registrationCallback)(SARA_R5_registration_status_t status, unsigned int lac, unsigned int ci, int Act))
711
+ {
712
+ _registrationCallback = registrationCallback;
713
+
714
+ char *command = sara_r5_calloc_char (strlen (SARA_R5_REGISTRATION_STATUS) + 3 );
715
+ if (command == NULL )
716
+ return SARA_R5_ERROR_OUT_OF_MEMORY;
717
+ sprintf (command, " %s=%d" , SARA_R5_REGISTRATION_STATUS, 2 /* enable URC with location*/ );
718
+ SARA_R5_error_t err = sendCommandWithResponse (command, SARA_R5_RESPONSE_OK_OR_ERROR,
719
+ NULL , SARA_R5_STANDARD_RESPONSE_TIMEOUT);
720
+ free (command);
721
+ return err;
722
+ }
723
+
724
+ SARA_R5_error_t SARA_R5::setEpsRegistrationCallback (void (*registrationCallback)(SARA_R5_registration_status_t status, unsigned int tac, unsigned int ci, int Act))
725
+ {
726
+ _epsRegistrationCallback = registrationCallback;
727
+
728
+ char *command = sara_r5_calloc_char (strlen (SARA_R5_EPSREGISTRATION_STATUS) + 3 );
729
+ if (command == NULL )
730
+ return SARA_R5_ERROR_OUT_OF_MEMORY;
731
+ sprintf (command, " %s=%d" , SARA_R5_EPSREGISTRATION_STATUS, 2 /* enable URC with location*/ );
732
+ SARA_R5_error_t err = sendCommandWithResponse (command, SARA_R5_RESPONSE_OK_OR_ERROR,
733
+ NULL , SARA_R5_STANDARD_RESPONSE_TIMEOUT);
734
+ free (command);
735
+ return err;
736
+ }
673
737
674
738
size_t SARA_R5::write (uint8_t c)
675
739
{
@@ -1353,17 +1417,17 @@ int8_t SARA_R5::rssi(void)
1353
1417
return rssi;
1354
1418
}
1355
1419
1356
- SARA_R5_registration_status_t SARA_R5::registration (void )
1420
+ SARA_R5_registration_status_t SARA_R5::registration (bool eps )
1357
1421
{
1358
1422
char *command;
1359
1423
char *response;
1360
1424
SARA_R5_error_t err;
1361
1425
int status;
1362
-
1363
- command = sara_r5_calloc_char (strlen (SARA_R5_REGISTRATION_STATUS ) + 2 );
1426
+ const char * tag = eps ? SARA_R5_EPSREGISTRATION_STATUS : SARA_R5_REGISTRATION_STATUS;
1427
+ command = sara_r5_calloc_char (strlen (tag ) + 3 );
1364
1428
if (command == NULL )
1365
1429
return SARA_R5_REGISTRATION_INVALID;
1366
- sprintf (command, " %s?" , SARA_R5_REGISTRATION_STATUS );
1430
+ sprintf (command, " %s?" , tag );
1367
1431
1368
1432
response = sara_r5_calloc_char (minimumResponseAllocation);
1369
1433
if (response == NULL )
@@ -1381,11 +1445,14 @@ SARA_R5_registration_status_t SARA_R5::registration(void)
1381
1445
free (response);
1382
1446
return SARA_R5_REGISTRATION_INVALID;
1383
1447
}
1384
-
1448
+
1385
1449
int scanned = 0 ;
1386
- char *searchPtr = strstr (response, " +CREG: " );
1387
- if (searchPtr != NULL )
1388
- scanned = sscanf (searchPtr, " +CREG: %*d,%d" , &status);
1450
+ const char *startTag = eps ? " +CEREG: " : " +CREG: " ;
1451
+ char *searchPtr = strstr (response, startTag);
1452
+ if (searchPtr != NULL ) {
1453
+ const char *format = eps ? " +CEREG: %*d,%d" : " +CREG: %*d,%d" ;
1454
+ scanned = sscanf (searchPtr, format, &status);
1455
+ }
1389
1456
if (scanned != 1 )
1390
1457
status = SARA_R5_REGISTRATION_INVALID;
1391
1458
0 commit comments