Skip to content

Commit

Permalink
Another update to examples
Browse files Browse the repository at this point in the history
  • Loading branch information
SRGDamia1 committed Aug 27, 2019
1 parent 4697285 commit 3a8a2ad
Show file tree
Hide file tree
Showing 8 changed files with 251 additions and 80 deletions.
17 changes: 15 additions & 2 deletions examples/AllFunctions/AllFunctions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,29 @@
//#define SMS_TARGET "+380xxxxxxxxx"
//#define CALL_TARGET "+380xxxxxxxxx"

// Your GPRS credentials
// Leave empty, if missing user or pass
// Your GPRS credentials, if any
const char apn[] = "YourAPN";
const char gprsUser[] = "";
const char gprsPass[] = "";

// Your WiFi connection credentials, if applicable
const char wifiSSID[] = "YourSSID";
const char wifiPass[] = "YourWiFiPass";

#include <TinyGsmClient.h>

#if TINY_GSM_TEST_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS
#define TINY_GSM_TEST_GPRS false
#define TINY_GSM_TEST_CALL false
#define TINY_GSM_TEST_SMS false
#define TINY_GSM_TEST_USSD false
#define TINY_GSM_TEST_WIFI true
#endif
#if TINY_GSM_TEST_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
#endif

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
Expand Down
5 changes: 2 additions & 3 deletions examples/BlynkClient/BlynkClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@
//SoftwareSerial SerialAT(2, 3); // RX, TX


// Your GPRS credentials
// Leave empty, if missing user or pass
// Your GPRS credentials, if any
const char apn[] = "YourAPN";
const char user[] = "";
const char pass[] = "";
Expand All @@ -91,7 +90,7 @@ void setup()
modem.restart();

String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.print("Modem Info: ");
SerialMon.println(modemInfo);

// Unlock your SIM card with a PIN
Expand Down
45 changes: 40 additions & 5 deletions examples/FileDownload/FileDownload.ino
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,19 @@
// Add a reception delay - may be needed for a fast processor at a slow baud rate
//#define TINY_GSM_YIELD() { delay(2); }

// Define how you're planning to connect to the internet
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false

// set GSM PIN, if any
#define GSM_PIN ""

// Your GPRS credentials
// Leave empty, if missing user or pass
// Your GPRS credentials, if any
const char apn[] = "YourAPN";
const char gprsUser[] = "";
const char gprsPass[] = "";

// Your WiFi connection credentials, if applicable
const char wifiSSID[] = "YourSSID";
const char wifiPass[] = "YourWiFiPass";

Expand All @@ -82,6 +84,20 @@ const int port = 80;
#include <TinyGsmClient.h>
#include <CRC32.h>

// Just in case someone defined the wrong thing..
#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS false
#define TINY_GSM_USE_WIFI true
#endif
#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
#endif

const char resource[] = "/TinyGSM/test_1k.bin";
uint32_t knownCRC32 = 0x6f50d767;
uint32_t knownFileSize = 1024; // In case server does not send it
Expand All @@ -101,6 +117,12 @@ void setup() {
SerialMon.begin(115200);
delay(10);

// !!!!!!!!!!!
// Set your reset, enable, power pins here
// !!!!!!!!!!!

SerialMon.println("Wait...");

// Set GSM module baud rate
SerialAT.begin(115200);
delay(3000);
Expand All @@ -109,9 +131,10 @@ void setup() {
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
modem.restart();
// modem.init();

String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.print("Modem Info: ");
SerialMon.println(modemInfo);

#if TINY_GSM_USE_GPRS
Expand All @@ -135,7 +158,8 @@ void printPercent(uint32_t readLength, uint32_t contentLength) {

void loop() {

#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI
#if TINY_GSM_USE_WIFI
// Wifi connection parameters must be set before waiting for the network
SerialMon.print(F("Setting SSID/password..."));
if (!modem.networkConnect(wifiSSID, wifiPass)) {
SerialMon.println(" fail");
Expand All @@ -162,7 +186,8 @@ void loop() {
SerialMon.println("Network connected");
}

#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS
#if TINY_GSM_USE_GPRS
// GPRS connection parameters are usually set after network registration
SerialMon.print(F("Connecting to "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
Expand All @@ -171,6 +196,10 @@ void loop() {
return;
}
SerialMon.println(" success");

if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}
#endif

SerialMon.print(F("Connecting to "));
Expand Down Expand Up @@ -292,8 +321,14 @@ void loop() {
client.stop();
SerialMon.println(F("Server disconnected"));

#if TINY_GSM_USE_WIFI
modem.networkDisconnect();
SerialMon.println(F("WiFi disconnected"));
#endif
#if TINY_GSM_USE_GPRS
modem.gprsDisconnect();
SerialMon.println(F("GPRS disconnected"));
#endif

float duration = float(timeElapsed) / 1000;

Expand Down
39 changes: 33 additions & 6 deletions examples/HttpClient/HttpClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,26 @@
#define TINY_GSM_DEBUG SerialMon
//#define LOGGING // <- Logging is for the HTTP library

// Range to attempt to autobaud
#define GSM_AUTOBAUD_MIN 9600
#define GSM_AUTOBAUD_MAX 115200

// Add a reception delay - may be needed for a fast processor at a slow baud rate
//#define TINY_GSM_YIELD() { delay(2); }

// Define how you're planning to connect to the internet
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false

// set GSM PIN, if any
#define GSM_PIN ""

// Your GPRS credentials
// Leave empty, if missing user or pass
// Your GPRS credentials, if any
const char apn[] = "YourAPN";
const char gprsUser[] = "";
const char gprsPass[] = "";

// Your WiFi connection credentials, if applicable
const char wifiSSID[] = "YourSSID";
const char wifiPass[] = "YourWiFiPass";

Expand All @@ -88,6 +94,20 @@ const int port = 80;
#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>

// Just in case someone defined the wrong thing..
#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS false
#define TINY_GSM_USE_WIFI true
#endif
#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
#endif

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
Expand All @@ -111,7 +131,8 @@ void setup() {
SerialMon.println("Wait...");

// Set GSM module baud rate
SerialAT.begin(115200);
// TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX);
SerialAT.begin(9600);
delay(3000);

// Restart takes quite some time
Expand All @@ -121,7 +142,7 @@ void setup() {
// modem.init();

String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.print("Modem Info: ");
SerialMon.println(modemInfo);

#if TINY_GSM_USE_GPRS
Expand All @@ -134,7 +155,8 @@ void setup() {

void loop() {

#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI
#if TINY_GSM_USE_WIFI
// Wifi connection parameters must be set before waiting for the network
SerialMon.print(F("Setting SSID/password..."));
if (!modem.networkConnect(wifiSSID, wifiPass)) {
SerialMon.println(" fail");
Expand All @@ -161,7 +183,8 @@ void loop() {
SerialMon.println("Network connected");
}

#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS
#if TINY_GSM_USE_GPRS
// GPRS connection parameters are usually set after network registration
SerialMon.print(F("Connecting to "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
Expand All @@ -170,6 +193,10 @@ void loop() {
return;
}
SerialMon.println(" success");

if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}
#endif

SerialMon.print(F("Performing HTTP GET request... "));
Expand Down
41 changes: 34 additions & 7 deletions examples/HttpsClient/HttpsClient.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,26 @@
#define TINY_GSM_DEBUG SerialMon
//#define LOGGING // <- Logging is for the HTTP library

// Range to attempt to autobaud
#define GSM_AUTOBAUD_MIN 9600
#define GSM_AUTOBAUD_MAX 115200

// Add a reception delay - may be needed for a fast processor at a slow baud rate
//#define TINY_GSM_YIELD() { delay(2); }

// Define how you're planning to connect to the internet
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false

// set GSM PIN, if any
#define GSM_PIN ""

// Your GPRS credentials
// Leave empty, if missing user or pass
// Your GPRS credentials, if any
const char apn[] = "YourAPN";
const char gprsUser[] = "";
const char gprsPass[] = "";

// Your WiFi connection credentials, if applicable
const char wifiSSID[] = "YourSSID";
const char wifiPass[] = "YourWiFiPass";

Expand All @@ -80,6 +86,20 @@ const int port = 443;
#include <TinyGsmClient.h>
#include <ArduinoHttpClient.h>

// Just in case someone defined the wrong thing..
#if TINY_GSM_USE_GPRS && not defined TINY_GSM_MODEM_HAS_GPRS
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS false
#define TINY_GSM_USE_WIFI true
#endif
#if TINY_GSM_USE_WIFI && not defined TINY_GSM_MODEM_HAS_WIFI
#undef TINY_GSM_USE_GPRS
#undef TINY_GSM_USE_WIFI
#define TINY_GSM_USE_GPRS true
#define TINY_GSM_USE_WIFI false
#endif

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
Expand All @@ -103,7 +123,8 @@ void setup() {
SerialMon.println("Wait...");

// Set GSM module baud rate
SerialAT.begin(115200);
// TinyGsmAutoBaud(SerialAT,GSM_AUTOBAUD_MIN,GSM_AUTOBAUD_MAX);
SerialAT.begin(9600);
delay(3000);

// Restart takes quite some time
Expand All @@ -113,7 +134,7 @@ void setup() {
// modem.init();

String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.print("Modem Info: ");
SerialMon.println(modemInfo);

#if TINY_GSM_USE_GPRS
Expand All @@ -131,7 +152,8 @@ void setup() {

void loop() {

#if defined TINY_GSM_USE_WIFI && defined TINY_GSM_MODEM_HAS_WIFI
#if TINY_GSM_USE_WIFI
// Wifi connection parameters must be set before waiting for the network
SerialMon.print(F("Setting SSID/password..."));
if (!modem.networkConnect(wifiSSID, wifiPass)) {
SerialMon.println(" fail");
Expand All @@ -158,7 +180,8 @@ void loop() {
SerialMon.println("Network connected");
}

#if TINY_GSM_USE_GPRS && defined TINY_GSM_MODEM_HAS_GPRS
#if TINY_GSM_USE_GPRS
// GPRS connection parameters are usually set after network registration
SerialMon.print(F("Connecting to "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
Expand All @@ -167,10 +190,14 @@ void loop() {
return;
}
SerialMon.println(" success");

if (modem.isGprsConnected()) {
SerialMon.println("GPRS connected");
}
#endif

SerialMon.print(F("Performing HTTPS GET request... "));
http.connectionKeepAlive(); // Currently, this is needed for HTTPS
http.connectionKeepAlive(); // Currently, this is needed for HTTPS
int err = http.get(resource);
if (err != 0) {
SerialMon.println(F("failed to connect"));
Expand Down
Loading

0 comments on commit 3a8a2ad

Please sign in to comment.