diff --git a/examples/HTTPClient/HTTPClient.ino b/examples/HTTPClient/HTTPClient.ino index bc8cb31..5525676 100644 --- a/examples/HTTPClient/HTTPClient.ino +++ b/examples/HTTPClient/HTTPClient.ino @@ -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); @@ -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); } - diff --git a/examples/HTTPSClient/HTTPSClient.ino b/examples/HTTPSClient/HTTPSClient.ino index 3ac5e72..f4b45d7 100644 --- a/examples/HTTPSClient/HTTPSClient.ino +++ b/examples/HTTPSClient/HTTPSClient.ino @@ -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); @@ -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); -} \ No newline at end of file +} diff --git a/examples/SMSReceive/SMSReceive.ino b/examples/ReceiveSMS/ReceiveSMS.ino similarity index 70% rename from examples/SMSReceive/SMSReceive.ino rename to examples/ReceiveSMS/ReceiveSMS.ino index fc72329..4d1720b 100644 --- a/examples/SMSReceive/SMSReceive.ino +++ b/examples/ReceiveSMS/ReceiveSMS.ino @@ -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++){ @@ -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(); @@ -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); } } -} \ No newline at end of file +} diff --git a/examples/SMSReceive/arduino_secrets.h b/examples/ReceiveSMS/arduino_secrets.h similarity index 100% rename from examples/SMSReceive/arduino_secrets.h rename to examples/ReceiveSMS/arduino_secrets.h