Skip to content

Examples cleanup #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions examples/HTTPClient/HTTPClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
#include "ArduinoCellular.h"
#include "arduino_secrets.h"


const char server[] = "vsh.pp.ua";
const char resource[] = "/TinyGSM/logo.txt";
const int port = 80;

ArduinoCellular cellular = ArduinoCellular();
HttpClient http = cellular.getHTTPClient(server, port);

HttpClient client = cellular.getHTTPClient(server, port);

void setup(){
Serial.begin(115200);
Expand All @@ -23,19 +21,18 @@ void loop(){

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

http.get(resource);
client.get(resource);

int status_code = http.responseStatusCode();
String response = http.responseBody();
int statusCode = client.responseStatusCode();
String response = client.responseBody();

Serial.print("Status code: ");
Serial.println(status_code);
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);

http.stop();
client.stop();

delay(5000);

}

19 changes: 8 additions & 11 deletions examples/HTTPSClient/HTTPSClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#include <ArduinoHttpClient.h>
#include "arduino_secrets.h"


const char server[] = "example.com";
const char resource[] = "/";
const int port = 443;

ArduinoCellular cellular = ArduinoCellular();
HttpClient http = cellular.getHTTPSClient(server, port);
HttpClient client = cellular.getHTTPSClient(server, port);

void setup(){
Serial.begin(115200);
Expand All @@ -20,21 +19,19 @@ void setup(){
cellular.connect(SECRET_GPRS_APN, SECRET_GPRS_LOGIN, SECRET_GPRS_PASSWORD, SECRET_PINNUMBER);
}

void loop()
{
void loop(){
Serial.println("Making GET request...");

http.get(resource);
client.get(resource);

int status_code = http.responseStatusCode();
String response = http.responseBody();
int statusCode = client.responseStatusCode();
String response = client.responseBody();

Serial.print("Status code: ");
Serial.println(status_code);
Serial.println(statusCode);
Serial.print("Response: ");
Serial.println(response);

http.stop();

client.stop();
delay(5000);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
#include "ArduinoCellular.h"
#include "arduino_secrets.h"

// #define TINY_GSM_DEBUG Serial
// #define ARDUINO_CELLULAR_DEBUG


#define TINY_GSM_DEBUG Serial
#define ARDUINO_CELLULAR_DEBUG
constexpr int NEW_SMS_INTERRUPT_PIN = A0;

ArduinoCellular cellular = ArduinoCellular();

boolean newSMS = false;

volatile boolean newSMSavailable = false;

void printMessages(std::vector<SMS> msg){
for(int i = 0; i < msg.size(); i++){
Expand All @@ -20,18 +18,20 @@ void printMessages(std::vector<SMS> msg){
}
}
void newSMSCallback(){
Serial.println("new sms received");
newSMS = true;
Serial.println("New SMS received!");
newSMSavailable = true;
}

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

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


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

Serial.println("Read SMS:");
std::vector<SMS> readSMS = cellular.getReadSMS();
Expand All @@ -40,16 +40,14 @@ void setup(){
Serial.println("Unread SMS:");
std::vector<SMS> unreadSMS = cellular.getUnreadSMS();
printMessages(unreadSMS);

cellular.sendSMS("+40788494946", "bleep bleep");
}

void loop(){
if(newSMS){
newSMS = false;
if(newSMSavailable){
newSMSavailable = false;
std::vector<SMS> unreadSMS = cellular.getUnreadSMS();
if (unreadSMS.size() > 0){
printMessages(unreadSMS);
}
}
}
}
Loading