初始化提交
This commit is contained in:
@@ -0,0 +1,202 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
* NOTE:
|
||||
* Some of the functions may be unavailable for your modem.
|
||||
* Just comment them out.
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
// #define TINY_GSM_MODEM_M590
|
||||
|
||||
// Set serial for debug console (to the Serial Monitor, speed 115200)
|
||||
#define SerialMon Serial
|
||||
|
||||
// Set serial for AT commands (to the module)
|
||||
// Use Hardware Serial on Mega, Leonardo, Micro
|
||||
#define SerialAT Serial1
|
||||
|
||||
// or Software Serial on Uno, Nano
|
||||
//#include <SoftwareSerial.h>
|
||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
|
||||
//#define DUMP_AT_COMMANDS
|
||||
#define TINY_GSM_DEBUG SerialMon
|
||||
|
||||
// Set phone numbers, if you want to test SMS and Calls
|
||||
//#define SMS_TARGET "+380xxxxxxxxx"
|
||||
//#define CALL_TARGET "+380xxxxxxxxx"
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set your reset, enable, power pins here
|
||||
|
||||
delay(3000);
|
||||
|
||||
// Set GSM module baud rate
|
||||
TinyGsmAutoBaud(SerialAT);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
DBG("Initializing modem...");
|
||||
if (!modem.restart()) {
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
DBG("Modem:", modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
|
||||
DBG("Waiting for network...");
|
||||
if (!modem.waitForNetwork()) {
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
if (modem.isNetworkConnected()) {
|
||||
DBG("Network connected");
|
||||
}
|
||||
|
||||
DBG("Connecting to", apn);
|
||||
if (!modem.gprsConnect(apn, user, pass)) {
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
bool res = modem.isGprsConnected();
|
||||
DBG("GPRS status:", res ? "connected" : "not connected");
|
||||
|
||||
String ccid = modem.getSimCCID();
|
||||
DBG("CCID:", ccid);
|
||||
|
||||
String imei = modem.getIMEI();
|
||||
DBG("IMEI:", imei);
|
||||
|
||||
String cop = modem.getOperator();
|
||||
DBG("Operator:", cop);
|
||||
|
||||
IPAddress local = modem.localIP();
|
||||
DBG("Local IP:", local);
|
||||
|
||||
int csq = modem.getSignalQuality();
|
||||
DBG("Signal quality:", csq);
|
||||
|
||||
// This is NOT supported on M590
|
||||
int battLevel = modem.getBattPercent();
|
||||
DBG("Battery lavel:", battLevel);
|
||||
|
||||
// This is only supported on SIMxxx series
|
||||
float battVoltage = modem.getBattVoltage() / 1000.0F;
|
||||
DBG("Battery voltage:", battVoltage);
|
||||
|
||||
// This is only supported on SIMxxx series
|
||||
String gsmLoc = modem.getGsmLocation();
|
||||
DBG("GSM location:", gsmLoc);
|
||||
|
||||
// This is only supported on SIMxxx series
|
||||
String gsmTime = modem.getGSMDateTime(DATE_TIME);
|
||||
DBG("GSM Time:", gsmTime);
|
||||
String gsmDate = modem.getGSMDateTime(DATE_DATE);
|
||||
DBG("GSM Date:", gsmDate);
|
||||
|
||||
String ussd_balance = modem.sendUSSD("*111#");
|
||||
DBG("Balance (USSD):", ussd_balance);
|
||||
|
||||
String ussd_phone_num = modem.sendUSSD("*161#");
|
||||
DBG("Phone number (USSD):", ussd_phone_num);
|
||||
|
||||
#if defined(TINY_GSM_MODEM_SIM808)
|
||||
modem.enableGPS();
|
||||
String gps_raw = modem.getGPSraw();
|
||||
modem.disableGPS();
|
||||
DBG("GPS raw data:", gps_raw);
|
||||
#endif
|
||||
|
||||
#if defined(SMS_TARGET)
|
||||
res = modem.sendSMS(SMS_TARGET, String("Hello from ") + imei);
|
||||
DBG("SMS:", res ? "OK" : "fail");
|
||||
|
||||
// This is only supported on SIMxxx series
|
||||
res = modem.sendSMS_UTF16(SMS_TARGET, u"Привіііт!", 9);
|
||||
DBG("UTF16 SMS:", res ? "OK" : "fail");
|
||||
#endif
|
||||
|
||||
#if defined(CALL_TARGET)
|
||||
DBG("Calling:", CALL_TARGET);
|
||||
|
||||
// This is NOT supported on M590
|
||||
res = modem.callNumber(CALL_TARGET);
|
||||
DBG("Call:", res ? "OK" : "fail");
|
||||
|
||||
if (res) {
|
||||
delay(1000L);
|
||||
|
||||
// Play DTMF A, duration 1000ms
|
||||
modem.dtmfSend('A', 1000);
|
||||
|
||||
// Play DTMF 0..4, default duration (100ms)
|
||||
for (char tone='0'; tone<='4'; tone++) {
|
||||
modem.dtmfSend(tone);
|
||||
}
|
||||
|
||||
delay(5000);
|
||||
|
||||
res = modem.callHangup();
|
||||
DBG("Hang up:", res ? "OK" : "fail");
|
||||
}
|
||||
#endif
|
||||
|
||||
modem.gprsDisconnect();
|
||||
if (!modem.isGprsConnected()) {
|
||||
DBG("GPRS disconnected");
|
||||
} else {
|
||||
DBG("GPRS disconnect: Failed.");
|
||||
}
|
||||
|
||||
// Try to power-off (modem may decide to restart automatically)
|
||||
// To turn off modem completely, please use Reset/Enable pins
|
||||
modem.poweroff();
|
||||
DBG("Poweroff.");
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
modem.maintain();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* For this example, you need to install Blynk library:
|
||||
* https://github.com/blynkkk/blynk-library/releases/latest
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
**************************************************************
|
||||
*
|
||||
* Blynk is a platform with iOS and Android apps to control
|
||||
* Arduino, Raspberry Pi and the likes over the Internet.
|
||||
* You can easily build graphic interfaces for all your
|
||||
* projects by simply dragging and dropping widgets.
|
||||
*
|
||||
* Blynk supports many development boards with WiFi, Ethernet,
|
||||
* GSM, Bluetooth, BLE, USB/Serial connection methods.
|
||||
* See more in Blynk library examples and community forum.
|
||||
*
|
||||
* http://www.blynk.io/
|
||||
*
|
||||
* Change GPRS apm, user, pass, and Blynk auth token to run :)
|
||||
**************************************************************/
|
||||
|
||||
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
|
||||
|
||||
// Default heartbeat interval for GSM is 60
|
||||
// If you want override this value, uncomment and set this option:
|
||||
//#define BLYNK_HEARTBEAT 30
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
// #define TINY_GSM_MODEM_M590
|
||||
// #define TINY_GSM_MODEM_ESP8266
|
||||
// #define TINY_GSM_MODEM_XBEE
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
#include <BlynkSimpleSIM800.h>
|
||||
|
||||
// Set serial for debug console (to the Serial Monitor, default speed 115200)
|
||||
#define SerialMon Serial
|
||||
|
||||
// Hardware Serial on Mega, Leonardo, Micro
|
||||
#define SerialAT Serial1
|
||||
|
||||
// or Software Serial on Uno, Nano
|
||||
//#include <SoftwareSerial.h>
|
||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
// You should get Auth Token in the Blynk App.
|
||||
// Go to the Project Settings (nut icon).
|
||||
const char auth[] = "YourAuthToken";
|
||||
|
||||
TinyGsm modem(SerialAT);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
SerialAT.begin(115200);
|
||||
delay(3000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.println("Initializing modem...");
|
||||
modem.restart();
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
SerialMon.print("Modem: ");
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
|
||||
Blynk.begin(auth, modem, apn, user, pass);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
Blynk.run();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,207 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* For this example, you need to install CRC32 library:
|
||||
* https://github.com/bakercp/CRC32
|
||||
* or from http://librarymanager/all#CRC32+checksum
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
* ATTENTION! Downloading big files requires of knowledge of
|
||||
* the TinyGSM internals and some modem specifics,
|
||||
* so this is for more experienced developers.
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
// #define TINY_GSM_MODEM_M590
|
||||
// #define TINY_GSM_MODEM_ESP8266
|
||||
// #define TINY_GSM_MODEM_XBEE
|
||||
|
||||
// Increase RX buffer if needed
|
||||
#define TINY_GSM_RX_BUFFER 1024
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
#include <CRC32.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
|
||||
|
||||
// or Software Serial on Uno, Nano
|
||||
//#include <SoftwareSerial.h>
|
||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const int port = 80;
|
||||
|
||||
const char resource[] = "/TinyGSM/test_1k.bin";
|
||||
uint32_t knownCRC32 = 0x6f50d767;
|
||||
uint32_t knownFileSize = 1024; // In case server does not send it
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
TinyGsmClient client(modem);
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
SerialAT.begin(115200);
|
||||
delay(3000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.println(F("Initializing modem..."));
|
||||
modem.restart();
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
SerialMon.print(F("Modem: "));
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
}
|
||||
|
||||
void printPercent(uint32_t readLength, uint32_t contentLength) {
|
||||
// If we know the total length
|
||||
if (contentLength != -1) {
|
||||
SerialMon.print("\r ");
|
||||
SerialMon.print((100.0 * readLength) / contentLength);
|
||||
SerialMon.print('%');
|
||||
} else {
|
||||
SerialMon.println(readLength);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
SerialMon.print(F("Waiting for network..."));
|
||||
if (!modem.waitForNetwork()) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, user, pass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(server);
|
||||
if (!client.connect(server, port)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.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");
|
||||
|
||||
long timeout = millis();
|
||||
while (client.available() == 0) {
|
||||
if (millis() - timeout > 5000L) {
|
||||
SerialMon.println(F(">>> Client Timeout !"));
|
||||
client.stop();
|
||||
delay(10000L);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
SerialMon.println(F("Reading response header"));
|
||||
uint32_t contentLength = knownFileSize;
|
||||
|
||||
while (client.available()) {
|
||||
String line = client.readStringUntil('\n');
|
||||
line.trim();
|
||||
//SerialMon.println(line); // Uncomment this to show response header
|
||||
line.toLowerCase();
|
||||
if (line.startsWith("content-length:")) {
|
||||
contentLength = line.substring(line.lastIndexOf(':') + 1).toInt();
|
||||
} else if (line.length() == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SerialMon.println(F("Reading response data"));
|
||||
timeout = millis();
|
||||
uint32_t readLength = 0;
|
||||
CRC32 crc;
|
||||
|
||||
unsigned long timeElapsed = millis();
|
||||
printPercent(readLength, contentLength);
|
||||
while (readLength < contentLength && client.connected() && millis() - timeout < 10000L) {
|
||||
while (client.available()) {
|
||||
uint8_t c = client.read();
|
||||
//SerialMon.print((char)c); // Uncomment this to show data
|
||||
crc.update(c);
|
||||
readLength++;
|
||||
if (readLength % (contentLength / 13) == 0) {
|
||||
printPercent(readLength, contentLength);
|
||||
}
|
||||
timeout = millis();
|
||||
}
|
||||
}
|
||||
printPercent(readLength, contentLength);
|
||||
timeElapsed = millis() - timeElapsed;
|
||||
SerialMon.println();
|
||||
|
||||
// Shutdown
|
||||
|
||||
client.stop();
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
|
||||
float duration = float(timeElapsed) / 1000;
|
||||
|
||||
SerialMon.println();
|
||||
SerialMon.print("Content-Length: "); SerialMon.println(contentLength);
|
||||
SerialMon.print("Actually read: "); SerialMon.println(readLength);
|
||||
SerialMon.print("Calc. CRC32: 0x"); SerialMon.println(crc.finalize(), HEX);
|
||||
SerialMon.print("Known CRC32: 0x"); SerialMon.println(knownCRC32, HEX);
|
||||
SerialMon.print("Duration: "); SerialMon.print(duration); SerialMon.println("s");
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
160
arduino-cli/libraries/TinyGSM/examples/HttpClient/HttpClient.ino
Normal file
160
arduino-cli/libraries/TinyGSM/examples/HttpClient/HttpClient.ino
Normal file
@@ -0,0 +1,160 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* This sketch connects to a website and downloads a page.
|
||||
* It can be used to perform HTTP/RESTful API calls.
|
||||
*
|
||||
* For this example, you need to install ArduinoHttpClient library:
|
||||
* https://github.com/arduino-libraries/ArduinoHttpClient
|
||||
* or from http://librarymanager/all#ArduinoHttpClient
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
* For more HTTP API examples, see ArduinoHttpClient library
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
// #define TINY_GSM_MODEM_M590
|
||||
// #define TINY_GSM_MODEM_ESP8266
|
||||
|
||||
// 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
|
||||
|
||||
// or Software Serial on Uno, Nano
|
||||
//#include <SoftwareSerial.h>
|
||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
// 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, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
TinyGsmClient client(modem);
|
||||
HttpClient http(client, server, port);
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
SerialAT.begin(115200);
|
||||
delay(3000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.println(F("Initializing modem..."));
|
||||
modem.restart();
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
SerialMon.print(F("Modem: "));
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
SerialMon.print(F("Waiting for network..."));
|
||||
if (!modem.waitForNetwork()) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, user, pass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Performing HTTP GET request... "));
|
||||
int err = http.get(resource);
|
||||
if (err != 0) {
|
||||
SerialMon.println(F("failed to connect"));
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
int status = http.responseStatusCode();
|
||||
SerialMon.println(status);
|
||||
if (!status) {
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
while (http.headerAvailable()) {
|
||||
String headerName = http.readHeaderName();
|
||||
String headerValue = http.readHeaderValue();
|
||||
//SerialMon.println(headerName + " : " + headerValue);
|
||||
}
|
||||
|
||||
int length = http.contentLength();
|
||||
if (length >= 0) {
|
||||
SerialMon.print(F("Content length is: "));
|
||||
SerialMon.println(length);
|
||||
}
|
||||
if (http.isResponseChunked()) {
|
||||
SerialMon.println(F("The response is chunked"));
|
||||
}
|
||||
|
||||
String body = http.responseBody();
|
||||
SerialMon.println(F("Response:"));
|
||||
SerialMon.println(body);
|
||||
|
||||
SerialMon.print(F("Body length is: "));
|
||||
SerialMon.println(body.length());
|
||||
|
||||
// Shutdown
|
||||
|
||||
http.stop();
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,162 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* This sketch connects to a website and downloads a page.
|
||||
* It can be used to perform HTTP/RESTful API calls.
|
||||
*
|
||||
* For this example, you need to install ArduinoHttpClient library:
|
||||
* https://github.com/arduino-libraries/ArduinoHttpClient
|
||||
* or from http://librarymanager/all#ArduinoHttpClient
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
* SSL/TLS is currently supported only with: SIM8xx, uBlox
|
||||
*
|
||||
* For more HTTP API examples, see ArduinoHttpClient library
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
|
||||
// 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
|
||||
|
||||
// or Software Serial on Uno, Nano
|
||||
//#include <SoftwareSerial.h>
|
||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char resource[] = "/TinyGSM/logo.txt";
|
||||
const int port = 443;
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
TinyGsmClientSecure client(modem);
|
||||
HttpClient http(client, server, port);
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
SerialAT.begin(115200);
|
||||
delay(3000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.println(F("Initializing modem..."));
|
||||
modem.restart();
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
SerialMon.print(F("Modem: "));
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
|
||||
if (!modem.hasSSL()) {
|
||||
SerialMon.println(F("SSL is not supported by this modem"));
|
||||
while(true) { delay(1000); }
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
SerialMon.print(F("Waiting for network..."));
|
||||
if (!modem.waitForNetwork()) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, user, pass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Performing HTTPS GET request... "));
|
||||
http.connectionKeepAlive(); // Currently, this is needed for HTTPS
|
||||
int err = http.get(resource);
|
||||
if (err != 0) {
|
||||
SerialMon.println(F("failed to connect"));
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
int status = http.responseStatusCode();
|
||||
SerialMon.println(status);
|
||||
if (!status) {
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
while (http.headerAvailable()) {
|
||||
String headerName = http.readHeaderName();
|
||||
String headerValue = http.readHeaderValue();
|
||||
//SerialMon.println(headerName + " : " + headerValue);
|
||||
}
|
||||
|
||||
int length = http.contentLength();
|
||||
if (length >= 0) {
|
||||
SerialMon.print(F("Content length is: "));
|
||||
SerialMon.println(length);
|
||||
}
|
||||
if (http.isResponseChunked()) {
|
||||
SerialMon.println(F("The response is chunked"));
|
||||
}
|
||||
|
||||
String body = http.responseBody();
|
||||
SerialMon.println(F("Response:"));
|
||||
SerialMon.println(body);
|
||||
|
||||
SerialMon.print(F("Body length is: "));
|
||||
SerialMon.println(body.length());
|
||||
|
||||
// Shutdown
|
||||
|
||||
http.stop();
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
174
arduino-cli/libraries/TinyGSM/examples/MqttClient/MqttClient.ino
Normal file
174
arduino-cli/libraries/TinyGSM/examples/MqttClient/MqttClient.ino
Normal file
@@ -0,0 +1,174 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* For this example, you need to install PubSubClient library:
|
||||
* https://github.com/knolleary/pubsubclient
|
||||
* or from http://librarymanager/all#PubSubClient
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
* For more MQTT examples, see PubSubClient library
|
||||
*
|
||||
**************************************************************
|
||||
* Use Mosquitto client tools to work with MQTT
|
||||
* Ubuntu/Linux: sudo apt-get install mosquitto-clients
|
||||
* Windows: https://mosquitto.org/download/
|
||||
*
|
||||
* Subscribe for messages:
|
||||
* mosquitto_sub -h test.mosquitto.org -t GsmClientTest/init -t GsmClientTest/ledStatus -q 1
|
||||
* Toggle led:
|
||||
* mosquitto_pub -h test.mosquitto.org -t GsmClientTest/led -q 1 -m "toggle"
|
||||
*
|
||||
* You can use Node-RED for wiring together MQTT-enabled devices
|
||||
* https://nodered.org/
|
||||
* Also, take a look at these additional Node-RED modules:
|
||||
* node-red-contrib-blynk-ws
|
||||
* node-red-dashboard
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
// #define TINY_GSM_MODEM_M590
|
||||
// #define TINY_GSM_MODEM_ESP8266
|
||||
// #define TINY_GSM_MODEM_XBEE
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
#include <PubSubClient.h>
|
||||
|
||||
// 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
|
||||
|
||||
// or Software Serial on Uno, Nano
|
||||
//#include <SoftwareSerial.h>
|
||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
// MQTT details
|
||||
const char* broker = "test.mosquitto.org";
|
||||
|
||||
const char* topicLed = "GsmClientTest/led";
|
||||
const char* topicInit = "GsmClientTest/init";
|
||||
const char* topicLedStatus = "GsmClientTest/ledStatus";
|
||||
|
||||
TinyGsm modem(SerialAT);
|
||||
TinyGsmClient client(modem);
|
||||
PubSubClient mqtt(client);
|
||||
|
||||
#define LED_PIN 13
|
||||
int ledStatus = LOW;
|
||||
|
||||
long lastReconnectAttempt = 0;
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_PIN, OUTPUT);
|
||||
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
SerialAT.begin(115200);
|
||||
delay(3000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.println("Initializing modem...");
|
||||
modem.restart();
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
SerialMon.print("Modem: ");
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
|
||||
SerialMon.print("Waiting for network...");
|
||||
if (!modem.waitForNetwork()) {
|
||||
SerialMon.println(" fail");
|
||||
while (true);
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print("Connecting to ");
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, user, pass)) {
|
||||
SerialMon.println(" fail");
|
||||
while (true);
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
// MQTT Broker setup
|
||||
mqtt.setServer(broker, 1883);
|
||||
mqtt.setCallback(mqttCallback);
|
||||
}
|
||||
|
||||
boolean mqttConnect() {
|
||||
SerialMon.print("Connecting to ");
|
||||
SerialMon.print(broker);
|
||||
|
||||
// Connect to MQTT Broker
|
||||
boolean status = mqtt.connect("GsmClientTest");
|
||||
|
||||
// Or, if you want to authenticate MQTT:
|
||||
//boolean status = mqtt.connect("GsmClientName", "mqtt_user", "mqtt_pass");
|
||||
|
||||
if (status == false) {
|
||||
SerialMon.println(" fail");
|
||||
return false;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
mqtt.publish(topicInit, "GsmClientTest started");
|
||||
mqtt.subscribe(topicLed);
|
||||
return mqtt.connected();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
if (!mqtt.connected()) {
|
||||
SerialMon.println("=== MQTT NOT CONNECTED ===");
|
||||
// Reconnect every 10 seconds
|
||||
unsigned long t = millis();
|
||||
if (t - lastReconnectAttempt > 10000L) {
|
||||
lastReconnectAttempt = t;
|
||||
if (mqttConnect()) {
|
||||
lastReconnectAttempt = 0;
|
||||
}
|
||||
}
|
||||
delay(100);
|
||||
return;
|
||||
}
|
||||
|
||||
mqtt.loop();
|
||||
}
|
||||
|
||||
void mqttCallback(char* topic, byte* payload, unsigned int len) {
|
||||
SerialMon.print("Message arrived [");
|
||||
SerialMon.print(topic);
|
||||
SerialMon.print("]: ");
|
||||
SerialMon.write(payload, len);
|
||||
SerialMon.println();
|
||||
|
||||
// Only proceed if incoming message's topic matches
|
||||
if (String(topic) == topicLed) {
|
||||
ledStatus = !ledStatus;
|
||||
digitalWrite(LED_PIN, ledStatus);
|
||||
mqtt.publish(topicLedStatus, ledStatus ? "1" : "0");
|
||||
}
|
||||
}
|
||||
|
||||
148
arduino-cli/libraries/TinyGSM/examples/WebClient/WebClient.ino
Normal file
148
arduino-cli/libraries/TinyGSM/examples/WebClient/WebClient.ino
Normal file
@@ -0,0 +1,148 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* This sketch connects to a website and downloads a page.
|
||||
* It can be used to perform HTTP/RESTful API calls.
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Select your modem:
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
// #define TINY_GSM_MODEM_SIM808
|
||||
// #define TINY_GSM_MODEM_SIM900
|
||||
// #define TINY_GSM_MODEM_UBLOX
|
||||
// #define TINY_GSM_MODEM_BG96
|
||||
// #define TINY_GSM_MODEM_A6
|
||||
// #define TINY_GSM_MODEM_A7
|
||||
// #define TINY_GSM_MODEM_M590
|
||||
// #define TINY_GSM_MODEM_ESP8266
|
||||
|
||||
// Increase RX buffer if needed
|
||||
//#define TINY_GSM_RX_BUFFER 512
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
|
||||
// Uncomment this if you want to see all AT commands
|
||||
//#define DUMP_AT_COMMANDS
|
||||
|
||||
// Uncomment this if you want to use SSL
|
||||
//#define USE_SSL
|
||||
|
||||
// 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
|
||||
|
||||
// or Software Serial on Uno, Nano
|
||||
//#include <SoftwareSerial.h>
|
||||
//SoftwareSerial SerialAT(2, 3); // RX, TX
|
||||
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char resource[] = "/TinyGSM/logo.txt";
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SSL
|
||||
TinyGsmClientSecure client(modem);
|
||||
const int port = 443;
|
||||
#else
|
||||
TinyGsmClient client(modem);
|
||||
const int port = 80;
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
SerialAT.begin(115200);
|
||||
delay(3000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.println(F("Initializing modem..."));
|
||||
modem.restart();
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
SerialMon.print(F("Modem: "));
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
SerialMon.print(F("Waiting for network..."));
|
||||
if (!modem.waitForNetwork()) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, user, pass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(server);
|
||||
if (!client.connect(server, port)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.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();
|
||||
SerialMon.print(c);
|
||||
timeout = millis();
|
||||
}
|
||||
}
|
||||
SerialMon.println();
|
||||
|
||||
// Shutdown
|
||||
|
||||
client.stop();
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,135 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* This sketch connects to a website and downloads a page.
|
||||
* It can be used to perform HTTP/RESTful API calls.
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Hologram Dash uses UBLOX U2 modems
|
||||
#define TINY_GSM_MODEM_UBLOX
|
||||
|
||||
// Increase RX buffer if needed
|
||||
//#define TINY_GSM_RX_BUFFER 512
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
|
||||
// Uncomment this if you want to see all AT commands
|
||||
//#define DUMP_AT_COMMANDS
|
||||
|
||||
// Uncomment this if you want to use SSL
|
||||
//#define USE_SSL
|
||||
|
||||
// Set serial for debug console (to the Serial Monitor, speed 115200)
|
||||
#define SerialMon Serial
|
||||
|
||||
// We'll be using SerialSystem in Passthrough mode
|
||||
#define SerialAT SerialSystem
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char resource[] = "/TinyGSM/logo.txt";
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm mdm(debugger);
|
||||
#else
|
||||
TinyGsm mdm(SerialAT);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SSL
|
||||
TinyGsmClientSecure client(mdm);
|
||||
const int port = 443;
|
||||
#else
|
||||
TinyGsmClient client(mdm);
|
||||
const int port = 80;
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set up Passthrough
|
||||
HologramCloud.enterPassthrough();
|
||||
delay(3000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.println(F("Initializing modem..."));
|
||||
mdm.restart();
|
||||
|
||||
String modemInfo = mdm.getModemInfo();
|
||||
SerialMon.print(F("Modem: "));
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//mdm.simUnlock("1234");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
SerialMon.print(F("Waiting for network..."));
|
||||
if (!mdm.waitForNetwork()) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!mdm.gprsConnect(apn, user, pass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(server);
|
||||
if (!client.connect(server, port)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.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();
|
||||
SerialMon.print(c);
|
||||
timeout = millis();
|
||||
}
|
||||
}
|
||||
SerialMon.println();
|
||||
|
||||
// Shutdown
|
||||
|
||||
client.stop();
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
mdm.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,160 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* This sketch connects to a website and downloads a page.
|
||||
* It can be used to perform HTTP/RESTful API calls.
|
||||
*
|
||||
* For this example, you need to install ArduinoHttpClient library:
|
||||
* https://github.com/arduino-libraries/ArduinoHttpClient
|
||||
* or from http://librarymanager/all#ArduinoHttpClient
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
* For more HTTP API examples, see ArduinoHttpClient library
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// Industruino uses SIM800H
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
|
||||
// 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
|
||||
|
||||
// Uncomment this if you want to use SSL
|
||||
//#define USE_SSL
|
||||
|
||||
// Set serial for debug console (to the Serial Monitor, speed 115200)
|
||||
#define SerialMon SerialUSB
|
||||
|
||||
// Select Serial1 or Serial depending on your module configuration
|
||||
#define SerialAT Serial1
|
||||
|
||||
// Your GPRS credentials
|
||||
// Leave empty, if missing user or pass
|
||||
const char apn[] = "YourAPN";
|
||||
const char user[] = "";
|
||||
const char pass[] = "";
|
||||
|
||||
// Server details
|
||||
const char server[] = "vsh.pp.ua";
|
||||
const char resource[] = "/TinyGSM/logo.txt";
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
#ifdef USE_SSL
|
||||
TinyGsmClientSecure client(modem);
|
||||
HttpClient http(client, server, 443);
|
||||
#else
|
||||
TinyGsmClient client(modem);
|
||||
HttpClient http(client, server, 80);
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
// Turn on modem with 1 second pulse on D6
|
||||
pinMode(6, OUTPUT);
|
||||
digitalWrite(6, HIGH);
|
||||
delay(1000);
|
||||
digitalWrite(6, LOW);
|
||||
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
SerialAT.begin(115200);
|
||||
delay(3000);
|
||||
|
||||
// Restart takes quite some time
|
||||
// To skip it, call init() instead of restart()
|
||||
SerialMon.println(F("Initializing modem..."));
|
||||
modem.restart();
|
||||
|
||||
String modemInfo = modem.getModemInfo();
|
||||
SerialMon.print(F("Modem: "));
|
||||
SerialMon.println(modemInfo);
|
||||
|
||||
// Unlock your SIM card with a PIN
|
||||
//modem.simUnlock("1234");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
SerialMon.print(F("Waiting for network..."));
|
||||
if (!modem.waitForNetwork()) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Connecting to "));
|
||||
SerialMon.print(apn);
|
||||
if (!modem.gprsConnect(apn, user, pass)) {
|
||||
SerialMon.println(" fail");
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
SerialMon.println(" OK");
|
||||
|
||||
SerialMon.print(F("Performing HTTP GET request... "));
|
||||
int err = http.get(resource);
|
||||
if (err != 0) {
|
||||
SerialMon.println(F("failed to connect"));
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
int status = http.responseStatusCode();
|
||||
SerialMon.println(status);
|
||||
if (!status) {
|
||||
delay(10000);
|
||||
return;
|
||||
}
|
||||
|
||||
while (http.headerAvailable()) {
|
||||
String headerName = http.readHeaderName();
|
||||
String headerValue = http.readHeaderValue();
|
||||
//SerialMon.println(headerName + " : " + headerValue);
|
||||
}
|
||||
|
||||
int length = http.contentLength();
|
||||
if (length >= 0) {
|
||||
SerialMon.print(F("Content length is: "));
|
||||
SerialMon.println(length);
|
||||
}
|
||||
if (http.isResponseChunked()) {
|
||||
SerialMon.println(F("The response is chunked"));
|
||||
}
|
||||
|
||||
String body = http.responseBody();
|
||||
SerialMon.println(F("Response:"));
|
||||
SerialMon.println(body);
|
||||
|
||||
SerialMon.print(F("Body length is: "));
|
||||
SerialMon.println(body.length());
|
||||
|
||||
// Shutdown
|
||||
|
||||
http.stop();
|
||||
SerialMon.println(F("Server disconnected"));
|
||||
|
||||
modem.gprsDisconnect();
|
||||
SerialMon.println(F("GPRS disconnected"));
|
||||
|
||||
// Do nothing forevermore
|
||||
while (true) {
|
||||
delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
const char cert[] PROGMEM =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
"MIIF2DCCA8CgAwIBAgIQTKr5yttjb+Af907YWwOGnTANBgkqhkiG9w0BAQwFADCB\n"
|
||||
"hTELMAkGA1UEBhMCR0IxGzAZBgNVBAgTEkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4G\n"
|
||||
"A1UEBxMHU2FsZm9yZDEaMBgGA1UEChMRQ09NT0RPIENBIExpbWl0ZWQxKzApBgNV\n"
|
||||
"BAMTIkNPTU9ETyBSU0EgQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwHhcNMTAwMTE5\n"
|
||||
"MDAwMDAwWhcNMzgwMTE4MjM1OTU5WjCBhTELMAkGA1UEBhMCR0IxGzAZBgNVBAgT\n"
|
||||
"EkdyZWF0ZXIgTWFuY2hlc3RlcjEQMA4GA1UEBxMHU2FsZm9yZDEaMBgGA1UEChMR\n"
|
||||
"Q09NT0RPIENBIExpbWl0ZWQxKzApBgNVBAMTIkNPTU9ETyBSU0EgQ2VydGlmaWNh\n"
|
||||
"dGlvbiBBdXRob3JpdHkwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQCR\n"
|
||||
"6FSS0gpWsawNJN3Fz0RndJkrN6N9I3AAcbxT38T6KhKPS38QVr2fcHK3YX/JSw8X\n"
|
||||
"pz3jsARh7v8Rl8f0hj4K+j5c+ZPmNHrZFGvnnLOFoIJ6dq9xkNfs/Q36nGz637CC\n"
|
||||
"9BR++b7Epi9Pf5l/tfxnQ3K9DADWietrLNPtj5gcFKt+5eNu/Nio5JIk2kNrYrhV\n"
|
||||
"/erBvGy2i/MOjZrkm2xpmfh4SDBF1a3hDTxFYPwyllEnvGfDyi62a+pGx8cgoLEf\n"
|
||||
"Zd5ICLqkTqnyg0Y3hOvozIFIQ2dOciqbXL1MGyiKXCJ7tKuY2e7gUYPDCUZObT6Z\n"
|
||||
"+pUX2nwzV0E8jVHtC7ZcryxjGt9XyD+86V3Em69FmeKjWiS0uqlWPc9vqv9JWL7w\n"
|
||||
"qP/0uK3pN/u6uPQLOvnoQ0IeidiEyxPx2bvhiWC4jChWrBQdnArncevPDt09qZah\n"
|
||||
"SL0896+1DSJMwBGB7FY79tOi4lu3sgQiUpWAk2nojkxl8ZEDLXB0AuqLZxUpaVIC\n"
|
||||
"u9ffUGpVRr+goyhhf3DQw6KqLCGqR84onAZFdr+CGCe01a60y1Dma/RMhnEw6abf\n"
|
||||
"Fobg2P9A3fvQQoh/ozM6LlweQRGBY84YcWsr7KaKtzFcOmpH4MN5WdYgGq/yapiq\n"
|
||||
"crxXStJLnbsQ/LBMQeXtHT1eKJ2czL+zUdqnR+WEUwIDAQABo0IwQDAdBgNVHQ4E\n"
|
||||
"FgQUu69+Aj36pvE8hI6t7jiY7NkyMtQwDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB\n"
|
||||
"/wQFMAMBAf8wDQYJKoZIhvcNAQEMBQADggIBAArx1UaEt65Ru2yyTUEUAJNMnMvl\n"
|
||||
"wFTPoCWOAvn9sKIN9SCYPBMtrFaisNZ+EZLpLrqeLppysb0ZRGxhNaKatBYSaVqM\n"
|
||||
"4dc+pBroLwP0rmEdEBsqpIt6xf4FpuHA1sj+nq6PK7o9mfjYcwlYRm6mnPTXJ9OV\n"
|
||||
"2jeDchzTc+CiR5kDOF3VSXkAKRzH7JsgHAckaVd4sjn8OoSgtZx8jb8uk2Intzna\n"
|
||||
"FxiuvTwJaP+EmzzV1gsD41eeFPfR60/IvYcjt7ZJQ3mFXLrrkguhxuhoqEwWsRqZ\n"
|
||||
"CuhTLJK7oQkYdQxlqHvLI7cawiiFwxv/0Cti76R7CZGYZ4wUAc1oBmpjIXUDgIiK\n"
|
||||
"boHGhfKppC3n9KUkEEeDys30jXlYsQab5xoq2Z0B15R97QNKyvDb6KkBPvVWmcke\n"
|
||||
"jkk9u+UJueBPSZI9FoJAzMxZxuY67RIuaTxslbH9qh17f4a+Hg4yRvv7E491f0yL\n"
|
||||
"S0Zj/gA0QHDBw7mh3aZw4gSzQbzpgJHqZJx64SIDqZxubw5lT2yHh17zbqD5daWb\n"
|
||||
"QOhTsiedSrnAdyGN/4fy3ryM7xfft0kL0fJuMAsaDk527RH89elWsn2/x20Kk4yl\n"
|
||||
"0MC2Hb46TpSi125sC8KKfPog88Tk5c0NqMuRkrF8hey1FGlmDoLnzc7ILaZRfyHB\n"
|
||||
"NVOFBkpdn627G190\n"
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
const char cert[] PROGMEM =
|
||||
{
|
||||
0x30, 0x82, 0x03, 0x4a, 0x30, 0x82, 0x02, 0x32, 0xa0, 0x03, 0x02, 0x01,
|
||||
0x02, 0x02, 0x10, 0x44, 0xaf, 0xb0, 0x80, 0xd6, 0xa3, 0x27, 0xba, 0x89,
|
||||
0x30, 0x39, 0x86, 0x2e, 0xf8, 0x40, 0x6b, 0x30, 0x0d, 0x06, 0x09, 0x2a,
|
||||
0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x30, 0x3f,
|
||||
0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b, 0x44,
|
||||
0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x61,
|
||||
0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20, 0x43,
|
||||
0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13,
|
||||
0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41,
|
||||
0x20, 0x58, 0x33, 0x30, 0x1e, 0x17, 0x0d, 0x30, 0x30, 0x30, 0x39, 0x33,
|
||||
0x30, 0x32, 0x31, 0x31, 0x32, 0x31, 0x39, 0x5a, 0x17, 0x0d, 0x32, 0x31,
|
||||
0x30, 0x39, 0x33, 0x30, 0x31, 0x34, 0x30, 0x31, 0x31, 0x35, 0x5a, 0x30,
|
||||
0x3f, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x1b,
|
||||
0x44, 0x69, 0x67, 0x69, 0x74, 0x61, 0x6c, 0x20, 0x53, 0x69, 0x67, 0x6e,
|
||||
0x61, 0x74, 0x75, 0x72, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74, 0x20,
|
||||
0x43, 0x6f, 0x2e, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, 0x04, 0x03,
|
||||
0x13, 0x0e, 0x44, 0x53, 0x54, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43,
|
||||
0x41, 0x20, 0x58, 0x33, 0x30, 0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09,
|
||||
0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03,
|
||||
0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01,
|
||||
0x00, 0xdf, 0xaf, 0xe9, 0x97, 0x50, 0x08, 0x83, 0x57, 0xb4, 0xcc, 0x62,
|
||||
0x65, 0xf6, 0x90, 0x82, 0xec, 0xc7, 0xd3, 0x2c, 0x6b, 0x30, 0xca, 0x5b,
|
||||
0xec, 0xd9, 0xc3, 0x7d, 0xc7, 0x40, 0xc1, 0x18, 0x14, 0x8b, 0xe0, 0xe8,
|
||||
0x33, 0x76, 0x49, 0x2a, 0xe3, 0x3f, 0x21, 0x49, 0x93, 0xac, 0x4e, 0x0e,
|
||||
0xaf, 0x3e, 0x48, 0xcb, 0x65, 0xee, 0xfc, 0xd3, 0x21, 0x0f, 0x65, 0xd2,
|
||||
0x2a, 0xd9, 0x32, 0x8f, 0x8c, 0xe5, 0xf7, 0x77, 0xb0, 0x12, 0x7b, 0xb5,
|
||||
0x95, 0xc0, 0x89, 0xa3, 0xa9, 0xba, 0xed, 0x73, 0x2e, 0x7a, 0x0c, 0x06,
|
||||
0x32, 0x83, 0xa2, 0x7e, 0x8a, 0x14, 0x30, 0xcd, 0x11, 0xa0, 0xe1, 0x2a,
|
||||
0x38, 0xb9, 0x79, 0x0a, 0x31, 0xfd, 0x50, 0xbd, 0x80, 0x65, 0xdf, 0xb7,
|
||||
0x51, 0x63, 0x83, 0xc8, 0xe2, 0x88, 0x61, 0xea, 0x4b, 0x61, 0x81, 0xec,
|
||||
0x52, 0x6b, 0xb9, 0xa2, 0xe2, 0x4b, 0x1a, 0x28, 0x9f, 0x48, 0xa3, 0x9e,
|
||||
0x0c, 0xda, 0x09, 0x8e, 0x3e, 0x17, 0x2e, 0x1e, 0xdd, 0x20, 0xdf, 0x5b,
|
||||
0xc6, 0x2a, 0x8a, 0xab, 0x2e, 0xbd, 0x70, 0xad, 0xc5, 0x0b, 0x1a, 0x25,
|
||||
0x90, 0x74, 0x72, 0xc5, 0x7b, 0x6a, 0xab, 0x34, 0xd6, 0x30, 0x89, 0xff,
|
||||
0xe5, 0x68, 0x13, 0x7b, 0x54, 0x0b, 0xc8, 0xd6, 0xae, 0xec, 0x5a, 0x9c,
|
||||
0x92, 0x1e, 0x3d, 0x64, 0xb3, 0x8c, 0xc6, 0xdf, 0xbf, 0xc9, 0x41, 0x70,
|
||||
0xec, 0x16, 0x72, 0xd5, 0x26, 0xec, 0x38, 0x55, 0x39, 0x43, 0xd0, 0xfc,
|
||||
0xfd, 0x18, 0x5c, 0x40, 0xf1, 0x97, 0xeb, 0xd5, 0x9a, 0x9b, 0x8d, 0x1d,
|
||||
0xba, 0xda, 0x25, 0xb9, 0xc6, 0xd8, 0xdf, 0xc1, 0x15, 0x02, 0x3a, 0xab,
|
||||
0xda, 0x6e, 0xf1, 0x3e, 0x2e, 0xf5, 0x5c, 0x08, 0x9c, 0x3c, 0xd6, 0x83,
|
||||
0x69, 0xe4, 0x10, 0x9b, 0x19, 0x2a, 0xb6, 0x29, 0x57, 0xe3, 0xe5, 0x3d,
|
||||
0x9b, 0x9f, 0xf0, 0x02, 0x5d, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42,
|
||||
0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff,
|
||||
0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55,
|
||||
0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30,
|
||||
0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xc4, 0xa7,
|
||||
0xb1, 0xa4, 0x7b, 0x2c, 0x71, 0xfa, 0xdb, 0xe1, 0x4b, 0x90, 0x75, 0xff,
|
||||
0xc4, 0x15, 0x60, 0x85, 0x89, 0x10, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86,
|
||||
0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x82, 0x01,
|
||||
0x01, 0x00, 0xa3, 0x1a, 0x2c, 0x9b, 0x17, 0x00, 0x5c, 0xa9, 0x1e, 0xee,
|
||||
0x28, 0x66, 0x37, 0x3a, 0xbf, 0x83, 0xc7, 0x3f, 0x4b, 0xc3, 0x09, 0xa0,
|
||||
0x95, 0x20, 0x5d, 0xe3, 0xd9, 0x59, 0x44, 0xd2, 0x3e, 0x0d, 0x3e, 0xbd,
|
||||
0x8a, 0x4b, 0xa0, 0x74, 0x1f, 0xce, 0x10, 0x82, 0x9c, 0x74, 0x1a, 0x1d,
|
||||
0x7e, 0x98, 0x1a, 0xdd, 0xcb, 0x13, 0x4b, 0xb3, 0x20, 0x44, 0xe4, 0x91,
|
||||
0xe9, 0xcc, 0xfc, 0x7d, 0xa5, 0xdb, 0x6a, 0xe5, 0xfe, 0xe6, 0xfd, 0xe0,
|
||||
0x4e, 0xdd, 0xb7, 0x00, 0x3a, 0xb5, 0x70, 0x49, 0xaf, 0xf2, 0xe5, 0xeb,
|
||||
0x02, 0xf1, 0xd1, 0x02, 0x8b, 0x19, 0xcb, 0x94, 0x3a, 0x5e, 0x48, 0xc4,
|
||||
0x18, 0x1e, 0x58, 0x19, 0x5f, 0x1e, 0x02, 0x5a, 0xf0, 0x0c, 0xf1, 0xb1,
|
||||
0xad, 0xa9, 0xdc, 0x59, 0x86, 0x8b, 0x6e, 0xe9, 0x91, 0xf5, 0x86, 0xca,
|
||||
0xfa, 0xb9, 0x66, 0x33, 0xaa, 0x59, 0x5b, 0xce, 0xe2, 0xa7, 0x16, 0x73,
|
||||
0x47, 0xcb, 0x2b, 0xcc, 0x99, 0xb0, 0x37, 0x48, 0xcf, 0xe3, 0x56, 0x4b,
|
||||
0xf5, 0xcf, 0x0f, 0x0c, 0x72, 0x32, 0x87, 0xc6, 0xf0, 0x44, 0xbb, 0x53,
|
||||
0x72, 0x6d, 0x43, 0xf5, 0x26, 0x48, 0x9a, 0x52, 0x67, 0xb7, 0x58, 0xab,
|
||||
0xfe, 0x67, 0x76, 0x71, 0x78, 0xdb, 0x0d, 0xa2, 0x56, 0x14, 0x13, 0x39,
|
||||
0x24, 0x31, 0x85, 0xa2, 0xa8, 0x02, 0x5a, 0x30, 0x47, 0xe1, 0xdd, 0x50,
|
||||
0x07, 0xbc, 0x02, 0x09, 0x90, 0x00, 0xeb, 0x64, 0x63, 0x60, 0x9b, 0x16,
|
||||
0xbc, 0x88, 0xc9, 0x12, 0xe6, 0xd2, 0x7d, 0x91, 0x8b, 0xf9, 0x3d, 0x32,
|
||||
0x8d, 0x65, 0xb4, 0xe9, 0x7c, 0xb1, 0x57, 0x76, 0xea, 0xc5, 0xb6, 0x28,
|
||||
0x39, 0xbf, 0x15, 0x65, 0x1c, 0xc8, 0xf6, 0x77, 0x96, 0x6a, 0x0a, 0x8d,
|
||||
0x77, 0x0b, 0xd8, 0x91, 0x0b, 0x04, 0x8e, 0x07, 0xdb, 0x29, 0xb6, 0x0a,
|
||||
0xee, 0x9d, 0x82, 0x35, 0x35, 0x10
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
const char cert[] PROGMEM =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
"MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/\n"
|
||||
"MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n"
|
||||
"DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow\n"
|
||||
"PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD\n"
|
||||
"Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB\n"
|
||||
"AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O\n"
|
||||
"rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq\n"
|
||||
"OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b\n"
|
||||
"xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw\n"
|
||||
"7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD\n"
|
||||
"aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV\n"
|
||||
"HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG\n"
|
||||
"SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69\n"
|
||||
"ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr\n"
|
||||
"AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz\n"
|
||||
"R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5\n"
|
||||
"JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo\n"
|
||||
"Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ\n"
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
/**************************************************************
|
||||
*
|
||||
* This sketch uploads SSL certificates to the SIM8xx
|
||||
*
|
||||
* TinyGSM Getting Started guide:
|
||||
* https://tiny.cc/tinygsm-readme
|
||||
*
|
||||
**************************************************************/
|
||||
|
||||
// This example is specific to SIM8xx
|
||||
#define TINY_GSM_MODEM_SIM800
|
||||
|
||||
// Select your certificate:
|
||||
#include "DSTRootCAX3.h"
|
||||
//#include "DSTRootCAX3.der.h"
|
||||
//#include "COMODORSACertificationAuthority.h"
|
||||
|
||||
// Select the file you want to write into
|
||||
// (the file is stored on the modem)
|
||||
#define CERT_FILE "C:\\USER\\CERT.CRT"
|
||||
|
||||
#include <TinyGsmClient.h>
|
||||
|
||||
// Set serial for debug console (to the Serial Monitor, speed 115200)
|
||||
#define SerialMon Serial
|
||||
|
||||
// Use Hardware Serial for AT commands
|
||||
#define SerialAT Serial1
|
||||
|
||||
// Uncomment this if you want to see all AT commands
|
||||
//#define DUMP_AT_COMMANDS
|
||||
|
||||
|
||||
#ifdef DUMP_AT_COMMANDS
|
||||
#include <StreamDebugger.h>
|
||||
StreamDebugger debugger(SerialAT, SerialMon);
|
||||
TinyGsm modem(debugger);
|
||||
#else
|
||||
TinyGsm modem(SerialAT);
|
||||
#endif
|
||||
|
||||
void setup() {
|
||||
// Set console baud rate
|
||||
SerialMon.begin(115200);
|
||||
delay(10);
|
||||
|
||||
// Set GSM module baud rate
|
||||
SerialAT.begin(115200);
|
||||
delay(3000);
|
||||
|
||||
SerialMon.println(F("Initializing modem..."));
|
||||
modem.init();
|
||||
|
||||
modem.sendAT(GF("+FSCREATE=" CERT_FILE));
|
||||
if (modem.waitResponse() != 1) return;
|
||||
|
||||
const int cert_size = sizeof(cert);
|
||||
|
||||
modem.sendAT(GF("+FSWRITE=" CERT_FILE ",0,"), cert_size, GF(",10"));
|
||||
if (modem.waitResponse(GF(">")) != 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < cert_size; i++) {
|
||||
char c = pgm_read_byte(&cert[i]);
|
||||
modem.stream.write(c);
|
||||
}
|
||||
|
||||
modem.stream.write(GSM_NL);
|
||||
modem.stream.flush();
|
||||
|
||||
if (modem.waitResponse(2000) != 1) return;
|
||||
|
||||
modem.sendAT(GF("+SSLSETCERT=\"" CERT_FILE "\""));
|
||||
if (modem.waitResponse() != 1) return;
|
||||
if (modem.waitResponse(5000L, GF(GSM_NL "+SSLSETCERT:")) != 1) return;
|
||||
const int retCode = modem.stream.readStringUntil('\n').toInt();
|
||||
|
||||
|
||||
SerialMon.println();
|
||||
SerialMon.println();
|
||||
SerialMon.println(F("****************************"));
|
||||
SerialMon.print(F("Setting Certificate: "));
|
||||
SerialMon.println((0 == retCode) ? "OK" : "FAILED");
|
||||
SerialMon.println(F("****************************"));
|
||||
}
|
||||
|
||||
void loop() {
|
||||
if (SerialAT.available()) {
|
||||
SerialMon.write(SerialAT.read());
|
||||
}
|
||||
if (SerialMon.available()) {
|
||||
SerialAT.write(SerialMon.read());
|
||||
}
|
||||
delay(0);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user