Update API and examples

This commit is contained in:
Volodymyr Shymanskyy
2016-12-08 14:03:37 +02:00
parent f9ef69cb6d
commit f11060e885
9 changed files with 203 additions and 138 deletions

View File

@@ -9,7 +9,7 @@
**************************************************************/
// Set serial for debug console (to the Serial Monitor, speed 115200)
#define SerialMonitor Serial
#define SerialMon Serial
// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
@@ -20,11 +20,11 @@
//SoftwareSerial SerialAT(2, 3); // RX, TX
#include <TinyGsmClient.h>
TinyGsmClient gsm(SerialAT);
TinyGsm modem(SerialAT);
void setup() {
// Set console baud rate
SerialMonitor.begin(115200);
SerialMon.begin(115200);
delay(5000);
}
@@ -33,43 +33,43 @@ void loop() {
uint32_t rate = 0;
uint32_t rates[] = { 115200, 9600, 57600, 19200, 74400, 74880 };
SerialMonitor.println("Autodetecting baud rate");
SerialMon.println("Autodetecting baud rate");
for (unsigned i = 0; i < sizeof(rates)/sizeof(rates[0]); i++) {
SerialMonitor.print(String("Trying baud rate ") + rates[i] + "... ");
SerialMon.print(String("Trying baud rate ") + rates[i] + "... ");
SerialAT.begin(rates[i]);
delay(10);
if (gsm.autoBaud(3000)) {
if (modem.autoBaud(2000)) {
rate = rates[i];
SerialMonitor.println(F("OK"));
SerialMon.println(F("OK"));
break;
} else {
SerialMonitor.println(F("fail"));
SerialMon.println(F("fail"));
}
}
if (!rate) {
SerialMonitor.println(F("***********************************************************"));
SerialMonitor.println(F(" Module does not respond!"));
SerialMonitor.println(F(" Check your Serial wiring"));
SerialMonitor.println(F(" Check the module is correctly powered and turned on"));
SerialMonitor.println(F("***********************************************************"));
SerialMon.println(F("***********************************************************"));
SerialMon.println(F(" Module does not respond!"));
SerialMon.println(F(" Check your Serial wiring"));
SerialMon.println(F(" Check the module is correctly powered and turned on"));
SerialMon.println(F("***********************************************************"));
delay(30000L);
return;
}
// Access AT commands from Serial Monitor
SerialMonitor.println(F("***********************************************************"));
SerialMonitor.println(F(" You can now send AT commands"));
SerialMonitor.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
SerialMonitor.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
SerialMonitor.println(F("***********************************************************"));
SerialMon.println(F("***********************************************************"));
SerialMon.println(F(" You can now send AT commands"));
SerialMon.println(F(" Enter \"AT\" (without quotes), and you should see \"OK\""));
SerialMon.println(F(" If it doesn't work, select \"Both NL & CR\" in Serial Monitor"));
SerialMon.println(F("***********************************************************"));
while(true) {
if (SerialAT.available()) {
SerialMonitor.write(SerialAT.read());
SerialMon.write(SerialAT.read());
}
if (SerialMonitor.available()) {
SerialAT.write(SerialMonitor.read());
if (SerialMon.available()) {
SerialAT.write(SerialMon.read());
}
delay(0);
}

View File

@@ -10,7 +10,7 @@
**************************************************************/
// Set serial for debug console (to the Serial Monitor, speed 115200)
#define SerialMonitor Serial
#define SerialMon Serial
// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
@@ -22,33 +22,33 @@
#include <TinyGsmClient.h>
#include <StreamDebugger.h>
StreamDebugger DebugAT(SerialAT, SerialMonitor);
TinyGsmClient gsm(DebugAT);
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
void setup() {
// Set console baud rate
SerialMonitor.begin(115200);
SerialMon.begin(115200);
delay(10);
// Set GSM module baud rate
SerialAT.begin(115200);
delay(3000);
if (!gsm.begin()) {
SerialMonitor.println(F("***********************************************************"));
SerialMonitor.println(F(" Cannot initialize module!"));
SerialMonitor.println(F(" Use File -> Examples -> TinyGSM -> tools -> AT_Debug"));
SerialMonitor.println(F(" to find correct configuration"));
SerialMonitor.println(F("***********************************************************"));
if (!modem.begin()) {
SerialMon.println(F("***********************************************************"));
SerialMon.println(F(" Cannot initialize module!"));
SerialMon.println(F(" Use File -> Examples -> TinyGSM -> tools -> AT_Debug"));
SerialMon.println(F(" to find correct configuration"));
SerialMon.println(F("***********************************************************"));
return;
}
bool ret = gsm.factoryDefault();
bool ret = modem.factoryDefault();
SerialMonitor.println(F("***********************************************************"));
SerialMonitor.print (F(" Return settings to Factory Defaults: "));
SerialMonitor.println((ret) ? "OK" : "FAIL");
SerialMonitor.println(F("***********************************************************"));
SerialMon.println(F("***********************************************************"));
SerialMon.print (F(" Return settings to Factory Defaults: "));
SerialMon.println((ret) ? "OK" : "FAIL");
SerialMon.println(F("***********************************************************"));
}
void loop() {

View File

@@ -12,15 +12,12 @@
// Increase buffer fo see less commands
#define GSM_RX_BUFFER 256
#include <TinyGsmClient.h>
#include <StreamDebugger.h>
char apn[] = "YourAPN";
char user[] = "";
char pass[] = "";
// Set serial for debug console (to the Serial Monitor, speed 115200)
#define SerialMonitor Serial
#define SerialMon Serial
// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
@@ -30,15 +27,19 @@ char pass[] = "";
//#include <SoftwareSerial.h>
//SoftwareSerial SerialAT(2, 3); // RX, TX
StreamDebugger DebugAT(SerialAT, SerialMonitor);
TinyGsmClient client(DebugAT);
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
#include <TinyGsmClient.h>
TinyGsm modem(debugger);
TinyGsmClient client(modem);
char server[] = "cdn.rawgit.com";
char resource[] = "/vshymanskyy/tinygsm/master/extras/test_simple.txt";
void setup() {
// Set console baud rate
SerialMonitor.begin(115200);
SerialMon.begin(115200);
delay(10);
// Set GSM module baud rate
@@ -47,12 +48,19 @@ void setup() {
// Restart takes quite some time
// You can skip it in many cases
SerialMonitor.println("Restarting modem...");
client.restart();
SerialMon.println("Restarting modem...");
modem.restart();
SerialMon.println("Waiting for network... ");
if (modem.waitForNetwork()) {
SerialMon.println("OK");
} else {
SerialMon.println("fail");
}
}
void loop() {
if (!client.networkConnect(apn, user, pass)) {
if (!modem.networkConnect(apn, user, pass)) {
delay(10000);
return;
}
@@ -76,7 +84,7 @@ void loop() {
while (client.connected() && millis() - timeout < 10000L) {
while (client.available()) {
char c = client.read();
//SerialMonitor.print(c);
//SerialMon.print(c);
bytesReceived += 1;
timeout = millis();
}
@@ -84,16 +92,16 @@ void loop() {
client.stop();
client.networkDisconnect();
modem.networkDisconnect();
SerialMonitor.println();
SerialMonitor.println("************************");
SerialMonitor.print (" Received: ");
SerialMonitor.print(bytesReceived);
SerialMonitor.println("bytes");
SerialMonitor.print (" Test: ");
SerialMonitor.println((bytesReceived == 1000) ? "PASSED" : "FAIL");
SerialMonitor.println("************************");
SerialMon.println();
SerialMon.println("************************");
SerialMon.print (" Received: ");
SerialMon.print(bytesReceived);
SerialMon.println("bytes");
SerialMon.print (" Test: ");
SerialMon.println((bytesReceived == 1000) ? "PASSED" : "FAIL");
SerialMon.println("************************");
// Do nothing forevermore
while (true) {