Hello,
I have a problem with the connection to the blynk server via GSM. The connection closed after a few seconds and can connect again. Any ideas why that could be?
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4
Wait...
Initializing modem...
[10550] ### TinyGSM Version: 0.11.4
[10550] ### TinyGSM Compiled Module: TinyGsmClientSIM800
[10861] ### Modem: SIMCOM SIM800L
[10861] ### Modem: SIMCOM SIM800L
Modem Info: SIM800 R14.18
[13891]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v1.0.0 on ESP32
[13895] Modem init...
[13897] ### TinyGSM Version: 0.11.4
[13900] ### TinyGSM Compiled Module: TinyGsmClientSIM800
[13919] ### Modem: SIMCOM SIM800L
[13919] ### Modem: SIMCOM SIM800L
[13936] Connecting to network...
[17763] Network: D1
[17763] Connecting to internet.t-mobile ...
[21773] Connected to GPRS
[31397] Connecting to blynk-cloud.com:80
[35989] Ready (ping: 238ms).
[71224] Connecting to blynk-cloud.com:80
[149230] Connecting to blynk-cloud.com:80
[227236] Connecting to blynk-cloud.com:80
[305242] Connecting to blynk-cloud.com:80
here the skech
/**************************************************************
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
// Please select the corresponding model
#define SIM800L_IP5306_VERSION_20190610
//#define SIM800L_AXP192_VERSION_20200327
// #define SIM800C_AXP192_VERSION_20200609
// #define SIM800L_IP5306_VERSION_20200811
#include "utilities.h"
// Select your modem:
#define TINY_GSM_MODEM_SIM800
// Set serial for debug console (to the Serial Monitor, default speed 115200)
#define SerialMon Serial
// Set serial for AT commands (to the module)
// Use Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1
// See all AT commands, if wanted
//#define DUMP_AT_COMMANDS
// Define the serial console for debug prints, if needed
#define TINY_GSM_DEBUG SerialMon
// set GSM PIN, if any
#define GSM_PIN ""
// Your GPRS credentials, if any
const char apn[] = "internet.t-mobile"; // search for apn of your network provider on Google
const char gprsUser[] = "t-mobile";
const char gprsPass[] = "tm";
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
const char auth[] = "oXXXXXXXXXXXXXXXXXXX01";
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <SPI.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 2
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 28
// NeoPixel brightness, 0 (min) to 255 (max)
#define BRIGHTNESS 200 // Set BRIGHTNESS to about 1/5 (max = 255)
// Declare our NeoPixel strip object:
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRBW + NEO_KHZ800);
// Argument 1 = Number of pixels in NeoPixel strip
// Argument 2 = Arduino pin number (most are valid)
// Argument 3 = Pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#ifdef DUMP_AT_COMMANDS
#include <StreamDebugger.h>
StreamDebugger debugger(SerialAT, SerialMon);
TinyGsm modem(debugger);
#else
TinyGsm modem(SerialAT);
#endif
TinyGsmClient client(modem);
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
WidgetLED led1(V0);
WidgetLED led2(V1);
WidgetLCD lcd2(V2);
int LED1=32, tasterPin1=14;
int LED2=33, tasterPin2=12;
int tasterPin3=15;
struct StoppUhr // alles was für eine Stoppuhr benötigt wird
{
const byte pinStart;
const byte pinStop;
const byte pinReset;
unsigned long timeStart;
unsigned long timeStop;
unsigned long time;
bool active;
bool resume;
bool blink;
byte oldSecond;
StoppUhr (byte p1, byte p2, byte p3) :
// Initialisierungsliste;
pinStart {p1},
pinStop {p2},
pinReset {p3},
timeStart {0},
timeStop {0},
time {0},
active {false},
resume {false},
blink{false}, // für ':' Schönheitskorrektur auf dem Display
oldSecond {255} // überhöhter Startwert für 0 Ausgabe auf Lcd
{}
};
StoppUhr arrayUhr[]
{ // Pins der Taster
{12, 14, 15}, // rot, blau, stopAll
{14, 12, 15}, // blau, rot, stopAll
};
const byte ANZAHLUHREN = sizeof(arrayUhr) / sizeof(arrayUhr[0]);
void setup()
{
for (auto &i : arrayUhr)
{
pinMode(i.pinStart, INPUT_PULLUP);
pinMode(i.pinStop, INPUT_PULLUP);
pinMode(i.pinReset, INPUT_PULLUP);
}
pinMode(tasterPin1,INPUT_PULLUP);
pinMode(tasterPin2,INPUT_PULLUP);
pinMode(tasterPin3,INPUT_PULLUP);
pinMode(LED1,OUTPUT);
pinMode(LED2,OUTPUT);
// Set console baud rate
SerialMon.begin(115200);
delay(10);
setupModem();
SerialMon.println("Wait...");
// Set GSM module baud rate and UART pins
SerialAT.begin(115200, SERIAL_8N1, MODEM_RX, MODEM_TX);
delay(6000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
SerialMon.println("Initializing modem...");
modem.restart();
// modem.init();
String modemInfo = modem.getModemInfo();
SerialMon.print("Modem Info: ");
SerialMon.println(modemInfo);
// Unlock your SIM card with a PIN
//modem.simUnlock("1234");
Blynk.begin(auth, modem, apn, gprsUser, gprsPass);
SPI.begin();
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
lcd.clear();
lcd.setCursor(0, 0); lcd.print("ROT :");
lcd.setCursor(0, 1); lcd.print("BLAU:");
//lcd2.print(0, 0, "ROT :");
//lcd2.print(0, 1, "BLAU:");
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(BRIGHTNESS);
}
void loop()
{
Blynk.run();
leds();
eingabe();
ausgabe();
}
void leds (void)
{
if (digitalRead(tasterPin1) && !digitalRead(tasterPin2))
{
digitalWrite(LED1,HIGH);
led1.on();
digitalWrite(LED2,LOW);
led2.off();
strip.setPixelColor(0, 255, 0, 0); // Red
}
if (digitalRead(tasterPin2) && !digitalRead(tasterPin1))
{
digitalWrite(LED2,HIGH);
led2.on();
digitalWrite(LED1,LOW);
led1.off();
strip.setPixelColor(0, 0, 0, 255); // Blue
}
if (!digitalRead(tasterPin3))
{
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
led1.off();
led2.off();
strip.clear();
}
}
void eingabe (void)
{
unsigned long loopMillis = millis();
for (auto &i : arrayUhr)
{
// Uhr wird neu gestartet
if ( !digitalRead(i.pinStart) && !i.active && !i.resume )
{
i.timeStart = loopMillis;
i.active = true;
}
// wenn Resuming aktiv läuft Uhr mit alter Zeit weiter
// wird einmalig abgearbeitet
if ( !digitalRead(i.pinStart) && !i.active && i.resume )
{
// alte Zeitdifferenz ermitteln und von aktuellen millis abziehen
i.timeStart = loopMillis - (i.timeStop - i.timeStart);
i.active = true;
i.resume = false;
}
// Uhr wird gestoppt unter der Bedingung das sie überhaupt läuft,
// und fürs spätere weiterlaufen vorbereitet
if ( i.active && (!digitalRead(i.pinStop)) )
{
i.active = false;
i.resume = true;
i.timeStop = loopMillis;
}
// Uhr wird gestoppt unter der Bedingung das sie überhaupt läuft,
// ansonsten gibts unschöne Effekte
// und für Neustart Nullung vorbereitet
if ( !digitalRead(i.pinReset) )
{
i.active = false;
i.resume = false;
}
// laufende Zeit ermitteln
if ( i.active )
{
i.time = loopMillis - i.timeStart;
}
}
}
void ausgabe (void)
{
byte hour {0};
byte minute {0};
byte second {0};
char buf[10] {'\0'};
// Index vom Uhren Array dient mit zur Zeilenbestimmung auf dem Display.
for (byte i = 0; i < ANZAHLUHREN; i++)
{
unsigned long temp = arrayUhr[i].time / 1000;
second = temp % 60;
temp = temp / 60;
minute = temp % 60;
hour = temp / 60;
//snprintf(buf, sizeof(buf), "%02d:%02d:%02d", hour, minute, second);
// display refreshrate every seconds
if ( arrayUhr[i].oldSecond != second )
{
snprintf(buf, sizeof(buf), "%02d:%02d:%02d", hour, minute, second);
lcd.setCursor(6, i);
lcd.print(buf);
lcd2.print(0, 0, "ROT ");
lcd2.print(0, 1, "BLAU");
lcd2.print(6, i, buf);
arrayUhr[i].oldSecond = second;
}
// Resume Warteanzeige - optische Spielerei - blinkende Doppelpunkte
static unsigned long lastMillis {0};
//static bool blink {false};
if ( arrayUhr[i].resume )
{
if (millis() - lastMillis >= 1000)
{
arrayUhr[i].blink = !arrayUhr[i].blink;
if (arrayUhr[i].blink)
{
lcd.setCursor(8, i); lcd.print(' ');
lcd.setCursor(11,i); lcd.print(' ');
//lcd2.print(8, i, ' ');
//lcd2.print(11,i, ' ');
}
else
{
lcd.setCursor(8, i); lcd.print(':');
lcd.setCursor(11,i); lcd.print(':');
//lcd2.print(8, i, ':');
//lcd2.print(11,i, ':');
}
lastMillis = millis();
}
}
// Resume Warteanzeige - Schönheitskorrektur
// falls Uhr gestoppt bzw. resetet wird und ':' zufällig ausgeblendet war,
// dann wird das Zeichen einmal neu dargestellt.
if ( !arrayUhr[i].resume && arrayUhr[i].blink)
{
lcd.setCursor(8, i); lcd.print(':');
lcd.setCursor(11,i); lcd.print(':');
//lcd2.print(8, i, ':');
//lcd2.print(11,i, ':');
arrayUhr[i].blink = false;
}
} // Ende for
}
With the wifi connection there are no problems with the sketch.
With 3 or 4 simple on / off buttons and leds the sketch works fine with GSM connection and the connection is stable.