Skip to content

Commit

Permalink
Merge pull request #6 from arduino-libraries/header-issue-fix
Browse files Browse the repository at this point in the history
Fix issue about umbrella header
  • Loading branch information
sebromero authored Apr 9, 2024
2 parents b4058f7 + 33cf496 commit 597bc6f
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 56 deletions.
Binary file removed .DS_Store
Binary file not shown.
28 changes: 0 additions & 28 deletions .github/workflows/check-arduino.yml

This file was deleted.

10 changes: 6 additions & 4 deletions .github/workflows/compile-examples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ env:
- examples/HTTPClient
- examples/HTTPSClient
- examples/TimeAndLocation
- examples/SMSReceive
- examples/ReceiveSMS
- examples/SendSMS
SKETCHES_REPORTS_PATH: sketches-reports
SKETCHES_REPORTS_ARTIFACT_NAME: sketches-reports

Expand Down Expand Up @@ -65,9 +66,10 @@ jobs:
libraries: |
# Install the library from the local path.
- source-path: ./
- name: Arduino_USBHostMbed5
- name: Arduino_POSIXStorage
- name: ArduinoRS485
- name: ArduinoBearSSL
- name: StreamDebugger
- name: TinyGSM
- name: ArduinoHttpClient
# Additional library dependencies can be listed here.
# See: https://github.com/arduino/compile-sketches#libraries
sketch-paths: |
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Arduino Cellular

[![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)


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.

## Examples
* [examples/HTTPClient]() - Example of using this library together with [HttpClient]() to connect to a web server
* [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
* [examples/SMSReceive]() - Example for the SMS sending and receiving functionality
* [examples/TimeAndLocation]() - Use GPS, or Cellular to aquire the location and time of the device.
* [examples/ReceiveSMS]() - Example for the SMS sending and receiving functionality
* [examples/TimeAndLocation]() - Use GPS, or Cellular to acquire the location and time of the device.
* [examples/ModemTerminal]() - A handy example for debugging and Testing AT commands

## Features
Expand Down
2 changes: 1 addition & 1 deletion docs/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ These features enable precise tracking of device locations and ensure synchroniz

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.

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

### Cellular Location
**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.
Expand Down
13 changes: 7 additions & 6 deletions examples/ReceiveSMS/ReceiveSMS.ino
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
constexpr int NEW_SMS_INTERRUPT_PIN = A0;

ArduinoCellular cellular = ArduinoCellular();
volatile boolean newSMSavailable = false;
volatile boolean smsReceived = false;

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

void setup(){
Serial.begin(115200);
while (!Serial);
cellular.setDebugStream(Serial);

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

// Register interrupt based callback for new SMS
attachInterrupt(digitalPinToInterrupt(NEW_SMS_INTERRUPT_PIN), newSMSCallback, RISING);
attachInterrupt(digitalPinToInterrupt(NEW_SMS_INTERRUPT_PIN), onSMSReceived, RISING);

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

void loop(){
if(newSMSavailable){
newSMSavailable = false;
if(smsReceived){
smsReceived = false;
std::vector<SMS> unreadSMS = cellular.getUnreadSMS();
if (unreadSMS.size() > 0){
printMessages(unreadSMS);
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ category=Communication
url=https://github.com/arduino-libraries/Arduino_Cellular
depends=ArduinoBearSSL,StreamDebugger,TinyGSM,ArduinoHttpClient
architectures=renesas_portenta, mbed_portenta
includes=ArduinoCellular.h
includes=Arduino_Cellular.h
56 changes: 43 additions & 13 deletions src/ArduinoCellular.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,23 @@ void ArduinoCellular::begin() {

bool ArduinoCellular::connect(String apn, String gprsUser, String gprsPass, String pin){
SimStatus simStatus = getSimStatus();
if(simStatus == SimStatus::SIM_LOCKED) {
if(simStatus == SimStatus::SIM_LOCKED && pin.length() > 0){
unlockSIM(pin.c_str());
}

simStatus = getSimStatus();
if(simStatus == SimStatus::SIM_READY) {
if(awaitNetworkRegistration()){
if(connectToGPRS(apn.c_str(), gprsUser.c_str(), gprsPass.c_str())){
Serial.println("Setting DNS...");
Serial.println(this->sendATCommand("+QIDNSCFG=1,\"8.8.8.8\",\"8.8.4.4\""));
if(this->debugStream != nullptr){
this->debugStream->println("Setting DNS...");
}

auto response = this->sendATCommand("+QIDNSCFG=1,\"8.8.8.8\",\"8.8.4.4\"");

if(this->debugStream != nullptr){
this->debugStream->println(response);
}
return true;
}
} else {
Expand Down Expand Up @@ -83,7 +90,9 @@ Location ArduinoCellular::getGPSLocation(unsigned long timeout){

return loc;
} else {
Serial.println("Unsupported modem model");
if(this->debugStream != nullptr){
this->debugStream->println("Unsupported modem model");
}
return Location();
}
}
Expand All @@ -108,7 +117,11 @@ void ArduinoCellular::sendSMS(String number, String message){
modem.stream->print(message); // Actually send the message
modem.stream->write(static_cast<char>(0x1A)); // Terminate the message
modem.stream->flush();
Serial.println(modem.waitResponse(10000L));
auto response = modem.waitResponse(10000L);

if(this->debugStream != nullptr){
this->debugStream->println("Response: " + String(response));
}
}


Expand Down Expand Up @@ -141,9 +154,13 @@ bool ArduinoCellular::isConnectedToOperator(){
}

bool ArduinoCellular::connectToGPRS(const char * apn, const char * gprsUser, const char * gprsPass){
Serial.print(F("Connecting to 4G network..."));
if(this->debugStream != nullptr){
this->debugStream->println("Connecting to 4G network...");
}
while(!modem.gprsConnect(apn, gprsUser, gprsPass)) {
Serial.print(".");
if(this->debugStream != nullptr){
this->debugStream->print(".");
}
delay(2000);
}
return true;
Expand All @@ -155,7 +172,9 @@ bool ArduinoCellular::isConnectedToInternet(){

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

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

bool ArduinoCellular::unlockSIM(const char * pin){
Serial.println("Unlocking SIM...");
if(this->debugStream != nullptr){
this->debugStream->println("Unlocking SIM...");
}
modem.simUnlock(pin);
}

bool ArduinoCellular::awaitNetworkRegistration(){
Serial.print("Waiting for network registration...");
if(this->debugStream != nullptr){
this->debugStream->println("Waiting for network registration...");
}
while (!modem.waitForNetwork()) {
Serial.println(".");
if(this->debugStream != nullptr){
this->debugStream->print(".");
}
delay(2000);
}
return true;
}

bool ArduinoCellular::enableGPS(bool assisted){
Serial.println("Enabling GPS...");
if(this->debugStream != nullptr){
this->debugStream->println("Enabling GPS...");
}

if(assisted){
sendATCommand("AT+QGPSCFG=\"agpsposmode\",33488767");
} else {
Expand Down Expand Up @@ -304,4 +332,6 @@ std::vector<SMS> ArduinoCellular::getUnreadSMS(){
}
}


void ArduinoCellular::setDebugStream(Stream &stream){
this->debugStream = &stream;
}
14 changes: 13 additions & 1 deletion src/ArduinoCellular.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class ArduinoCellular {
* @param pin The SIM card PIN.
* @return True if the connection is successful, false otherwise.
*/
bool connect(String apn, String gprsUser, String gprsPass, String pin);
bool connect(String apn, String gprsUser, String gprsPass, String pin = "");

/**
* @brief Checks if the modem is registered on the network.
Expand Down Expand Up @@ -214,6 +214,16 @@ class ArduinoCellular {
*/
int getSignalQuality();

/**
* @brief Sets the debug stream for ArduinoCellular.
*
* This function allows you to set the debug stream for ArduinoCellular.
* The debug stream is used to output debug messages and information.
*
* @param stream A pointer to the Stream object that will be used as the debug stream.
*/
void setDebugStream(Stream& stream);

private:
bool connectToGPRS(const char * apn, const char * gprsUser, const char * gprsPass);

Expand Down Expand Up @@ -249,6 +259,8 @@ class ArduinoCellular {

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

Stream* debugStream = nullptr; /**< The stream to be used for printing debugging messages. */

static unsigned long getTime(); /** Callback for getting the current time as an unix timestamp. */
};

Expand Down
5 changes: 5 additions & 0 deletions src/Arduino_Cellular.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifndef ARDUINO_CELLULAR_H

#include "ArduinoCellular.h"

#endif

0 comments on commit 597bc6f

Please sign in to comment.