Skip to content

Commit 94fb048

Browse files
authored
Merge pull request sparkfun#20 from sparkfun/release_candidate
v1.1.2
2 parents dbd8a45 + 746d555 commit 94fb048

File tree

4 files changed

+183
-78
lines changed

4 files changed

+183
-78
lines changed

.github/workflows/compile-sketch.yml

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
name: Compile Sketch
2+
3+
on:
4+
# - push
5+
- pull_request
6+
7+
8+
jobs:
9+
compile-sketch:
10+
runs-on: ubuntu-latest
11+
12+
strategy:
13+
fail-fast: false
14+
15+
matrix:
16+
board:
17+
# ATmega2560
18+
# https://github.com/arduino/ArduinoCore-avr/blob/master/boards.txt
19+
- fqbn: arduino:avr:mega
20+
platforms: |
21+
- name: arduino:avr
22+
source-url: https://downloads.arduino.cc/packages/package_index.json
23+
24+
# ESP32
25+
# https://github.com/espressif/arduino-esp32/blob/master/boards.txt
26+
- fqbn: esp32:esp32:esp32
27+
platforms: |
28+
- name: esp32:esp32
29+
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
30+
31+
# ESP32-S2
32+
# https://github.com/espressif/arduino-esp32/blob/master/boards.txt
33+
- fqbn: esp32:esp32:esp32s2
34+
platforms: |
35+
- name: esp32:esp32
36+
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
37+
38+
# ESP32-C3
39+
# https://github.com/espressif/arduino-esp32/blob/master/boards.txt
40+
- fqbn: esp32:esp32:esp32c3
41+
platforms: |
42+
- name: esp32:esp32
43+
source-url: https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
44+
45+
# Artemis / Apollo3
46+
# https://github.com/sparkfun/Arduino_Apollo3/blob/main/boards.txt
47+
- fqbn: SparkFun:apollo3:sfe_artemis_atp
48+
platforms: |
49+
- name: SparkFun:apollo3
50+
source-url: https://raw.githubusercontent.com/sparkfun/Arduino_Apollo3/master/package_sparkfun_apollo3_index.json
51+
52+
# ESP8266
53+
# https://github.com/esp8266/Arduino/blob/master/boards.txt
54+
- fqbn: esp8266:esp8266:thingdev
55+
platforms: |
56+
- name: esp8266:esp8266
57+
source-url: https://arduino.esp8266.com/stable/package_esp8266com_index.json
58+
59+
# SAMD21
60+
# https://github.com/arduino/ArduinoCore-samd/blob/master/boards.txt
61+
- fqbn: arduino:samd:mkr1000
62+
platforms: |
63+
- name: arduino:samd
64+
# source-url: https://downloads.arduino.cc/packages/package_index.json
65+
66+
# Nano BLE 33 / nRF52840
67+
# https://github.com/arduino/ArduinoCore-mbed/blob/master/boards.txt
68+
- fqbn: arduino:mbed:nano33ble
69+
platforms: |
70+
- name: arduino:mbed
71+
# source-url: https://downloads.arduino.cc/packages/package_index.json
72+
73+
# RP2040
74+
# https://github.com/arduino/ArduinoCore-mbed/blob/master/boards.txt
75+
- fqbn: rp2040:rp2040:sparkfun_promicrorp2040
76+
platforms: |
77+
- name: rp2040:rp2040
78+
source-url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json
79+
80+
# STM32
81+
# https://github.com/arduino/ArduinoCore-mbed/blob/master/boards.txt
82+
- fqbn: STMicroelectronics:stm32:GenF4
83+
platforms: |
84+
- name: STMicroelectronics:stm32
85+
source-url: https://github.com/stm32duino/BoardManagerFiles/raw/main/package_stmicroelectronics_index.json
86+
87+
steps:
88+
- name: Checkout
89+
uses: actions/checkout@v2
90+
91+
- name: Branch name
92+
run: echo running on branch ${GITHUB_REF##*/}
93+
94+
- name: Compile Sketch
95+
uses: arduino/compile-sketches@v1
96+
with:
97+
platforms: ${{ matrix.board.platforms }}
98+
fqbn: ${{ matrix.board.fqbn }}
99+
libraries: |
100+
- source-path: ./
101+
sketch-paths: |
102+
- examples/SARA-R5_Example10_SocketPingPong
103+
enable-warnings-report: true
104+
enable-deltas-report: true
105+
# verbose: true
106+
107+
# outputs:
108+
# report-artifact-name: ${{ steps.report-artifact-name.outputs.report-artifact-name }}
109+

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SparkFun u-blox SARA-R5 Arduino Library
2-
version=1.1.1
2+
version=1.1.2
33
author=SparkFun Electronics <[email protected]>
44
maintainer=SparkFun Electronics <sparkfun.com>
55
sentence=Library for the u-blox SARA-R5 LTE-M / NB-IoT modules with secure cloud<br/><br/>

src/SparkFun_u-blox_SARA-R5_Arduino_Library.cpp

Lines changed: 67 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,15 @@ bool SARA_R5::begin(HardwareSerial &hardSerial, unsigned long baud)
174174

175175
//Calling this function with nothing sets the debug port to Serial
176176
//You can also call it with other streams like Serial1, SerialUSB, etc.
177-
void SARA_R5::enableDebugging(Stream &debugPort)
177+
void SARA_R5::enableDebugging(Print &debugPort)
178178
{
179179
_debugPort = &debugPort;
180180
_printDebug = true;
181181
}
182182

183183
//Calling this function with nothing sets the debug port to Serial
184184
//You can also call it with other streams like Serial1, SerialUSB, etc.
185-
void SARA_R5::enableAtDebugging(Stream &debugPort)
185+
void SARA_R5::enableAtDebugging(Print &debugPort)
186186
{
187187
_debugAtPort = &debugPort;
188188
_printAtDebug = true;
@@ -246,6 +246,8 @@ bool SARA_R5::bufferedPoll(void)
246246
c = '0'; // Convert any NULLs to ASCII Zeros
247247
_saraRXBuffer[avail++] = c;
248248
timeIn = millis();
249+
} else {
250+
yield();
249251
}
250252
}
251253

@@ -546,10 +548,15 @@ bool SARA_R5::processURCEvent(const char *event)
546548
{ // URC: +UUMQTTC (HTTP Command Result)
547549
int command, result;
548550
int scanNum;
549-
551+
int qos = -1;
552+
String topic;
550553
scanNum = sscanf(event, "+UUMQTTC: %d,%d", &command, &result);
551-
552-
if (scanNum == 2)
554+
if ((scanNum == 2) && (command == SARA_R5_MQTT_COMMAND_SUBSCRIBE)) {
555+
char topicC[100] = "";
556+
scanNum = sscanf(event, "+UUMQTTC: %*d,%*d,%d,\"%[^\"]\"", &qos, topicC);
557+
topic = topicC;
558+
}
559+
if ((scanNum == 2) || (scanNum == 4))
553560
{
554561
if (_printDebug == true)
555562
_debugPort->println(F("processReadEvent: MQTT command result"));
@@ -673,6 +680,8 @@ bool SARA_R5::poll(void)
673680
{
674681
c = readChar();
675682
_saraRXBuffer[avail++] = c;
683+
} else {
684+
yield();
676685
}
677686
}
678687

@@ -1615,14 +1624,12 @@ SARA_R5_error_t SARA_R5::setAPN(String apn, uint8_t cid, SARA_R5_pdp_type pdpTyp
16151624
}
16161625

16171626
// Return the Access Point Name and IP address for the chosen context identifier
1618-
SARA_R5_error_t SARA_R5::getAPN(int cid, String *apn, IPAddress *ip)
1627+
SARA_R5_error_t SARA_R5::getAPN(int cid, String *apn, IPAddress *ip, SARA_R5_pdp_type* pdpType)
16191628
{
16201629
SARA_R5_error_t err;
16211630
char *command;
16221631
char *response;
1623-
int ipOctets[4];
1624-
int rcid = -1;
1625-
1632+
16261633
if (cid > SARA_R5_NUM_PDP_CONTEXT_IDENTIFIERS)
16271634
return SARA_R5_ERROR_ERROR;
16281635

@@ -1646,72 +1653,47 @@ SARA_R5_error_t SARA_R5::getAPN(int cid, String *apn, IPAddress *ip)
16461653
// Example:
16471654
// +CGDCONT: 0,"IP","payandgo.o2.co.uk","0.0.0.0",0,0,0,0,0,0,0,0,0,0
16481655
// +CGDCONT: 1,"IP","payandgo.o2.co.uk.mnc010.mcc234.gprs","10.160.182.234",0,0,0,2,0,0,0,0,0,0
1649-
1656+
int rcid = -1;
16501657
char *searchPtr = response;
16511658

16521659
bool keepGoing = true;
16531660
while (keepGoing == true)
16541661
{
1655-
int apnLen = 0;
16561662
int scanned = 0;
16571663
// Find the first/next occurrence of +CGDCONT:
16581664
searchPtr = strstr(searchPtr, "+CGDCONT: ");
16591665
if (searchPtr != NULL)
16601666
{
1667+
char strPdpType[10];
1668+
char strApn[128];
1669+
int ipOct[4];
1670+
16611671
searchPtr += strlen("+CGDCONT: "); // Point to the cid
1662-
rcid = (*searchPtr) - '0'; // Get the first/only digit of cid
1663-
searchPtr++;
1664-
if (*searchPtr != ',') // Get the second digit of cid - if there is one
1665-
{
1666-
rcid *= 10;
1667-
rcid += (*searchPtr) - '0';
1668-
}
1669-
if (_printDebug == true)
1670-
{
1671-
_debugPort->print(F("getAPN: cid is "));
1672-
_debugPort->println(rcid);
1673-
}
1674-
if (rcid == cid) // If we have a match
1675-
{
1676-
// Search to the third double-quote
1677-
for (int i = 0; i < 3; i++)
1672+
scanned = sscanf(searchPtr, "%d,\"%[^\"]\",\"%[^\"]\",\"%d.%d.%d.%d",
1673+
&rcid, strPdpType, strApn,
1674+
&ipOct[0], &ipOct[1], &ipOct[2], &ipOct[3]);
1675+
if ((scanned == 7) && (rcid == cid)) {
1676+
if (apn) *apn = strApn;
1677+
for (int o = 0; ip && (o < 4); o++)
16781678
{
1679-
searchPtr = strchr(++searchPtr, '\"');
1679+
(*ip)[o] = (uint8_t)ipOct[o];
16801680
}
1681-
if (searchPtr != NULL)
1682-
{
1683-
// Fill in the APN:
1684-
//searchPtr = strchr(searchPtr, '\"'); // Move to first quote
1685-
while ((*(++searchPtr) != '\"') && (*searchPtr != '\0'))
1686-
{
1687-
apn->concat(*(searchPtr));
1688-
apnLen++;
1689-
}
1690-
// Now get the IP:
1691-
if (searchPtr != NULL)
1692-
{
1693-
scanned = sscanf(searchPtr, "\",\"%d.%d.%d.%d\"",
1694-
&ipOctets[0], &ipOctets[1], &ipOctets[2], &ipOctets[3]);
1695-
if (scanned == 4)
1696-
{
1697-
for (int octet = 0; octet < 4; octet++)
1698-
{
1699-
(*ip)[octet] = (uint8_t)ipOctets[octet];
1700-
}
1701-
}
1702-
}
1681+
if (pdpType) {
1682+
*pdpType = (0 == strcmp(strPdpType, "IPV4V6")) ? PDP_TYPE_IPV4V6 :
1683+
(0 == strcmp(strPdpType, "IPV6")) ? PDP_TYPE_IPV6 :
1684+
(0 == strcmp(strPdpType, "IP")) ? PDP_TYPE_IP :
1685+
PDP_TYPE_INVALID;
17031686
}
1704-
}
1705-
else // We don't have a match so let's clear the APN and IP address
1706-
{
1707-
*apn = "";
1708-
*ip = {0, 0, 0, 0};
1687+
keepGoing = false;
17091688
}
17101689
}
1711-
if ((rcid == cid) || (searchPtr == NULL) || (*searchPtr == '\0')) // Stop searching
1690+
else // We don't have a match so let's clear the APN and IP address
17121691
{
1713-
keepGoing = false;
1714-
}
1692+
if (apn) *apn = "";
1693+
if (pdpType) *pdpType = PDP_TYPE_INVALID;
1694+
if (ip) *ip = {0, 0, 0, 0};
1695+
keepGoing = false;
1696+
}
17151697
}
17161698
}
17171699
else
@@ -1752,7 +1734,8 @@ SARA_R5_error_t SARA_R5::getSimStatus(String* code)
17521734
scanned = sscanf(searchPtr, "+CPIN: %s\r\n", c);
17531735
if (scanned == 1)
17541736
{
1755-
*code = c;
1737+
if(code)
1738+
*code = c;
17561739
}
17571740
else
17581741
err = SARA_R5_ERROR_UNEXPECTED_RESPONSE;
@@ -4076,7 +4059,7 @@ SARA_R5_error_t SARA_R5::subscribeMQTTtopic(int max_Qos, String topic)
40764059
{
40774060
SARA_R5_error_t err;
40784061
char *command;
4079-
command = sara_r5_calloc_char(strlen(SARA_R5_MQTT_COMMAND) + topic.length() + 16);
4062+
command = sara_r5_calloc_char(strlen(SARA_R5_MQTT_COMMAND) + 16 + topic.length());
40804063
if (command == NULL)
40814064
return SARA_R5_ERROR_OUT_OF_MEMORY;
40824065
sprintf(command, "%s=%d,%d,\"%s\"", SARA_R5_MQTT_COMMAND, SARA_R5_MQTT_COMMAND_SUBSCRIBE, max_Qos, topic.c_str());
@@ -4090,7 +4073,7 @@ SARA_R5_error_t SARA_R5::unsubscribeMQTTtopic(String topic)
40904073
{
40914074
SARA_R5_error_t err;
40924075
char *command;
4093-
command = sara_r5_calloc_char(strlen(SARA_R5_MQTT_COMMAND) + topic.length() + 16);
4076+
command = sara_r5_calloc_char(strlen(SARA_R5_MQTT_COMMAND) + 16 + topic.length());
40944077
if (command == NULL)
40954078
return SARA_R5_ERROR_OUT_OF_MEMORY;
40964079
sprintf(command, "%s=%d,\"%s\"", SARA_R5_MQTT_COMMAND, SARA_R5_MQTT_COMMAND_UNSUBSCRIBE, topic.c_str());
@@ -4099,8 +4082,8 @@ SARA_R5_error_t SARA_R5::unsubscribeMQTTtopic(String topic)
40994082
free(command);
41004083
return err;
41014084
}
4102-
4103-
SARA_R5_error_t SARA_R5::readMQTT(int* pQos, char* pTopic, uint8_t *readDest, int readLength, int *bytesRead)
4085+
4086+
SARA_R5_error_t SARA_R5::readMQTT(int* pQos, String* pTopic, uint8_t *readDest, int readLength, int *bytesRead)
41044087
{
41054088
char *command;
41064089
char *response;
@@ -4148,8 +4131,8 @@ SARA_R5_error_t SARA_R5::readMQTT(int* pQos, char* pTopic, uint8_t *readDest, in
41484131
// Extract the data
41494132
char *searchPtr = strstr(response, "+UMQTTC: 6");
41504133
if (searchPtr != NULL)
4151-
scanNum = sscanf(searchPtr, "+UMQTTC: 6,%d,%d,%d,\"%[^\"]\",%d\"", pQos, &total_length, &topic_length, pTopic, &data_length);
4152-
if (scanNum != 5)
4134+
scanNum = sscanf(searchPtr, "+UMQTTC: 6,%d,%d,%d,\"%*[^\"]\",%d,\"", pQos, &total_length, &topic_length, &data_length);
4135+
if (scanNum != 4)
41534136
{
41544137
if (_printDebug == true)
41554138
{
@@ -4160,13 +4143,17 @@ SARA_R5_error_t SARA_R5::readMQTT(int* pQos, char* pTopic, uint8_t *readDest, in
41604143
free(response);
41614144
return SARA_R5_ERROR_UNEXPECTED_RESPONSE;
41624145
}
4163-
41644146
searchPtr = strstr(searchPtr, "\"");
4165-
searchPtr = strstr(searchPtr+1, "\"");
4166-
searchPtr = strstr(searchPtr+1, "\"");
4167-
*bytesRead = (data_length > readLength) ? readLength : data_length;
4168-
memcpy(readDest, searchPtr, *bytesRead);
4169-
4147+
if (pTopic) {
4148+
searchPtr[topic_length+1] = '\0'; // zero terminate
4149+
*pTopic = searchPtr+1;
4150+
searchPtr[topic_length+1] = '\"'; // restore
4151+
}
4152+
searchPtr = strstr(searchPtr + topic_length + 2, "\"");
4153+
if (readDest) {
4154+
*bytesRead = (data_length > readLength) ? readLength : data_length;
4155+
memcpy(readDest, searchPtr+1, *bytesRead);
4156+
}
41704157
free(command);
41714158
free(response);
41724159

@@ -5495,6 +5482,8 @@ SARA_R5_error_t SARA_R5::waitForResponse(const char *expectedResponse, const cha
54955482
else
54965483
_saraResponseBacklog[_saraResponseBacklogLength++] = c;
54975484
}
5485+
} else {
5486+
yield();
54985487
}
54995488
}
55005489

@@ -5616,6 +5605,8 @@ SARA_R5_error_t SARA_R5::sendCommandWithResponse(
56165605
else
56175606
_saraResponseBacklog[_saraResponseBacklogLength++] = c;
56185607
}
5608+
} else {
5609+
yield();
56195610
}
56205611
}
56215612

@@ -5681,6 +5672,8 @@ void SARA_R5::sendCommand(const char *command, bool at)
56815672
c = '0';
56825673
_saraResponseBacklog[_saraResponseBacklogLength++] = c;
56835674
timeIn = millis();
5675+
} else {
5676+
yield();
56845677
}
56855678
}
56865679
}
@@ -6068,6 +6061,9 @@ void SARA_R5::pruneBacklog()
60686061
|| (strstr(event, "+UUSIMSTAT:") != NULL)
60696062
|| (strstr(event, "+UUPSDA:") != NULL)
60706063
|| (strstr(event, "+UUPING:") != NULL)
6064+
|| (strstr(event, "+UUMQTTC:") != NULL)
6065+
|| (strstr(event, "+UUCREG:") != NULL)
6066+
|| (strstr(event, "+UUCEREG:") != NULL)
60716067
|| (strstr(event, "+UUHTTPCR:") != NULL))
60726068
{
60736069
strcat(_pruneBuffer, event); // The URCs are all readable text so using strcat is OK

0 commit comments

Comments
 (0)