Added deepsleep current test

This commit is contained in:
lewis he
2020-02-26 16:53:20 +08:00
parent eacd2834b0
commit ed3984bfec
9 changed files with 628 additions and 553 deletions
+2
View File
@@ -12,8 +12,10 @@
- Arduino + TinyGSM library: [/examples/Arduino_TinyGSM](/examples/Arduino_TinyGSM)
- Arduino + SIM800 library: [/examples/Arduino_sim800](/examples/Arduino_sim800)
- Arduino OTA update over GSM: [/examples/Arduino_GSM_OTA](/examples/Arduino_GSM_OTA)
- Arduino Deepsleep: [/examples/Arduino_Deepsleep](/examples/Arduino_Deepsleep)
- ESP-IDF: https://github.com/espressif/esp-idf/tree/master/examples/protocols/pppos_client
## Pinout
![pinout](https://github.com/Xinyuan-LilyGO/TTGO-T-Call/blob/master/datasheet/T-Call.jpg)
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

@@ -0,0 +1,65 @@
#include <Arduino.h>
#include <Wire.h>
#include <sim800.h>
#include <gprs.h>
#define UART_TX 27
#define UART_RX 26
#define SIMCARD_RST 5
#define SIMCARD_PWKEY 4
#define SIM800_POWER_ON 23
#define UART_BANUD_RATE 9600
#define I2C_SDA 21
#define I2C_SCL 22
#define IP5306_ADDR 0X75
#define IP5306_REG_SYS_CTL0 0x00
HardwareSerial hwSerial(1);
SIM800 gprs(hwSerial, SIMCARD_PWKEY, SIMCARD_RST, SIM800_POWER_ON);
bool setPowerBoostKeepOn(int en)
{
Wire.beginTransmission(IP5306_ADDR);
Wire.write(IP5306_REG_SYS_CTL0);
if (en)
Wire.write(0x37); // Set bit1: 1 enable 0 disable boost keep on
else
Wire.write(0x35); // 0x37 is default reg value
return Wire.endTransmission() == 0;
}
void setup()
{
Serial.begin(115200);
Wire.begin(I2C_SDA, I2C_SCL);
bool isOk = setPowerBoostKeepOn(1);
String info = "IP5306 KeepOn " + String((isOk ? "PASS" : "FAIL"));
Serial.println(info);
hwSerial.begin(UART_BANUD_RATE, SERIAL_8N1, UART_RX, UART_TX);
if (gprs.preInit()) {
Serial.println("SIM800 Begin PASS");
} else {
Serial.println("SIM800 Begin FAIL");
}
Serial.println("enter deepsleep now");
delay(3000);
esp_sleep_enable_ext0_wakeup(GPIO_NUM_33, HIGH);
esp_deep_sleep_start();
}
void loop()
{
}
+8
View File
@@ -0,0 +1,8 @@
## Install the following dependency library files:
[SIM800_Library](https://github.com/lewisxhe/SIM800_Library)
#### description:
Use battery test when esp32 is in deep sleep state, current is about 1.1mA
![](../../datasheet/deepsleep.jpg)
+236 -236
View File
@@ -1,236 +1,236 @@
/*
* Copyright Volodymyr Shymanskyy 2018
*/
// Your GPRS credentials (leave empty, if missing)
const char apn[] = ""; // Your APN
const char gprsUser[] = ""; // User
const char gprsPass[] = ""; // Password
const char simPIN[] = ""; // SIM card PIN code, if any
// URL to download the firmware from
String overTheAirURL = "http://vsh.pp.ua/ota/ttgo-t-call-B.bin";
// TTGO T-Call pin definitions
#define MODEM_RST 5
#define MODEM_PWKEY 4
#define MODEM_POWER_ON 23
#define MODEM_TX 27
#define MODEM_RX 26
#define I2C_SDA 21
#define I2C_SCL 22
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to the module)
#define SerialAT Serial1
// Configure TinyGSM library
#define TINY_GSM_MODEM_SIM800 // Modem is SIM800
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb
// Define the serial console for debug prints, if needed
//#define TINY_GSM_DEBUG SerialMon
//#define DUMP_AT_COMMANDS
#include <Wire.h>
#include <TinyGsmClient.h>
#include <Update.h>
#include "utilities.h"
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
#define DEBUG_PRINT(...) { SerialMon.print(millis()); SerialMon.print(" - "); SerialMon.println(__VA_ARGS__); }
#define DEBUG_FATAL(...) { SerialMon.print(millis()); SerialMon.print(" - FATAL: "); SerialMon.println(__VA_ARGS__); delay(10000); ESP.restart(); }
void startOtaUpdate(const String& ota_url)
{
String protocol, host, url;
int port;
if (!parseURL(ota_url, protocol, host, port, url)) {
DEBUG_FATAL(F("Cannot parse URL"));
}
DEBUG_PRINT(String("Connecting to ") + host + ":" + port);
Client* client = NULL;
if (protocol == "http") {
client = new TinyGsmClient(modem);
if (!client->connect(host.c_str(), port)) {
DEBUG_FATAL(F("Client not connected"));
}
} else if (protocol == "https") {
client = new TinyGsmClientSecure(modem);
if (!client->connect(host.c_str(), port)) {
DEBUG_FATAL(F("Client not connected"));
}
} else {
DEBUG_FATAL(String("Unsupported protocol: ") + protocol);
}
DEBUG_PRINT(String("Requesting ") + url);
client->print(String("GET ") + url + " HTTP/1.0\r\n"
+ "Host: " + host + "\r\n"
+ "Connection: keep-alive\r\n"
+ "\r\n");
long timeout = millis();
while (client->connected() && !client->available()) {
if (millis() - timeout > 10000L) {
DEBUG_FATAL("Response timeout");
}
}
// Collect headers
String md5;
int contentLength = 0;
while (client->available()) {
String line = client->readStringUntil('\n');
line.trim();
//SerialMon.println(line); // Uncomment this to show response headers
line.toLowerCase();
if (line.startsWith("content-length:")) {
contentLength = line.substring(line.lastIndexOf(':') + 1).toInt();
} else if (line.startsWith("x-md5:")) {
md5 = line.substring(line.lastIndexOf(':') + 1);
} else if (line.length() == 0) {
break;
}
}
if (contentLength <= 0) {
DEBUG_FATAL("Content-Length not defined");
}
bool canBegin = Update.begin(contentLength);
if (!canBegin) {
Update.printError(SerialMon);
DEBUG_FATAL("OTA begin failed");
}
if (md5.length()) {
DEBUG_PRINT(String("Expected MD5: ") + md5);
if(!Update.setMD5(md5.c_str())) {
DEBUG_FATAL("Cannot set MD5");
}
}
DEBUG_PRINT("Flashing...");
// The next loop does approx. the same thing as Update.writeStream(http) or Update.write(http)
int written = 0;
int progress = 0;
uint8_t buff[256];
while (client->connected() && written < contentLength) {
timeout = millis();
while (client->connected() && !client->available()) {
delay(1);
if (millis() - timeout > 10000L) {
DEBUG_FATAL("Timeout");
}
}
int len = client->read(buff, sizeof(buff));
if (len <= 0) continue;
Update.write(buff, len);
written += len;
int newProgress = (written*100)/contentLength;
if (newProgress - progress >= 5 || newProgress == 100) {
progress = newProgress;
SerialMon.print(String("\r ") + progress + "%");
}
}
SerialMon.println();
if (written != contentLength) {
Update.printError(SerialMon);
DEBUG_FATAL(String("Write failed. Written ") + written + " / " + contentLength + " bytes");
}
if (!Update.end()) {
Update.printError(SerialMon);
DEBUG_FATAL(F("Update not ended"));
}
if (!Update.isFinished()) {
DEBUG_FATAL(F("Update not finished"));
}
DEBUG_PRINT("=== Update successfully completed. Rebooting.");
ESP.restart();
}
void setup() {
// Set console baud rate
SerialMon.begin(115200);
delay(10);
//SerialMon.setDebugOutput(true);
printDeviceInfo();
// Keep power when running from battery
Wire.begin(I2C_SDA, I2C_SCL);
bool isOk = setPowerBoostKeepOn(1);
SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));
SerialMon.println(" Firmware A is running");
SerialMon.println("--------------------------");
DEBUG_PRINT(F("Starting OTA update in 10 seconds..."));
delay(10000);
// Set-up modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
DEBUG_PRINT(F("Initializing modem..."));
modem.restart();
// Or, use modem.init() if you don't need the complete restart
String modemInfo = modem.getModemInfo();
DEBUG_PRINT(String("Modem: ") + modemInfo);
// Unlock your SIM card with a PIN if needed
if (strlen(simPIN) && modem.getSimStatus() != 3 ) {
modem.simUnlock(simPIN);
}
DEBUG_PRINT(F("Waiting for network..."));
if (!modem.waitForNetwork(240000L)) {
DEBUG_FATAL(F("Network failed to connect"));
}
DEBUG_PRINT(F("Connecting to GPRS"));
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
DEBUG_FATAL(F("APN failed to connect"));
}
startOtaUpdate(overTheAirURL);
}
void loop() {
// We do nothing here
delay(1000);
}
/*
* Copyright Volodymyr Shymanskyy 2018
*/
// Your GPRS credentials (leave empty, if missing)
const char apn[] = ""; // Your APN
const char gprsUser[] = ""; // User
const char gprsPass[] = ""; // Password
const char simPIN[] = ""; // SIM card PIN code, if any
// URL to download the firmware from
String overTheAirURL = "http://vsh.pp.ua/ota/ttgo-t-call-B.bin";
// TTGO T-Call pin definitions
#define MODEM_RST 5
#define MODEM_PWKEY 4
#define MODEM_POWER_ON 23
#define MODEM_TX 27
#define MODEM_RX 26
#define I2C_SDA 21
#define I2C_SCL 22
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to the module)
#define SerialAT Serial1
// Configure TinyGSM library
#define TINY_GSM_MODEM_SIM800 // Modem is SIM800
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb
// Define the serial console for debug prints, if needed
//#define TINY_GSM_DEBUG SerialMon
//#define DUMP_AT_COMMANDS
#include <Wire.h>
#include <TinyGsmClient.h>
#include <Update.h>
#include "utilities.h"
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
#define DEBUG_PRINT(...) { SerialMon.print(millis()); SerialMon.print(" - "); SerialMon.println(__VA_ARGS__); }
#define DEBUG_FATAL(...) { SerialMon.print(millis()); SerialMon.print(" - FATAL: "); SerialMon.println(__VA_ARGS__); delay(10000); ESP.restart(); }
void startOtaUpdate(const String& ota_url)
{
String protocol, host, url;
int port;
if (!parseURL(ota_url, protocol, host, port, url)) {
DEBUG_FATAL(F("Cannot parse URL"));
}
DEBUG_PRINT(String("Connecting to ") + host + ":" + port);
Client* client = NULL;
if (protocol == "http") {
client = new TinyGsmClient(modem);
if (!client->connect(host.c_str(), port)) {
DEBUG_FATAL(F("Client not connected"));
}
} else if (protocol == "https") {
client = new TinyGsmClientSecure(modem);
if (!client->connect(host.c_str(), port)) {
DEBUG_FATAL(F("Client not connected"));
}
} else {
DEBUG_FATAL(String("Unsupported protocol: ") + protocol);
}
DEBUG_PRINT(String("Requesting ") + url);
client->print(String("GET ") + url + " HTTP/1.0\r\n"
+ "Host: " + host + "\r\n"
+ "Connection: keep-alive\r\n"
+ "\r\n");
long timeout = millis();
while (client->connected() && !client->available()) {
if (millis() - timeout > 10000L) {
DEBUG_FATAL("Response timeout");
}
}
// Collect headers
String md5;
int contentLength = 0;
while (client->available()) {
String line = client->readStringUntil('\n');
line.trim();
//SerialMon.println(line); // Uncomment this to show response headers
line.toLowerCase();
if (line.startsWith("content-length:")) {
contentLength = line.substring(line.lastIndexOf(':') + 1).toInt();
} else if (line.startsWith("x-md5:")) {
md5 = line.substring(line.lastIndexOf(':') + 1);
} else if (line.length() == 0) {
break;
}
}
if (contentLength <= 0) {
DEBUG_FATAL("Content-Length not defined");
}
bool canBegin = Update.begin(contentLength);
if (!canBegin) {
Update.printError(SerialMon);
DEBUG_FATAL("OTA begin failed");
}
if (md5.length()) {
DEBUG_PRINT(String("Expected MD5: ") + md5);
if(!Update.setMD5(md5.c_str())) {
DEBUG_FATAL("Cannot set MD5");
}
}
DEBUG_PRINT("Flashing...");
// The next loop does approx. the same thing as Update.writeStream(http) or Update.write(http)
int written = 0;
int progress = 0;
uint8_t buff[256];
while (client->connected() && written < contentLength) {
timeout = millis();
while (client->connected() && !client->available()) {
delay(1);
if (millis() - timeout > 10000L) {
DEBUG_FATAL("Timeout");
}
}
int len = client->read(buff, sizeof(buff));
if (len <= 0) continue;
Update.write(buff, len);
written += len;
int newProgress = (written*100)/contentLength;
if (newProgress - progress >= 5 || newProgress == 100) {
progress = newProgress;
SerialMon.print(String("\r ") + progress + "%");
}
}
SerialMon.println();
if (written != contentLength) {
Update.printError(SerialMon);
DEBUG_FATAL(String("Write failed. Written ") + written + " / " + contentLength + " bytes");
}
if (!Update.end()) {
Update.printError(SerialMon);
DEBUG_FATAL(F("Update not ended"));
}
if (!Update.isFinished()) {
DEBUG_FATAL(F("Update not finished"));
}
DEBUG_PRINT("=== Update successfully completed. Rebooting.");
ESP.restart();
}
void setup() {
// Set console baud rate
SerialMon.begin(115200);
delay(10);
//SerialMon.setDebugOutput(true);
printDeviceInfo();
// Keep power when running from battery
Wire.begin(I2C_SDA, I2C_SCL);
bool isOk = setPowerBoostKeepOn(1);
SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));
SerialMon.println(" Firmware A is running");
SerialMon.println("--------------------------");
DEBUG_PRINT(F("Starting OTA update in 10 seconds..."));
delay(10000);
// Set-up modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
DEBUG_PRINT(F("Initializing modem..."));
modem.restart();
// Or, use modem.init() if you don't need the complete restart
String modemInfo = modem.getModemInfo();
DEBUG_PRINT(String("Modem: ") + modemInfo);
// Unlock your SIM card with a PIN if needed
if (strlen(simPIN) && modem.getSimStatus() != 3 ) {
modem.simUnlock(simPIN);
}
DEBUG_PRINT(F("Waiting for network..."));
if (!modem.waitForNetwork(240000L)) {
DEBUG_FATAL(F("Network failed to connect"));
}
DEBUG_PRINT(F("Connecting to GPRS"));
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
DEBUG_FATAL(F("APN failed to connect"));
}
startOtaUpdate(overTheAirURL);
}
void loop() {
// We do nothing here
delay(1000);
}
+67 -67
View File
@@ -1,67 +1,67 @@
#define IP5306_ADDR 0x75
#define IP5306_REG_SYS_CTL0 0x00
bool setPowerBoostKeepOn(int en)
{
Wire.beginTransmission(IP5306_ADDR);
Wire.write(IP5306_REG_SYS_CTL0);
if (en) {
Wire.write(0x37); // Set bit1: 1 enable 0 disable boost keep on
} else {
Wire.write(0x35); // 0x37 is default reg value
}
return Wire.endTransmission() == 0;
}
void printDeviceInfo()
{
Serial.println();
Serial.println("--------------------------");
Serial.println(String("Build: ") + __DATE__ " " __TIME__);
#if defined(ESP8266)
Serial.println(String("Flash: ") + ESP.getFlashChipRealSize() / 1024 + "K");
Serial.println(String("ESP core: ") + ESP.getCoreVersion());
Serial.println(String("FW info: ") + ESP.getSketchSize() + "/" + ESP.getFreeSketchSpace() + ", " + ESP.getSketchMD5());
#elif defined(ESP32)
Serial.println(String("Flash: ") + ESP.getFlashChipSize() / 1024 + "K");
Serial.println(String("ESP sdk: ") + ESP.getSdkVersion());
Serial.println(String("Chip rev: ") + ESP.getChipRevision());
#endif
Serial.println(String("Free mem: ") + ESP.getFreeHeap());
Serial.println("--------------------------");
}
bool parseURL(String url, String& protocol, String& host, int& port, String& uri)
{
int index = url.indexOf(':');
if(index < 0) {
return false;
}
protocol = url.substring(0, index);
url.remove(0, (index + 3)); // remove protocol part
index = url.indexOf('/');
String server = url.substring(0, index);
url.remove(0, index); // remove server part
index = server.indexOf(':');
if(index >= 0) {
host = server.substring(0, index); // hostname
port = server.substring(index + 1).toInt(); // port
} else {
host = server;
if (protocol == "http") {
port = 80;
} else if (protocol == "https") {
port = 443;
}
}
if (url.length()) {
uri = url;
} else {
uri = "/";
}
return true;
}
#define IP5306_ADDR 0x75
#define IP5306_REG_SYS_CTL0 0x00
bool setPowerBoostKeepOn(int en)
{
Wire.beginTransmission(IP5306_ADDR);
Wire.write(IP5306_REG_SYS_CTL0);
if (en) {
Wire.write(0x37); // Set bit1: 1 enable 0 disable boost keep on
} else {
Wire.write(0x35); // 0x37 is default reg value
}
return Wire.endTransmission() == 0;
}
void printDeviceInfo()
{
Serial.println();
Serial.println("--------------------------");
Serial.println(String("Build: ") + __DATE__ " " __TIME__);
#if defined(ESP8266)
Serial.println(String("Flash: ") + ESP.getFlashChipRealSize() / 1024 + "K");
Serial.println(String("ESP core: ") + ESP.getCoreVersion());
Serial.println(String("FW info: ") + ESP.getSketchSize() + "/" + ESP.getFreeSketchSpace() + ", " + ESP.getSketchMD5());
#elif defined(ESP32)
Serial.println(String("Flash: ") + ESP.getFlashChipSize() / 1024 + "K");
Serial.println(String("ESP sdk: ") + ESP.getSdkVersion());
Serial.println(String("Chip rev: ") + ESP.getChipRevision());
#endif
Serial.println(String("Free mem: ") + ESP.getFreeHeap());
Serial.println("--------------------------");
}
bool parseURL(String url, String& protocol, String& host, int& port, String& uri)
{
int index = url.indexOf(':');
if(index < 0) {
return false;
}
protocol = url.substring(0, index);
url.remove(0, (index + 3)); // remove protocol part
index = url.indexOf('/');
String server = url.substring(0, index);
url.remove(0, index); // remove server part
index = server.indexOf(':');
if(index >= 0) {
host = server.substring(0, index); // hostname
port = server.substring(index + 1).toInt(); // port
} else {
host = server;
if (protocol == "http") {
port = 80;
} else if (protocol == "https") {
port = 443;
}
}
if (url.length()) {
uri = url;
} else {
uri = "/";
}
return true;
}
+160 -160
View File
@@ -1,160 +1,160 @@
/**************************************************************
*
* 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
*
**************************************************************/
// Your GPRS credentials (leave empty, if missing)
const char apn[] = ""; // Your APN
const char gprsUser[] = ""; // User
const char gprsPass[] = ""; // Password
const char simPIN[] = ""; // SIM card PIN code, if any
// TTGO T-Call pin definitions
#define MODEM_RST 5
#define MODEM_PWKEY 4
#define MODEM_POWER_ON 23
#define MODEM_TX 27
#define MODEM_RX 26
#define I2C_SDA 21
#define I2C_SCL 22
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to the module)
#define SerialAT Serial1
// Configure TinyGSM library
#define TINY_GSM_MODEM_SIM800 // Modem is SIM800
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb
// Define the serial console for debug prints, if needed
//#define TINY_GSM_DEBUG SerialMon
//#define DUMP_AT_COMMANDS
#include <Wire.h>
#include <TinyGsmClient.h>
#include "utilities.h"
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
// Server details
const char server[] = "vsh.pp.ua";
const char resource[] = "/TinyGSM/logo.txt";
TinyGsmClient client(modem);
const int port = 80;
void setup() {
// Set console baud rate
SerialMon.begin(115200);
delay(10);
// Keep power when running from battery
Wire.begin(I2C_SDA, I2C_SCL);
bool isOk = setPowerBoostKeepOn(1);
SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));
// Set-up modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
modem.restart();
// Or, use modem.init() if you don't need the complete restart
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.println(modemInfo);
// Unlock your SIM card with a PIN if needed
if (strlen(simPIN) && modem.getSimStatus() != 3 ) {
modem.simUnlock(simPIN);
}
}
void loop() {
SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork(240000L)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
if (modem.isNetworkConnected()) {
SerialMon.println("Network connected");
}
SerialMon.print(F("Connecting to APN: "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
SerialMon.print("Connecting to ");
SerialMon.print(server);
if (!client.connect(server, port)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
// Make a HTTP GET request:
SerialMon.println("Performing HTTP GET request...");
client.print(String("GET ") + resource + " HTTP/1.1\r\n");
client.print(String("Host: ") + server + "\r\n");
client.print("Connection: close\r\n\r\n");
client.println();
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);
}
}
/**************************************************************
*
* 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
*
**************************************************************/
// Your GPRS credentials (leave empty, if missing)
const char apn[] = ""; // Your APN
const char gprsUser[] = ""; // User
const char gprsPass[] = ""; // Password
const char simPIN[] = ""; // SIM card PIN code, if any
// TTGO T-Call pin definitions
#define MODEM_RST 5
#define MODEM_PWKEY 4
#define MODEM_POWER_ON 23
#define MODEM_TX 27
#define MODEM_RX 26
#define I2C_SDA 21
#define I2C_SCL 22
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to the module)
#define SerialAT Serial1
// Configure TinyGSM library
#define TINY_GSM_MODEM_SIM800 // Modem is SIM800
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb
// Define the serial console for debug prints, if needed
//#define TINY_GSM_DEBUG SerialMon
//#define DUMP_AT_COMMANDS
#include <Wire.h>
#include <TinyGsmClient.h>
#include "utilities.h"
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
// Server details
const char server[] = "vsh.pp.ua";
const char resource[] = "/TinyGSM/logo.txt";
TinyGsmClient client(modem);
const int port = 80;
void setup() {
// Set console baud rate
SerialMon.begin(115200);
delay(10);
// Keep power when running from battery
Wire.begin(I2C_SDA, I2C_SCL);
bool isOk = setPowerBoostKeepOn(1);
SerialMon.println(String("IP5306 KeepOn ") + (isOk ? "OK" : "FAIL"));
// Set-up modem reset, enable, power pins
pinMode(MODEM_PWKEY, OUTPUT);
pinMode(MODEM_RST, OUTPUT);
pinMode(MODEM_POWER_ON, OUTPUT);
digitalWrite(MODEM_PWKEY, LOW);
digitalWrite(MODEM_RST, HIGH);
digitalWrite(MODEM_POWER_ON, HIGH);
// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
modem.restart();
// Or, use modem.init() if you don't need the complete restart
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
SerialMon.println(modemInfo);
// Unlock your SIM card with a PIN if needed
if (strlen(simPIN) && modem.getSimStatus() != 3 ) {
modem.simUnlock(simPIN);
}
}
void loop() {
SerialMon.print("Waiting for network...");
if (!modem.waitForNetwork(240000L)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
if (modem.isNetworkConnected()) {
SerialMon.println("Network connected");
}
SerialMon.print(F("Connecting to APN: "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
SerialMon.print("Connecting to ");
SerialMon.print(server);
if (!client.connect(server, port)) {
SerialMon.println(" fail");
delay(10000);
return;
}
SerialMon.println(" OK");
// Make a HTTP GET request:
SerialMon.println("Performing HTTP GET request...");
client.print(String("GET ") + resource + " HTTP/1.1\r\n");
client.print(String("Host: ") + server + "\r\n");
client.print("Connection: close\r\n\r\n");
client.println();
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);
}
}
+14 -14
View File
@@ -1,14 +1,14 @@
#define IP5306_ADDR 0x75
#define IP5306_REG_SYS_CTL0 0x00
bool setPowerBoostKeepOn(int en)
{
Wire.beginTransmission(IP5306_ADDR);
Wire.write(IP5306_REG_SYS_CTL0);
if (en) {
Wire.write(0x37); // Set bit1: 1 enable 0 disable boost keep on
} else {
Wire.write(0x35); // 0x37 is default reg value
}
return Wire.endTransmission() == 0;
}
#define IP5306_ADDR 0x75
#define IP5306_REG_SYS_CTL0 0x00
bool setPowerBoostKeepOn(int en)
{
Wire.beginTransmission(IP5306_ADDR);
Wire.write(IP5306_REG_SYS_CTL0);
if (en) {
Wire.write(0x37); // Set bit1: 1 enable 0 disable boost keep on
} else {
Wire.write(0x35); // 0x37 is default reg value
}
return Wire.endTransmission() == 0;
}
+76 -76
View File
@@ -1,76 +1,76 @@
'''
Using your phone:
- Disable PIN code on the SIM card
- Check your balance
- Check that APN, User, Pass are correct and you have internet
Ensure the SIM card is correctly inserted into the board
Ensure that GSM antenna is firmly attached
NOTE: While GSM is connected to the Internet, WiFi can be used only in AP mode
More docs on GSM module here:
https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/gsm
Author: Volodymyr Shymanskyy
'''
import machine, time, sys
import gsm
# APN credentials (replace with yours)
GSM_APN = '' # Your APN
GSM_USER = '' # Your User
GSM_PASS = '' # Your Pass
# Power on the GSM module
GSM_PWR = machine.Pin(4, machine.Pin.OUT)
GSM_RST = machine.Pin(5, machine.Pin.OUT)
GSM_MODEM_PWR = machine.Pin(23, machine.Pin.OUT)
GSM_PWR.value(0)
GSM_RST.value(1)
GSM_MODEM_PWR.value(1)
# Init PPPoS
#gsm.debug(True) # Uncomment this to see more logs, investigate issues, etc.
gsm.start(tx=27, rx=26, apn=GSM_APN, user=GSM_USER, password=GSM_PASS)
sys.stdout.write('Waiting for AT command response...')
for retry in range(20):
if gsm.atcmd('AT'):
break
else:
sys.stdout.write('.')
time.sleep_ms(5000)
else:
raise Exception("Modem not responding!")
print()
print("Connecting to GSM...")
gsm.connect()
while gsm.status()[0] != 1:
pass
print('IP:', gsm.ifconfig()[0])
# GSM connection is complete.
# You can now use modules like urequests, uPing, etc.
# Let's try socket API:
import socket
addr_info = socket.getaddrinfo("towel.blinkenlights.nl", 23)
addr = addr_info[0][-1]
s = socket.socket()
s.connect(addr)
while True:
data = s.recv(500)
print(str(data, 'utf8'), end='')
# You should see terminal version of StarWars episode
# Just like this: https://asciinema.org/a/1457
'''
Using your phone:
- Disable PIN code on the SIM card
- Check your balance
- Check that APN, User, Pass are correct and you have internet
Ensure the SIM card is correctly inserted into the board
Ensure that GSM antenna is firmly attached
NOTE: While GSM is connected to the Internet, WiFi can be used only in AP mode
More docs on GSM module here:
https://github.com/loboris/MicroPython_ESP32_psRAM_LoBo/wiki/gsm
Author: Volodymyr Shymanskyy
'''
import machine, time, sys
import gsm
# APN credentials (replace with yours)
GSM_APN = '' # Your APN
GSM_USER = '' # Your User
GSM_PASS = '' # Your Pass
# Power on the GSM module
GSM_PWR = machine.Pin(4, machine.Pin.OUT)
GSM_RST = machine.Pin(5, machine.Pin.OUT)
GSM_MODEM_PWR = machine.Pin(23, machine.Pin.OUT)
GSM_PWR.value(0)
GSM_RST.value(1)
GSM_MODEM_PWR.value(1)
# Init PPPoS
#gsm.debug(True) # Uncomment this to see more logs, investigate issues, etc.
gsm.start(tx=27, rx=26, apn=GSM_APN, user=GSM_USER, password=GSM_PASS)
sys.stdout.write('Waiting for AT command response...')
for retry in range(20):
if gsm.atcmd('AT'):
break
else:
sys.stdout.write('.')
time.sleep_ms(5000)
else:
raise Exception("Modem not responding!")
print()
print("Connecting to GSM...")
gsm.connect()
while gsm.status()[0] != 1:
pass
print('IP:', gsm.ifconfig()[0])
# GSM connection is complete.
# You can now use modules like urequests, uPing, etc.
# Let's try socket API:
import socket
addr_info = socket.getaddrinfo("towel.blinkenlights.nl", 23)
addr = addr_info[0][-1]
s = socket.socket()
s.connect(addr)
while True:
data = s.recv(500)
print(str(data, 'utf8'), end='')
# You should see terminal version of StarWars episode
# Just like this: https://asciinema.org/a/1457