Skip to content

Commit

Permalink
Update examples so it works with the latest T-Call revision
Browse files Browse the repository at this point in the history
  • Loading branch information
vshymanskyy committed Jul 18, 2019
1 parent 6dcb2fa commit 6997515
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 46 deletions.
23 changes: 15 additions & 8 deletions examples/Arduino_GSM_OTA/Arduino_GSM_OTA.ino
Expand Up @@ -20,19 +20,24 @@ String overTheAirURL = "http://vsh.pp.ua/ota/ttgo-t-call-B.bin";
#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
#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 <Wire.h>
#include "utilities.h"

#define SerialMon Serial
#define SerialAT Serial1

#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
Expand Down Expand Up @@ -168,6 +173,7 @@ void startOtaUpdate(const String& ota_url)
}

void setup() {
// Set console baud rate
SerialMon.begin(115200);
delay(10);

Expand Down Expand Up @@ -201,6 +207,7 @@ void setup() {
// 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);
Expand All @@ -211,7 +218,7 @@ void setup() {
}

DEBUG_PRINT(F("Waiting for network..."));
if (!modem.waitForNetwork()) {
if (!modem.waitForNetwork(240000L)) {
DEBUG_FATAL(F("Network failed to connect"));
}

Expand All @@ -224,6 +231,6 @@ void setup() {
}

void loop() {
// put your main code here, to run repeatedly:

// We do nothing here
delay(1000);
}
84 changes: 46 additions & 38 deletions examples/Arduino_TinyGSM/Arduino_TinyGSM.ino
Expand Up @@ -8,36 +8,37 @@
*
**************************************************************/

// Select your modem:
#define TINY_GSM_MODEM_SIM800

// Increase RX buffer if needed
#define TINY_GSM_RX_BUFFER 512

// Define the serial console for debug prints, if needed
//#define TINY_GSM_DEBUG SerialMon
//#define DUMP_AT_COMMANDS
// 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

// Uncomment this if you want to use SSL
//#define USE_SSL
// 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
#define SerialAT Serial1

// 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
// Configure TinyGSM library
#define TINY_GSM_MODEM_SIM800 // Modem is SIM800
#define TINY_GSM_RX_BUFFER 1024 // Set RX buffer to 1Kb

// Server details
const char server[] = "vsh.pp.ua";
const char resource[] = "/TinyGSM/logo.txt";
// 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>
Expand All @@ -47,36 +48,43 @@ const char resource[] = "/TinyGSM/logo.txt";
TinyGsm modem(SerialAT);
#endif

#ifdef USE_SSL
TinyGsmClientSecure client(modem);
const int port = 443;
#else
TinyGsmClient client(modem);
const int port = 80;
#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);

// Set your reset, enable, power pins here
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(4, LOW);
digitalWrite(5, HIGH);
// 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);

SerialMon.println("Wait...");
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, 26, 27);
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();
// modem.init();
// Or, use modem.init() if you don't need the complete restart

String modemInfo = modem.getModemInfo();
SerialMon.print("Modem: ");
Expand All @@ -101,7 +109,7 @@ void loop() {
SerialMon.println("Network connected");
}

SerialMon.print(F("Connecting to "));
SerialMon.print(F("Connecting to APN: "));
SerialMon.print(apn);
if (!modem.gprsConnect(apn, gprsUser, gprsPass)) {
SerialMon.println(" fail");
Expand All @@ -111,7 +119,7 @@ void loop() {
SerialMon.println(" OK");

SerialMon.print("Connecting to ");
SerialMon.println(server);
SerialMon.print(server);
if (!client.connect(server, port)) {
SerialMon.println(" fail");
delay(10000);
Expand Down
14 changes: 14 additions & 0 deletions examples/Arduino_TinyGSM/utilities.h
@@ -0,0 +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;
}

0 comments on commit 6997515

Please sign in to comment.