Update examples
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
* TinyGSM Getting Started guide:
|
||||
* http://tiny.cc/tiny-gsm-readme
|
||||
*
|
||||
* For more HTTP API examples, see ArduinoHttpClient library
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Select your modem:
|
||||
@@ -21,8 +23,17 @@
|
||||
// #define TINY_GSM_MODEM_M590
|
||||
// #define TINY_GSM_MODEM_ESP8266
|
||||
|
||||
// Increase RX buffer
|
||||
#define TINY_GSM_RX_BUFFER 600
|
||||
// Increase RX buffer if needed
|
||||
//#define TINY_GSM_RX_BUFFER 512
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
|
||||
// Uncomment this if you want to see all AT commands
|
||||
//#define DUMP_AT_COMMANDS
|
||||
|
||||
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
||||
#define SerialMon Serial
|
||||
|
||||
// Use Hardware Serial on Mega, Leonardo, Micro
|
||||
#define SerialAT Serial1
|
||||
@@ -31,9 +42,6 @@
|
||||
//#include <SoftwareSerial.h>
|
||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
//#define DUMP_AT_COMMANDS
|
||||
//#define TINY_GSM_DEBUG Serial
|
||||
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
@@ -41,18 +49,14 @@ const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
// Name of the server we want to connect to
|
||||
const char server[] = "cdn.rawgit.com";
|
||||
const int port = 80;
|
||||
// Path to download (this is the bit after the hostname in the URL)
|
||||
const char resource[] = "/vshymanskyy/tinygsm/master/extras/logo.txt";
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
#include <ArduinoHttpClient.h>
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char resource[] = "/TinyGSM/logo.txt";
|
||||
const int port = 80;
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, Serial);
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
@@ -63,7 +67,7 @@ HttpClient http(client, server, port);
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
Serial.begin(115200);
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
@@ -72,46 +76,45 @@ void setup() {
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
Serial.println("Initializing modem...");
|
||||
SerialMon.println(F("Initializing modem..."));
|
||||
modem.restart();
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
Serial.print("Modem: ");
|
||||
Serial.println(modemInfo);
|
||||
SerialMon.print(F("Modem: "));
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print(F("Waiting for network..."));
|
||||
SerialMon.print(F("Waiting for network..."));
|
||||
if (!modem.waitForNetwork()) {
|
||||
Serial.println(" fail");
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
Serial.println(" OK");
|
||||
SerialMon.println(" OK");
|
||||
|
||||
Serial.print(F("Connecting to "));
|
||||
Serial.print(apn);
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, user, pass)) {
|
||||
Serial.println(" fail");
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
Serial.println(" OK");
|
||||
SerialMon.println(" OK");
|
||||
|
||||
|
||||
Serial.print(F("Performing HTTP GET request... "));
|
||||
SerialMon.print(F("Performing HTTP GET request... "));
|
||||
int err = http.get(resource);
|
||||
if (err != 0) {
|
||||
Serial.println("failed to connect");
|
||||
SerialMon.println(F("failed to connect"));
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
int status = http.responseStatusCode();
|
||||
Serial.println(status);
|
||||
SerialMon.println(status);
|
||||
if (!status) {
|
||||
delay(10000);
|
||||
return;
|
||||
@@ -120,29 +123,32 @@ void loop() {
|
||||
while (http.headerAvailable()) {
|
||||
String headerName = http.readHeaderName();
|
||||
String headerValue = http.readHeaderValue();
|
||||
//Serial.println(headerName + " : " + headerValue);
|
||||
//SerialMon.println(headerName + " : " + headerValue);
|
||||
}
|
||||
|
||||
int length = http.contentLength();
|
||||
if (length >= 0) {
|
||||
Serial.println(String("Content length is: ") + length);
|
||||
SerialMon.print(F("Content length is: "));
|
||||
SerialMon.println(length);
|
||||
}
|
||||
if (http.isResponseChunked()) {
|
||||
Serial.println("This response is chunked");
|
||||
SerialMon.println(F("The response is chunked"));
|
||||
}
|
||||
|
||||
String body = http.responseBody();
|
||||
Serial.println("Response:");
|
||||
Serial.println(body);
|
||||
SerialMon.println(F("Response:"));
|
||||
SerialMon.println(body);
|
||||
|
||||
Serial.println(String("Body length is: ") + body.length());
|
||||
SerialMon.print(F("Body length is: "));
|
||||
SerialMon.println(body.length());
|
||||
|
||||
// Shutdown
|
||||
|
||||
http.stop();
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
modem.gprsDisconnect();
|
||||
Serial.println("GPRS disconnected");
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
|
Reference in New Issue
Block a user