From bee4f222b116aac729cd8156477962355ef9a541 Mon Sep 17 00:00:00 2001 From: Volodymyr Shymanskyy Date: Fri, 2 Dec 2016 15:11:21 +0200 Subject: [PATCH] Add SimpleTest --- extras/test_simple.txt | 10 ++++ tools/AT_Debug/AT_Debug.ino | 6 +- tools/FactoryReset/FactoryReset.ino | 6 +- tools/SimpleTest/SimpleTest.ino | 93 +++++++++++++++++++++++++++++ 4 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 extras/test_simple.txt create mode 100644 tools/SimpleTest/SimpleTest.ino diff --git a/extras/test_simple.txt b/extras/test_simple.txt new file mode 100644 index 0000000..675136a --- /dev/null +++ b/extras/test_simple.txt @@ -0,0 +1,10 @@ +01 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +02 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +03 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +04 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +05 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +06 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +07 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +08 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +09 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +10 #$%@`"'~^&-*+=!?.,:;_\|/<>()[]{} 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz diff --git a/tools/AT_Debug/AT_Debug.ino b/tools/AT_Debug/AT_Debug.ino index 8423c55..ed339ab 100644 --- a/tools/AT_Debug/AT_Debug.ino +++ b/tools/AT_Debug/AT_Debug.ino @@ -1,7 +1,11 @@ /************************************************************** * - * To run this tool, you need to install StreamDebugger library: + * To run this tool you need StreamDebugger library: * https://github.com/vshymanskyy/StreamDebugger + * or from http://librarymanager/ + * + * TinyGSM Getting Started guide: + * http://tiny.cc/tiny-gsm-readme * **************************************************************/ diff --git a/tools/FactoryReset/FactoryReset.ino b/tools/FactoryReset/FactoryReset.ino index f882fa1..457bbf4 100644 --- a/tools/FactoryReset/FactoryReset.ino +++ b/tools/FactoryReset/FactoryReset.ino @@ -1,7 +1,11 @@ /************************************************************** * - * To run this tool, you need to install StreamDebugger library: + * To run this tool you need StreamDebugger library: * https://github.com/vshymanskyy/StreamDebugger + * or from http://librarymanager/ + * + * TinyGSM Getting Started guide: + * http://tiny.cc/tiny-gsm-readme * **************************************************************/ diff --git a/tools/SimpleTest/SimpleTest.ino b/tools/SimpleTest/SimpleTest.ino new file mode 100644 index 0000000..3978937 --- /dev/null +++ b/tools/SimpleTest/SimpleTest.ino @@ -0,0 +1,93 @@ +/************************************************************** + * + * To run this tool you need StreamDebugger library: + * https://github.com/vshymanskyy/StreamDebugger + * or from http://librarymanager/ + * + * TinyGSM Getting Started guide: + * http://tiny.cc/tiny-gsm-readme + * + **************************************************************/ + +#include +#include + +char apn[] = "YourAPN"; +char user[] = ""; +char pass[] = ""; + +// Use Hardware Serial on Mega, Leonardo, Micro +#define GsmSerial Serial1 + +// or Software Serial on Uno, Nano +//#include +//SoftwareSerial GsmSerial(2, 3); // RX, TX + +StreamDebugger DebugSerial(GsmSerial, Serial); +TinyGsmClient client(DebugSerial); + +char server[] = "cdn.rawgit.com"; +char resource[] = "/vshymanskyy/tinygsm/master/extras/test_simple.txt"; + +void setup() { + // Set console baud rate + Serial.begin(115200); + delay(10); + + // Set GSM module baud rate + GsmSerial.begin(115200); + delay(3000); + + // Restart takes quite some time + // You can skip it in many cases + Serial.println("Restarting modem..."); + client.restart(); +} + +void loop() { + Serial.print("Connecting to "); + Serial.print(apn); + if (!client.networkConnect(apn, user, pass)) { + Serial.println(" failed"); + delay(10000); + return; + } + Serial.println(" OK"); + + Serial.print("Connecting to "); + Serial.print(server); + if (!client.connect(server, 80)) { + Serial.println(" failed"); + delay(10000); + return; + } + Serial.println(" OK"); + + // Make a HTTP GET request: + client.print(String("GET ") + resource + " HTTP/1.0\r\n"); + client.print(String("Host: ") + server + "\r\n"); + client.print("Connection: close\r\n\r\n"); + + unsigned long timeout = millis(); + while (client.connected() && millis() - timeout < 10000L) { + // Print available data + while (client.available()) { + char c = client.read(); + //Serial.print(c); + timeout = millis(); + } + } + Serial.println(); + + client.stop(); + Serial.println("Server disconnected"); + + client.networkDisconnect(); + Serial.println("GPRS disconnected"); + + // Do nothing forevermore + while (true) { + delay(1000); + } +} +