Skip to content

Commit 5612288

Browse files
Merge pull request #9 from arduino-libraries/various-fixes
SMS Enhancements and minor fixes
2 parents 8727c3c + 51b55ec commit 5612288

File tree

17 files changed

+472
-224
lines changed

17 files changed

+472
-224
lines changed

.github/workflows/arduino-lint.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
uses: arduino/arduino-lint-action@v1
2323
with:
2424
compliance: specification
25-
library-manager: submit
25+
library-manager: update
2626
# Always use this setting for official repositories. Remove for 3rd party projects.
2727
official: true
2828
project-type: library

README.md

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,44 @@
1-
# Arduino Cellular
1+
# 📡 Arduino Cellular
22

33
[![Arduino Lint](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/arduino-lint.yml/badge.svg)](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/arduino-lint.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/badge.svg)](https://github.com/arduino-libraries/Arduino_Cellular/actions/workflows/render-documentation.yml)
44

55

66
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.
77

88
## Examples
9-
* [examples/HTTPClient]() - Example of using this library together with [HttpClient]() to connect to a web server
10-
* [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
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.
13-
* [examples/ModemTerminal]() - A handy example for debugging and Testing AT commands
14-
15-
## Features
9+
* [DeleteSMS](examples/DeleteSMS) - Example that shows how to delete SMS.
10+
* [GetLocation](examples/GetLocation) - Shows how to get the current GPS location.
11+
* [GetTime](examples/GetTime) - Use GPS to acquire the time of the device.
12+
* [HTTPClient](examples/HTTPClient) - Example of using this library together with [ArduinoHttpClient]() to connect to a web server
13+
* [HTTPSClient](examples/HTTPSClient) - Example of using this library together with [ArduinoHttpClient]() that uses [BearSSL]() under the hood to create a secure connection to a web server
14+
* [ModemTerminal](examples/ModemTerminal) - A handy example for debugging and Testing AT commands
15+
* [ReceiveSMS](examples/ReceiveSMS) - Example for the SMS sending and receiving functionality
16+
* [SendSMS](examples/SendSMS) - Shows how to send an SMS
17+
18+
## ✨ Features
1619
* Fast 4G connection to the internet
1720
* Secure SSL connections with BearSSL
1821
* Get location using GPS or GSM
1922
* Synchronise time with the cell provider
2023
* Send and Receive SMS Messages
2124

22-
## Instructions
25+
## 👀 Instructions
2326
1. Insert your Arduino 4G module to the Arduino Portenta Mid Carrier
2427
2. Insert a valid SIM card either on the back of the Arduino 4G miniPCI board, or the **PCIE_SIM** connector on the Portenta Mid Carrier
2528
3. Connect the 6 **SERIAL1** header pins to their corresponding pins on the **PCIE_BREAKOUT** header using jumpers
2629
![](https://raw.githubusercontent.com/arduino-libraries/Arduino_Cellular/main/extras/connection_img/header.jpg?token=GHSAT0AAAAAACNPRJPUBHNVP3J3KMRPUULUZQVDLKQ)
2730
4. Connect the **3V3 PCIE** pin to the **3V3 Buck**
2831
![](https://raw.githubusercontent.com/arduino-libraries/Arduino_Cellular/main/extras/connection_img/buck.jpg?token=GHSAT0AAAAAACNPRJPUBUCALG2FUCDZ7AVCZQVDLJA)
2932
5. Connect external power to the Mid Carrier, via the **VIN** (5-12V) because modem use a lot of power when connecting or getting a GPS location. Make sure your supply can handle around 3A.
30-
6. Get the APN settings from your network operator and add them to the "ArduinoSecrets.h" file for each sketch
31-
```c
33+
6. Get the APN settings from your network operator and add them to the "arduino_secrets.h" file for each sketch
34+
```cpp
3235
const char apn[] = "live.vodafone.com";
3336
const char gprsUser[] = "live";
3437
const char gprsPass[] = "";
3538
```
3639
7. Install the library and it's dependencies
3740
8. Enjoy
3841

42+
## 📖 Documentation
3943

44+
For more information about this library please read the documentation [here](./docs).

examples/DeleteSMS/DeleteSMS.ino

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* This example demonstrates how to delete SMS messages using the ArduinoCellular library.
3+
*
4+
* Instructions:
5+
* 1. Insert a SIM card with or without PIN code in the Arduino Pro 4G Module.
6+
* 2. Provide sufficient power to the Arduino Pro 4G Module. Ideally, use a 5V power supply
7+
* with a current rating of at least 2A and connect it to the VIN and GND pins.
8+
* 3. Send an SMS to the SIM card number to test the SMS reception.
9+
* 4. Upload the sketch to the connected Arduino board.
10+
* 5. Check the serial monitor for the received SMS.
11+
* 6. Enter the index of the SMS you want to delete in the serial monitor.
12+
*
13+
* Initial author: Sebastian Romero
14+
*/
15+
16+
#include "ArduinoCellular.h"
17+
18+
ArduinoCellular cellular = ArduinoCellular();
19+
20+
void printMessages(std::vector<SMS> msg){
21+
for(int i = 0; i < msg.size(); i++){
22+
Serial.println("SMS:");
23+
Serial.print("* Index: "); Serial.println(msg[i].index);
24+
Serial.print("* From: "); Serial.println(msg[i].sender);
25+
Serial.print("* Timestamp: "); Serial.println(msg[i].timestamp.getISO8601());
26+
Serial.println("* Message: "); Serial.println(msg[i].message);
27+
Serial.println("--------------------\n");
28+
}
29+
}
30+
31+
void setup(){
32+
Serial.begin(115200);
33+
while (!Serial);
34+
cellular.begin();
35+
delay(2000); // Give the modem some time to initialize
36+
}
37+
38+
void loop(){
39+
std::vector<SMS> readSMS = cellular.getReadSMS();
40+
if(readSMS.size() > 0){
41+
Serial.println("Read SMS:");
42+
printMessages(readSMS);
43+
}
44+
45+
std::vector<SMS> unreadSMS = cellular.getUnreadSMS();
46+
if(unreadSMS.size() > 0){
47+
Serial.println("Unread SMS:");
48+
printMessages(unreadSMS);
49+
}
50+
51+
// Prompt user which SMS to delete
52+
Serial.println("Enter the index of the SMS you want to delete:");
53+
54+
while(Serial.available() == 0);
55+
auto index = Serial.readStringUntil('\n').toInt();
56+
Serial.println("Deleting SMS...");
57+
58+
if(cellular.deleteSMS(index)){
59+
Serial.println("SMS deleted.");
60+
} else {
61+
Serial.println("Failed to delete SMS.");
62+
}
63+
}

examples/GetLocation/GetLocation.ino

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* This example demonstrates how to get the current GPS location using the ArduinoCellular library.
3+
*
4+
* Instructions:
5+
* 1. Move the Arduino Pro 4G Module to an outdoor location with a clear view of the sky.
6+
* 2. Provide sufficient power to the Arduino Pro 4G Module. Ideally, use a 5V power supply
7+
* 3. Upload the sketch to the connected Arduino board.
8+
* 4. Open the serial monitor to view the output.
9+
*
10+
* Initial author: Sebastian Romero
11+
*/
12+
13+
#include "ArduinoCellular.h"
14+
15+
ArduinoCellular cellular = ArduinoCellular();
16+
17+
void setup(){
18+
Serial.begin(115200);
19+
while (!Serial);
20+
cellular.setDebugStream(Serial);
21+
cellular.begin();
22+
23+
if(!cellular.enableGPS()){
24+
Serial.println("Failed to enable GPS");
25+
while(true); // Stop the program
26+
}
27+
delay(2000); // Give the modem some time to initialize
28+
}
29+
30+
void loop(){
31+
Location location = cellular.getGPSLocation();
32+
Serial.println("GPS Location:");
33+
Serial.print("* Latitude: "); Serial.println(location.latitude, 6);
34+
Serial.print("* Longitude: "); Serial.println(location.longitude, 6);
35+
Serial.println("--------------------\n");
36+
delay(10000);
37+
}

examples/GetTime/GetTime.ino

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/**
2+
* This example demonstrates how to get the current time using the ArduinoCellular library.
3+
* It derives the time from GPS connection.
4+
*
5+
* Instructions:
6+
* 1. Move the Arduino Pro 4G Module to an outdoor location with a clear view of the sky.
7+
* 2. Provide sufficient power to the Arduino Pro 4G Module. Ideally, use a 5V power supply
8+
* 3. Upload the sketch to the connected Arduino board.
9+
* 4. Open the serial monitor to view the output.
10+
*
11+
* Initial author: Cristian Dragomir
12+
*/
13+
14+
#include "ArduinoCellular.h"
15+
16+
ArduinoCellular cellular = ArduinoCellular();
17+
18+
void setup(){
19+
Serial.begin(115200);
20+
while (!Serial);
21+
cellular.begin();
22+
23+
if(!cellular.enableGPS()){
24+
Serial.println("Failed to enable GPS");
25+
while(true); // Stop the program
26+
}
27+
delay(2000); // Give the modem some time to initialize
28+
}
29+
30+
void loop(){
31+
Location location = cellular.getGPSLocation(10000);
32+
33+
if(location.latitude == 0.0 && location.longitude == 0.0){
34+
Serial.println("Failed to get GPS location");
35+
} else {
36+
Time time = cellular.getGPSTime();
37+
Serial.print("Current time (ISO8601): "); Serial.println(time.getISO8601());
38+
}
39+
40+
delay(10000);
41+
}

examples/HTTPClient/HTTPClient.ino

+37-9
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
/**
2+
* This example demonstrates how to make a HTTP GET request using
3+
* the ArduinoHttpClient library and the ArduinoCellular library.
4+
*
5+
* Instructions:
6+
* 1. Insert a SIM card with or without PIN code in the Arduino Pro 4G Module.
7+
* 2. Provide sufficient power to the Arduino Pro 4G Module. Ideally, use a 5V power supply
8+
* with a current rating of at least 2A and connect it to the VIN and GND pins.
9+
* 3. Specify the APN, login, and password for your cellular network provider.
10+
* 4. Upload the sketch to the connected Arduino board.
11+
* 5. Open the serial monitor to view the output.
12+
*
13+
* Initial author: Cristian Dragomir
14+
*/
15+
116
#define ARDUINO_CELLULAR_DEBUG
217

318
#include "ArduinoCellular.h"
@@ -10,14 +25,7 @@ const int port = 80;
1025
ArduinoCellular cellular = ArduinoCellular();
1126
HttpClient client = cellular.getHTTPClient(server, port);
1227

13-
void setup(){
14-
Serial.begin(115200);
15-
while (!Serial);
16-
cellular.begin();
17-
cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
18-
}
19-
20-
void loop(){
28+
void getResource(){
2129

2230
Serial.println("Making GET request...");
2331

@@ -32,7 +40,27 @@ void loop(){
3240
Serial.println(response);
3341

3442
client.stop();
43+
}
3544

36-
delay(5000);
45+
void setup(){
46+
Serial.begin(115200);
47+
while (!Serial);
48+
// cellular.setDebugStream(Serial); // Uncomment this line to enable debug output
49+
cellular.begin();
3750

51+
if(String(SECRET_PINNUMBER).length() > 0 && !cellular.unlockSIM(SECRET_PINNUMBER)){
52+
Serial.println("Failed to unlock SIM card.");
53+
while(true); // Stop here
54+
}
55+
56+
Serial.println("Connecting...");
57+
if(!cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD)){
58+
Serial.println("Failed to connect to the network.");
59+
while(true); // Stop here
60+
}
61+
Serial.println("Connected!");
62+
63+
getResource();
3864
}
65+
66+
void loop(){}

examples/HTTPSClient/HTTPSClient.ino

+39-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
/**
2+
* Example demonstrating how to make an HTTPS GET request using
3+
* the ArduinoHttpClient library and the ArduinoCellular library.
4+
*
5+
* Instructions:
6+
* 1. Insert a SIM card with or without PIN code in the Arduino Pro 4G Module.
7+
* 2. Provide sufficient power to the Arduino Pro 4G Module. Ideally, use a 5V power supply
8+
* with a current rating of at least 2A and connect it to the VIN and GND pins.
9+
* 3. Specify the APN, login, and password for your cellular network provider.
10+
* 4. Upload the sketch to the connected Arduino board.
11+
* 5. Open the serial monitor to view the output.
12+
*
13+
* Initial author: Cristian Dragomir
14+
*/
115

216
#include <Arduino.h>
317
#include "ArduinoCellular.h"
@@ -11,15 +25,7 @@ const int port = 443;
1125
ArduinoCellular cellular = ArduinoCellular();
1226
HttpClient client = cellular.getHTTPSClient(server, port);
1327

14-
void setup(){
15-
Serial.begin(115200);
16-
while (!Serial);
17-
18-
cellular.begin();
19-
cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
20-
}
21-
22-
void loop(){
28+
void getResource(){
2329
Serial.println("Making GET request...");
2430

2531
client.get(resource);
@@ -33,5 +39,28 @@ void loop(){
3339
Serial.println(response);
3440

3541
client.stop();
36-
delay(5000);
3742
}
43+
44+
void setup(){
45+
Serial.begin(115200);
46+
while (!Serial);
47+
48+
// cellular.setDebugStream(Serial); // Uncomment this line to enable debug output
49+
cellular.begin();
50+
51+
if(String(SECRET_PINNUMBER).length() > 0 && !cellular.unlockSIM(SECRET_PINNUMBER)){
52+
Serial.println("Failed to unlock SIM card.");
53+
while(true); // Stop here
54+
}
55+
56+
Serial.println("Connecting...");
57+
if(!cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD)){
58+
Serial.println("Failed to connect to the network.");
59+
while(true); // Stop here
60+
}
61+
Serial.println("Connected!");
62+
63+
getResource();
64+
}
65+
66+
void loop(){}

0 commit comments

Comments
 (0)