mirror of
				https://github.com/KevinMidboe/TinyGSM.git
				synced 2025-10-29 18:00:18 +00:00 
			
		
		
		
	Added code to use TinyGSM Fifo instead of buffer, but unstable
This commit is contained in:
		@@ -12,6 +12,9 @@
 | 
			
		||||
 *
 | 
			
		||||
 * For more HTTP API examples, see ArduinoHttpClient library
 | 
			
		||||
 *
 | 
			
		||||
 * NOTE: This example does NOT work with the XBee because the
 | 
			
		||||
 * HttpClient library does not empty to serial buffer fast enough
 | 
			
		||||
 * and the buffer overflow causes the HttpClient library to stall.
 | 
			
		||||
 **************************************************************/
 | 
			
		||||
 | 
			
		||||
// Select your modem:
 | 
			
		||||
@@ -28,10 +31,19 @@
 | 
			
		||||
// #define TINY_GSM_MODEM_MC60
 | 
			
		||||
// #define TINY_GSM_MODEM_MC60E
 | 
			
		||||
// #define TINY_GSM_MODEM_ESP8266
 | 
			
		||||
// #define TINY_GSM_MODEM_XBEE
 | 
			
		||||
 | 
			
		||||
// Increase RX buffer if needed
 | 
			
		||||
//#define TINY_GSM_RX_BUFFER 512
 | 
			
		||||
// Increase RX buffer to capture the entire response
 | 
			
		||||
// Chips without internal buffering (A6/A7, ESP8266, M590)
 | 
			
		||||
// need enough space in the buffer for the entire response
 | 
			
		||||
// else data will be lost (and the http library will fail).
 | 
			
		||||
#define TINY_GSM_RX_BUFFER 650
 | 
			
		||||
 | 
			
		||||
// See the debugging, if wanted
 | 
			
		||||
//#define TINY_GSM_DEBUG Serial
 | 
			
		||||
//#define LOGGING
 | 
			
		||||
 | 
			
		||||
// Add a reception delay, if needed
 | 
			
		||||
//#define TINY_GSM_YIELD() { delay(1); }
 | 
			
		||||
 | 
			
		||||
#include <TinyGsmClient.h>
 | 
			
		||||
#include <ArduinoHttpClient.h>
 | 
			
		||||
@@ -53,8 +65,10 @@
 | 
			
		||||
// Your GPRS credentials
 | 
			
		||||
// Leave empty, if missing user or pass
 | 
			
		||||
const char apn[]  = "YourAPN";
 | 
			
		||||
const char user[] = "";
 | 
			
		||||
const char pass[] = "";
 | 
			
		||||
const char gprsUser[] = "";
 | 
			
		||||
const char gprsPass[] = "";
 | 
			
		||||
const char wifiSSID[]  = "YourSSID";
 | 
			
		||||
const char wifiPass[] = "SSIDpw";
 | 
			
		||||
 | 
			
		||||
// Server details
 | 
			
		||||
const char server[] = "vsh.pp.ua";
 | 
			
		||||
@@ -76,6 +90,7 @@ void setup() {
 | 
			
		||||
  // Set console baud rate
 | 
			
		||||
  SerialMon.begin(115200);
 | 
			
		||||
  delay(10);
 | 
			
		||||
  SerialMon.println(F("Wait..."));
 | 
			
		||||
 | 
			
		||||
  // Set GSM module baud rate
 | 
			
		||||
  SerialAT.begin(115200);
 | 
			
		||||
@@ -95,6 +110,17 @@ void setup() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
 | 
			
		||||
  if (modem.hasWifi()) {
 | 
			
		||||
    SerialMon.print(F("Setting SSID/password..."));
 | 
			
		||||
    if (!modem.networkConnect(wifiSSID, wifiPass)) {
 | 
			
		||||
      SerialMon.println(" fail");
 | 
			
		||||
      delay(10000);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    SerialMon.println(" OK");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  SerialMon.print(F("Waiting for network..."));
 | 
			
		||||
  if (!modem.waitForNetwork()) {
 | 
			
		||||
    SerialMon.println(" fail");
 | 
			
		||||
@@ -103,14 +129,16 @@ void loop() {
 | 
			
		||||
  }
 | 
			
		||||
  SerialMon.println(" OK");
 | 
			
		||||
 | 
			
		||||
  SerialMon.print(F("Connecting to "));
 | 
			
		||||
  SerialMon.print(apn);
 | 
			
		||||
  if (!modem.gprsConnect(apn, user, pass)) {
 | 
			
		||||
    SerialMon.println(" fail");
 | 
			
		||||
    delay(10000);
 | 
			
		||||
    return;
 | 
			
		||||
  if (modem.hasGPRS()) {
 | 
			
		||||
    SerialMon.print(F("Connecting to "));
 | 
			
		||||
    SerialMon.print(apn);
 | 
			
		||||
    if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
 | 
			
		||||
      SerialMon.println(" fail");
 | 
			
		||||
      delay(10000);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    SerialMon.println(" OK");
 | 
			
		||||
  }
 | 
			
		||||
  SerialMon.println(" OK");
 | 
			
		||||
 | 
			
		||||
  SerialMon.print(F("Performing HTTP GET request... "));
 | 
			
		||||
  int err = http.get(resource);
 | 
			
		||||
@@ -121,16 +149,18 @@ void loop() {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int status = http.responseStatusCode();
 | 
			
		||||
  SerialMon.print(F("Response status code: "));
 | 
			
		||||
  SerialMon.println(status);
 | 
			
		||||
  if (!status) {
 | 
			
		||||
    delay(10000);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  SerialMon.println(F("Response Headers:"));
 | 
			
		||||
  while (http.headerAvailable()) {
 | 
			
		||||
    String headerName = http.readHeaderName();
 | 
			
		||||
    String headerValue = http.readHeaderValue();
 | 
			
		||||
    //SerialMon.println(headerName + " : " + headerValue);
 | 
			
		||||
    SerialMon.println("    " + headerName + " : " + headerValue);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int length = http.contentLength();
 | 
			
		||||
 
 | 
			
		||||
@@ -10,7 +10,7 @@
 | 
			
		||||
 * TinyGSM Getting Started guide:
 | 
			
		||||
 *   http://tiny.cc/tiny-gsm-readme
 | 
			
		||||
 *
 | 
			
		||||
 * SSL/TLS is currently supported only with: SIM8xx, uBlox
 | 
			
		||||
 * SSL/TLS is currently supported only with: SIM8xx, uBlox, ESP8266
 | 
			
		||||
 *
 | 
			
		||||
 * For more HTTP API examples, see ArduinoHttpClient library
 | 
			
		||||
 *
 | 
			
		||||
@@ -18,22 +18,23 @@
 | 
			
		||||
 | 
			
		||||
// Select your modem:
 | 
			
		||||
#define TINY_GSM_MODEM_SIM800
 | 
			
		||||
// #define TINY_GSM_MODEM_SIM900
 | 
			
		||||
// #define TINY_GSM_MODEM_SIM808
 | 
			
		||||
// #define TINY_GSM_MODEM_SIM868
 | 
			
		||||
// #define TINY_GSM_MODEM_UBLOX
 | 
			
		||||
// #define TINY_GSM_MODEM_M95
 | 
			
		||||
// #define TINY_GSM_MODEM_BG96
 | 
			
		||||
// #define TINY_GSM_MODEM_A6
 | 
			
		||||
// #define TINY_GSM_MODEM_A7
 | 
			
		||||
// #define TINY_GSM_MODEM_M590
 | 
			
		||||
// #define TINY_GSM_MODEM_MC60
 | 
			
		||||
// #define TINY_GSM_MODEM_MC60E
 | 
			
		||||
// #define TINY_GSM_MODEM_ESP8266
 | 
			
		||||
// #define TINY_GSM_MODEM_XBEE
 | 
			
		||||
 | 
			
		||||
// Increase RX buffer if needed
 | 
			
		||||
//#define TINY_GSM_RX_BUFFER 512
 | 
			
		||||
// Increase RX buffer to capture the entire response
 | 
			
		||||
// Chips without internal buffering (ESP8266)
 | 
			
		||||
// need enough space in the buffer for the entire response
 | 
			
		||||
// else data will be lost (and the http library will fail).
 | 
			
		||||
#define TINY_GSM_RX_BUFFER 650
 | 
			
		||||
 | 
			
		||||
// See the debugging, if wanted
 | 
			
		||||
//#define TINY_GSM_DEBUG Serial
 | 
			
		||||
//#define LOGGING
 | 
			
		||||
 | 
			
		||||
// Add a reception delay, if needed
 | 
			
		||||
//#define TINY_GSM_YIELD() { delay(1); }
 | 
			
		||||
 | 
			
		||||
#include <TinyGsmClient.h>
 | 
			
		||||
#include <ArduinoHttpClient.h>
 | 
			
		||||
@@ -55,8 +56,10 @@
 | 
			
		||||
// Your GPRS credentials
 | 
			
		||||
// Leave empty, if missing user or pass
 | 
			
		||||
const char apn[]  = "YourAPN";
 | 
			
		||||
const char user[] = "";
 | 
			
		||||
const char pass[] = "";
 | 
			
		||||
const char gprsUser[] = "";
 | 
			
		||||
const char gprsPass[] = "";
 | 
			
		||||
const char wifiSSID[]  = "YourSSID";
 | 
			
		||||
const char wifiPass[] = "SSIDpw";
 | 
			
		||||
 | 
			
		||||
// Server details
 | 
			
		||||
const char server[] = "vsh.pp.ua";
 | 
			
		||||
@@ -78,6 +81,7 @@ void setup() {
 | 
			
		||||
  // Set console baud rate
 | 
			
		||||
  SerialMon.begin(115200);
 | 
			
		||||
  delay(10);
 | 
			
		||||
  SerialMon.println(F("Wait..."));
 | 
			
		||||
 | 
			
		||||
  // Set GSM module baud rate
 | 
			
		||||
  SerialAT.begin(115200);
 | 
			
		||||
@@ -102,6 +106,17 @@ void setup() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
 | 
			
		||||
  if (modem.hasWifi()) {
 | 
			
		||||
    SerialMon.print(F("Setting SSID/password..."));
 | 
			
		||||
    if (!modem.networkConnect(wifiSSID, wifiPass)) {
 | 
			
		||||
      SerialMon.println(" fail");
 | 
			
		||||
      delay(10000);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    SerialMon.println(" OK");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  SerialMon.print(F("Waiting for network..."));
 | 
			
		||||
  if (!modem.waitForNetwork()) {
 | 
			
		||||
    SerialMon.println(" fail");
 | 
			
		||||
@@ -110,14 +125,16 @@ void loop() {
 | 
			
		||||
  }
 | 
			
		||||
  SerialMon.println(" OK");
 | 
			
		||||
 | 
			
		||||
  SerialMon.print(F("Connecting to "));
 | 
			
		||||
  SerialMon.print(apn);
 | 
			
		||||
  if (!modem.gprsConnect(apn, user, pass)) {
 | 
			
		||||
    SerialMon.println(" fail");
 | 
			
		||||
    delay(10000);
 | 
			
		||||
    return;
 | 
			
		||||
  if (modem.hasGPRS()) {
 | 
			
		||||
    SerialMon.print(F("Connecting to "));
 | 
			
		||||
    SerialMon.print(apn);
 | 
			
		||||
    if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
 | 
			
		||||
      SerialMon.println(" fail");
 | 
			
		||||
      delay(10000);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    SerialMon.println(" OK");
 | 
			
		||||
  }
 | 
			
		||||
  SerialMon.println(" OK");
 | 
			
		||||
 | 
			
		||||
  SerialMon.print(F("Performing HTTPS GET request... "));
 | 
			
		||||
  http.connectionKeepAlive(); // Currently, this is needed for HTTPS
 | 
			
		||||
@@ -129,16 +146,18 @@ void loop() {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int status = http.responseStatusCode();
 | 
			
		||||
  SerialMon.print(F("Response status code: "));
 | 
			
		||||
  SerialMon.println(status);
 | 
			
		||||
  if (!status) {
 | 
			
		||||
    delay(10000);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  SerialMon.println(F("Response Headers:"));
 | 
			
		||||
  while (http.headerAvailable()) {
 | 
			
		||||
    String headerName = http.readHeaderName();
 | 
			
		||||
    String headerValue = http.readHeaderValue();
 | 
			
		||||
    //SerialMon.println(headerName + " : " + headerValue);
 | 
			
		||||
    SerialMon.println("    " + headerName + " : " + headerValue);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int length = http.contentLength();
 | 
			
		||||
 
 | 
			
		||||
@@ -27,6 +27,13 @@
 | 
			
		||||
// Increase RX buffer if needed
 | 
			
		||||
//#define TINY_GSM_RX_BUFFER 512
 | 
			
		||||
 | 
			
		||||
// See the debugging, if wanted
 | 
			
		||||
//#define TINY_GSM_DEBUG Serial
 | 
			
		||||
//#define LOGGING
 | 
			
		||||
 | 
			
		||||
// Add a reception delay, if needed
 | 
			
		||||
//#define TINY_GSM_YIELD() { delay(1); }
 | 
			
		||||
 | 
			
		||||
#include <TinyGsmClient.h>
 | 
			
		||||
 | 
			
		||||
// Uncomment this if you want to see all AT commands
 | 
			
		||||
@@ -49,8 +56,10 @@
 | 
			
		||||
// Your GPRS credentials
 | 
			
		||||
// Leave empty, if missing user or pass
 | 
			
		||||
const char apn[]  = "YourAPN";
 | 
			
		||||
const char user[] = "";
 | 
			
		||||
const char pass[] = "";
 | 
			
		||||
const char gprsUser[] = "";
 | 
			
		||||
const char gprsPass[] = "";
 | 
			
		||||
const char wifiSSID[]  = "YourSSID";
 | 
			
		||||
const char wifiPass[] = "SSIDpw";
 | 
			
		||||
 | 
			
		||||
// Server details
 | 
			
		||||
const char server[] = "vsh.pp.ua";
 | 
			
		||||
@@ -76,9 +85,13 @@ void setup() {
 | 
			
		||||
  // Set console baud rate
 | 
			
		||||
  SerialMon.begin(115200);
 | 
			
		||||
  delay(10);
 | 
			
		||||
  SerialMon.println(F("Wait..."));
 | 
			
		||||
 | 
			
		||||
  pinMode(23, OUTPUT);
 | 
			
		||||
  digitalWrite(23, LOW);
 | 
			
		||||
 | 
			
		||||
  // Set GSM module baud rate
 | 
			
		||||
  SerialAT.begin(115200);
 | 
			
		||||
  SerialAT.begin(9600);
 | 
			
		||||
  delay(3000);
 | 
			
		||||
 | 
			
		||||
  // Restart takes quite some time
 | 
			
		||||
@@ -95,6 +108,26 @@ void setup() {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void loop() {
 | 
			
		||||
 | 
			
		||||
  if (modem.hasWifi()) {
 | 
			
		||||
    SerialMon.print(F("Setting SSID/password..."));
 | 
			
		||||
    if (!modem.networkConnect(wifiSSID, wifiPass)) {
 | 
			
		||||
      SerialMon.println(" fail");
 | 
			
		||||
      delay(10000);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    SerialMon.println(" OK");
 | 
			
		||||
  }
 | 
			
		||||
  else if (modem.getModemName().indexOf("XBee") >= 0) {
 | 
			
		||||
    SerialMon.print(F("Setting APN"));
 | 
			
		||||
    if (!modem.gprsConnect(apn)) {
 | 
			
		||||
      SerialMon.println(" fail");
 | 
			
		||||
      delay(10000);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    SerialMon.println(" OK");
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  SerialMon.print(F("Waiting for network..."));
 | 
			
		||||
  if (!modem.waitForNetwork()) {
 | 
			
		||||
    SerialMon.println(" fail");
 | 
			
		||||
@@ -103,14 +136,16 @@ void loop() {
 | 
			
		||||
  }
 | 
			
		||||
  SerialMon.println(" OK");
 | 
			
		||||
 | 
			
		||||
  SerialMon.print(F("Connecting to "));
 | 
			
		||||
  SerialMon.print(apn);
 | 
			
		||||
  if (!modem.gprsConnect(apn, user, pass)) {
 | 
			
		||||
    SerialMon.println(" fail");
 | 
			
		||||
    delay(10000);
 | 
			
		||||
    return;
 | 
			
		||||
  if (modem.hasGPRS()) {
 | 
			
		||||
    SerialMon.print(F("Connecting to "));
 | 
			
		||||
    SerialMon.print(apn);
 | 
			
		||||
    if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
 | 
			
		||||
      SerialMon.println(" fail");
 | 
			
		||||
      delay(10000);
 | 
			
		||||
      return;
 | 
			
		||||
    }
 | 
			
		||||
    SerialMon.println(" OK");
 | 
			
		||||
  }
 | 
			
		||||
  SerialMon.println(" OK");
 | 
			
		||||
 | 
			
		||||
  SerialMon.print(F("Connecting to "));
 | 
			
		||||
  SerialMon.print(server);
 | 
			
		||||
@@ -142,8 +177,14 @@ void loop() {
 | 
			
		||||
  client.stop();
 | 
			
		||||
  SerialMon.println(F("Server disconnected"));
 | 
			
		||||
 | 
			
		||||
  modem.gprsDisconnect();
 | 
			
		||||
  SerialMon.println(F("GPRS disconnected"));
 | 
			
		||||
  if (modem.hasWifi()) {
 | 
			
		||||
    modem.networkDisconnect();
 | 
			
		||||
    SerialMon.println(F("WiFi disconnected"));
 | 
			
		||||
  }
 | 
			
		||||
  else {
 | 
			
		||||
    modem.gprsDisconnect();
 | 
			
		||||
    SerialMon.println(F("GPRS disconnected"));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // Do nothing forevermore
 | 
			
		||||
  while (true) {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user