Update API and examples
This commit is contained in:
@@ -17,13 +17,14 @@ char user[] = "";
|
||||
char pass[] = "";
|
||||
|
||||
// Use Hardware Serial on Mega, Leonardo, Micro
|
||||
#define GsmSerial Serial1
|
||||
#define SerialAT Serial1
|
||||
|
||||
// or Software Serial on Uno, Nano
|
||||
//#include <SoftwareSerial.h>
|
||||
//SoftwareSerial GsmSerial(2, 3); // RX, TX
|
||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
TinyGsmClient client(GsmSerial);
|
||||
TinyGsm modem(SerialAT);
|
||||
TinyGsmClient client(modem);
|
||||
|
||||
char server[] = "cdn.rawgit.com";
|
||||
char resource[] = "/vshymanskyy/tinygsm/master/extras/logo.txt";
|
||||
@@ -34,20 +35,27 @@ void setup() {
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
GsmSerial.begin(115200);
|
||||
SerialAT.begin(115200);
|
||||
delay(3000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// You can skip it in many cases
|
||||
Serial.println("Restarting modem...");
|
||||
client.restart();
|
||||
modem.restart();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("Waiting for network...");
|
||||
if (!modem.waitForNetwork()) {
|
||||
Serial.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
Serial.println(" OK");
|
||||
|
||||
Serial.print("Connecting to ");
|
||||
Serial.print(apn);
|
||||
if (!client.networkConnect(apn, user, pass)) {
|
||||
Serial.println(" failed");
|
||||
if (!modem.gprsConnect(apn, user, pass)) {
|
||||
Serial.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
@@ -81,7 +89,7 @@ void loop() {
|
||||
client.stop();
|
||||
Serial.println("Server disconnected");
|
||||
|
||||
client.networkDisconnect();
|
||||
modem.gprsDisconnect();
|
||||
Serial.println("GPRS disconnected");
|
||||
|
||||
// Do nothing forevermore
|
||||
|
Reference in New Issue
Block a user