Skip to content

Commit 597bc6f

Browse files
authored
Merge pull request #6 from arduino-libraries/header-issue-fix
Fix issue about umbrella header
2 parents b4058f7 + 33cf496 commit 597bc6f

File tree

10 files changed

+80
-56
lines changed

10 files changed

+80
-56
lines changed

Diff for: .DS_Store

-6 KB
Binary file not shown.

Diff for: .github/workflows/check-arduino.yml

-28
This file was deleted.

Diff for: .github/workflows/compile-examples.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ env:
2626
- examples/HTTPClient
2727
- examples/HTTPSClient
2828
- examples/TimeAndLocation
29-
- examples/SMSReceive
29+
- examples/ReceiveSMS
30+
- examples/SendSMS
3031
SKETCHES_REPORTS_PATH: sketches-reports
3132
SKETCHES_REPORTS_ARTIFACT_NAME: sketches-reports
3233

@@ -65,9 +66,10 @@ jobs:
6566
libraries: |
6667
# Install the library from the local path.
6768
- source-path: ./
68-
- name: Arduino_USBHostMbed5
69-
- name: Arduino_POSIXStorage
70-
- name: ArduinoRS485
69+
- name: ArduinoBearSSL
70+
- name: StreamDebugger
71+
- name: TinyGSM
72+
- name: ArduinoHttpClient
7173
# Additional library dependencies can be listed here.
7274
# See: https://github.com/arduino/compile-sketches#libraries
7375
sketch-paths: |

Diff for: README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
# Arduino Cellular
22

3+
[![Arduino Lint](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/check-arduino.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/check-arduino.yml) [![Compile Examples](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/compile-examples.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/compile-examples.yml) [![Spell Check](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/spell-check.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/spell-check.yml) [![Sync Labels](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/sync-labels.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/sync-labels.yml)[Render Documentation](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/render-documentation.yml)
4+
35

46
This library provides a toolkit for interacting with the official Arduino 4G Modules. It allows you to connect to the internet, send and receive SMS messages, and get location from the cellular network or GPS.
57

68
## Examples
79
* [examples/HTTPClient]() - Example of using this library together with [HttpClient]() to connect to a web server
810
* [examples/HTTPClient]() - Example of using this library together with [HttpClient]() that uses [BearSSL]() under the hood to create a secure connection to a web server
9-
* [examples/SMSReceive]() - Example for the SMS sending and receiving functionality
10-
* [examples/TimeAndLocation]() - Use GPS, or Cellular to aquire the location and time of the device.
11+
* [examples/ReceiveSMS]() - Example for the SMS sending and receiving functionality
12+
* [examples/TimeAndLocation]() - Use GPS, or Cellular to acquire the location and time of the device.
1113
* [examples/ModemTerminal]() - A handy example for debugging and Testing AT commands
1214

1315
## Features

Diff for: docs/readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ These features enable precise tracking of device locations and ensure synchroniz
123123

124124
GPS Location is ideal for applications requiring high-precision location data, such as asset tracking or outdoor navigation solutions. This functionality relies on the Global Version of the modem, which is equipped with GPS capabilities.
125125

126-
To enable GPS Location you will need to call `enableGPS(bool assisted)`. Assisted GPS or A-GPS is an enchancement of GPS that uses the cellular network to get the location, it performs that much quicker than without assistence but depends on Cellular network coverage.
126+
To enable GPS Location you will need to call `enableGPS(bool assisted)`. Assisted GPS or A-GPS is an enhancement of GPS that uses the cellular network to get the location, it performs that much quicker than without assistance but depends on Cellular network coverage.
127127

128128
### Cellular Location
129129
**Method Overview:** `getCellularLocation(unsigned long timeout = 10000)` also provides location tracking but utilizes the cellular network. Similar to the GPS method, it's a blocking call with a specified timeout, returning latitude and longitude values through a Location structure. If the location is not obtained, the values default to 0.0.

Diff for: examples/ReceiveSMS/ReceiveSMS.ino

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
constexpr int NEW_SMS_INTERRUPT_PIN = A0;
88

99
ArduinoCellular cellular = ArduinoCellular();
10-
volatile boolean newSMSavailable = false;
10+
volatile boolean smsReceived = false;
1111

1212
void printMessages(std::vector<SMS> msg){
1313
for(int i = 0; i < msg.size(); i++){
@@ -17,21 +17,22 @@ void printMessages(std::vector<SMS> msg){
1717
Serial.print("\t * Timestamp: "); Serial.println(msg[i].timestamp.getISO8601());
1818
}
1919
}
20-
void newSMSCallback(){
20+
void onSMSReceived(){
2121
Serial.println("New SMS received!");
22-
newSMSavailable = true;
22+
smsReceived = true;
2323
}
2424

2525
void setup(){
2626
Serial.begin(115200);
2727
while (!Serial);
28+
cellular.setDebugStream(Serial);
2829

2930
cellular.begin();
3031
Serial.println("Connecting...");
3132
cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
3233

3334
// Register interrupt based callback for new SMS
34-
attachInterrupt(digitalPinToInterrupt(NEW_SMS_INTERRUPT_PIN), newSMSCallback, RISING);
35+
attachInterrupt(digitalPinToInterrupt(NEW_SMS_INTERRUPT_PIN), onSMSReceived, RISING);
3536

3637
Serial.println("Read SMS:");
3738
std::vector<SMS> readSMS = cellular.getReadSMS();
@@ -43,8 +44,8 @@ void setup(){
4344
}
4445

4546
void loop(){
46-
if(newSMSavailable){
47-
newSMSavailable = false;
47+
if(smsReceived){
48+
smsReceived = false;
4849
std::vector<SMS> unreadSMS = cellular.getUnreadSMS();
4950
if (unreadSMS.size() > 0){
5051
printMessages(unreadSMS);

Diff for: library.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ category=Communication
88
url=https://github.com/arduino-libraries/Arduino_Cellular
99
depends=ArduinoBearSSL,StreamDebugger,TinyGSM,ArduinoHttpClient
1010
architectures=renesas_portenta, mbed_portenta
11-
includes=ArduinoCellular.h
11+
includes=Arduino_Cellular.h

Diff for: src/ArduinoCellular.cpp

+43-13
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,23 @@ void ArduinoCellular::begin() {
4545

4646
bool ArduinoCellular::connect(String apn, String gprsUser, String gprsPass, String pin){
4747
SimStatus simStatus = getSimStatus();
48-
if(simStatus == SimStatus::SIM_LOCKED) {
48+
if(simStatus == SimStatus::SIM_LOCKED && pin.length() > 0){
4949
unlockSIM(pin.c_str());
5050
}
5151

5252
simStatus = getSimStatus();
5353
if(simStatus == SimStatus::SIM_READY) {
5454
if(awaitNetworkRegistration()){
5555
if(connectToGPRS(apn.c_str(), gprsUser.c_str(), gprsPass.c_str())){
56-
Serial.println("Setting DNS...");
57-
Serial.println(this->sendATCommand("+QIDNSCFG=1,\"8.8.8.8\",\"8.8.4.4\""));
56+
if(this->debugStream != nullptr){
57+
this->debugStream->println("Setting DNS...");
58+
}
59+
60+
auto response = this->sendATCommand("+QIDNSCFG=1,\"8.8.8.8\",\"8.8.4.4\"");
61+
62+
if(this->debugStream != nullptr){
63+
this->debugStream->println(response);
64+
}
5865
return true;
5966
}
6067
} else {
@@ -83,7 +90,9 @@ Location ArduinoCellular::getGPSLocation(unsigned long timeout){
8390

8491
return loc;
8592
} else {
86-
Serial.println("Unsupported modem model");
93+
if(this->debugStream != nullptr){
94+
this->debugStream->println("Unsupported modem model");
95+
}
8796
return Location();
8897
}
8998
}
@@ -108,7 +117,11 @@ void ArduinoCellular::sendSMS(String number, String message){
108117
modem.stream->print(message); // Actually send the message
109118
modem.stream->write(static_cast<char>(0x1A)); // Terminate the message
110119
modem.stream->flush();
111-
Serial.println(modem.waitResponse(10000L));
120+
auto response = modem.waitResponse(10000L);
121+
122+
if(this->debugStream != nullptr){
123+
this->debugStream->println("Response: " + String(response));
124+
}
112125
}
113126

114127

@@ -141,9 +154,13 @@ bool ArduinoCellular::isConnectedToOperator(){
141154
}
142155

143156
bool ArduinoCellular::connectToGPRS(const char * apn, const char * gprsUser, const char * gprsPass){
144-
Serial.print(F("Connecting to 4G network..."));
157+
if(this->debugStream != nullptr){
158+
this->debugStream->println("Connecting to 4G network...");
159+
}
145160
while(!modem.gprsConnect(apn, gprsUser, gprsPass)) {
146-
Serial.print(".");
161+
if(this->debugStream != nullptr){
162+
this->debugStream->print(".");
163+
}
147164
delay(2000);
148165
}
149166
return true;
@@ -155,7 +172,9 @@ bool ArduinoCellular::isConnectedToInternet(){
155172

156173
SimStatus ArduinoCellular::getSimStatus(){
157174
int simStatus = modem.getSimStatus();
158-
Serial.println("SIM Status: " + String(simStatus));
175+
if(this->debugStream != nullptr){
176+
this->debugStream->println("SIM Status: " + String(simStatus));
177+
}
159178

160179
if (modem.getSimStatus() == 0) {
161180
return SimStatus::SIM_ERROR;
@@ -171,21 +190,30 @@ SimStatus ArduinoCellular::getSimStatus(){
171190
}
172191

173192
bool ArduinoCellular::unlockSIM(const char * pin){
174-
Serial.println("Unlocking SIM...");
193+
if(this->debugStream != nullptr){
194+
this->debugStream->println("Unlocking SIM...");
195+
}
175196
modem.simUnlock(pin);
176197
}
177198

178199
bool ArduinoCellular::awaitNetworkRegistration(){
179-
Serial.print("Waiting for network registration...");
200+
if(this->debugStream != nullptr){
201+
this->debugStream->println("Waiting for network registration...");
202+
}
180203
while (!modem.waitForNetwork()) {
181-
Serial.println(".");
204+
if(this->debugStream != nullptr){
205+
this->debugStream->print(".");
206+
}
182207
delay(2000);
183208
}
184209
return true;
185210
}
186211

187212
bool ArduinoCellular::enableGPS(bool assisted){
188-
Serial.println("Enabling GPS...");
213+
if(this->debugStream != nullptr){
214+
this->debugStream->println("Enabling GPS...");
215+
}
216+
189217
if(assisted){
190218
sendATCommand("AT+QGPSCFG=\"agpsposmode\",33488767");
191219
} else {
@@ -304,4 +332,6 @@ std::vector<SMS> ArduinoCellular::getUnreadSMS(){
304332
}
305333
}
306334

307-
335+
void ArduinoCellular::setDebugStream(Stream &stream){
336+
this->debugStream = &stream;
337+
}

Diff for: src/ArduinoCellular.h

+13-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class ArduinoCellular {
9999
* @param pin The SIM card PIN.
100100
* @return True if the connection is successful, false otherwise.
101101
*/
102-
bool connect(String apn, String gprsUser, String gprsPass, String pin);
102+
bool connect(String apn, String gprsUser, String gprsPass, String pin = "");
103103

104104
/**
105105
* @brief Checks if the modem is registered on the network.
@@ -214,6 +214,16 @@ class ArduinoCellular {
214214
*/
215215
int getSignalQuality();
216216

217+
/**
218+
* @brief Sets the debug stream for ArduinoCellular.
219+
*
220+
* This function allows you to set the debug stream for ArduinoCellular.
221+
* The debug stream is used to output debug messages and information.
222+
*
223+
* @param stream A pointer to the Stream object that will be used as the debug stream.
224+
*/
225+
void setDebugStream(Stream& stream);
226+
217227
private:
218228
bool connectToGPRS(const char * apn, const char * gprsUser, const char * gprsPass);
219229

@@ -249,6 +259,8 @@ class ArduinoCellular {
249259

250260
ModemModel model; /**< The modem model. */
251261

262+
Stream* debugStream = nullptr; /**< The stream to be used for printing debugging messages. */
263+
252264
static unsigned long getTime(); /** Callback for getting the current time as an unix timestamp. */
253265
};
254266

Diff for: src/Arduino_Cellular.h

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#ifndef ARDUINO_CELLULAR_H
2+
3+
#include "ArduinoCellular.h"
4+
5+
#endif

0 commit comments

Comments
 (0)