I have some troubles at my project and I hope anyone can help me!
I want to do some measurements every 2h and send them to my local server. After that arduino should go in deep sleep. Measurements and transfer to the server works realy fine.
But I don’t have any solution for the case if the connection to the server fails.
In that case the arduino tries to build up a connection to the server and drains my batteries.
So it would helpful if builing up the connection fails, that the arduino stop trying, skip the transfer and continue the code! At the next loop the arduino should try again to build up a connection to the server.
Below you see my basic sketch!
By the way: I tried everything with Blynk.config(), Bylnk.connect(), Bylnk.connect(15),…
The question is whether there is a way to define a certain amount of time after Blynk will automatically disconnect. Or if you can define a number of connection attempts.
A version of the original code was being used by @christophebl to monitor a beehive. The code used Blynk.begin and sometimes his device wasn’t able to connect to either Wi-Fi or Blynk, so it would flatten his battery because the code never progressed past the blocking Blynk.begin phase so was never able to get to the deep sleep command.
We changed the code to use Blynk.config and Blynk.connect instead, and the logic is as follows:
Attempt to connect to Wi-Fi, if unsuccessful wait a short time (0.5-1 second) and re-try. Do this x times and if we still can’t connect then go to sleep.
If we are successful in connecting to Wi-Fi then call Blynk.connect. This will try to connect to Blynk for 10-12 seconds before timing-out.
If after calling Blynk.connect we are connected then take some readings, send them to Blynk and go to sleep.
If we weren’t successful in connecting to Blynk then go to sleep anyway.
Instead of connecting to Wi-Fi, you’d need to attempt to establish a GPRS connection. If that worked then you’d needs to try to connect to Blynk.
As the SIM800 is a separate board then you’d need to close the GPRS connection and put it into sleep mode before putting your MCU into sleep mode, and you’d need to wake-up the SIM800 again when your MCU wakes from deep sleep.
I tried your notes! Without result!
I can’t use Timer-function in my sketch. So I tried Blynk.config(…) instead of blynk.begin(), because blynk.beginn will block my sketch (apparently).
But Blynk.config(auth, server, port) with Blynk.connect() does not work. I get an compailing failure:
no matching function for call to ‘Blynk.SIM::config(char[33], char[18], int&)’
Maybe I did not explain my problem well enough:
Situation: If I have no connection to my server, Blynk will try to connect to server endless.
Is there an “EASY” way to interrupt the trying?
Example:
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.5.4 on Arduino Pro
[8523] Modem init...
[9776] Connecting to network...
[14476] Network: T-Mobile A
[14476] Connecting to ...
[18499] Connected to GPRS
[18563] Connecting to ................ddns.net:8080
[93741] Connecting to .....................dns.net:8080
[168918] Connecting to ...................ddns.net:8080
[244094] Connecting to .....................ddns.net:8080
[244094] Connecting to .....................ddns.net:8080
[244094] Connecting to .....................ddns.net:8080
[244094] Connecting to .....................ddns.net:8080
[244094] Connecting to .....................ddns.net:8080
[244094] Connecting to .....................ddns.net:8080
Please keep in mind, I work with SIM800 and not a WIFI, so the commands are completly different.
I have a quite tricky question. I try to connect to Blynk-Server with Blynk.config() and Blynk.connect() and also with Blynk.disconnect().
Connecting with Blynk.begin() works fine!
But my sketch stucks while connecting to blynk.cloud. Can anybody help me with this issue?
Sketch and Serial Monitor below!
Thank you ver much
Philip
#define BLYNK_PRINT Serial
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
// Default heartbeat interval for GSM is 60
// If you want override this value, uncomment and set this option:
//#define BLYNK_HEARTBEAT 30
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "51a487ef2b7841cd8dcd5768368a14c9";
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "YourAPN";
char user[] = "";
char pass[] = "";
char domain[] = "";
char server[] = "";
int port;
int csq;
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(8, 10); // RX, TX
TinyGsm modem(SerialAT);
int i = 0;
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// SerialAT.begin(9600);
SerialAT.begin(115200);
delay(3000);
digitalWrite(11, HIGH); // Start GSM Modul
Serial.println("Initializing modem...");
modem.restart();
// if (!modem.restart()) {
// delay(10000);
// Serial.println("!no modem found");
// return;
// }
// Blynk.config(modem, auth, server, port);
Blynk.config(modem, auth);
Blynk.connect();
// Blynk.begin(auth, modem, apn, user, pass);
Blynk.disconnect();
delay(5000);
digitalWrite(11, LOW); // Shut down GSM Modul
delay(5000);
// csq = modem.getSignalQuality();
// Serial.print("Signal quality:");
// Serial.println(csq);
}
void loop()
{
digitalWrite(11, HIGH);
delay(10000);
Serial.println("Power on");
delay(1000);
if (!Blynk.connected())
{
Serial.println("nö");
Blynk.connect();
}
// if (Blynk.connected())
// {
// Serial.println("run");
// Blynk.run();
// }
// else
// {
// Serial.println("nein");
// }
delay(1000);
// Blynk.run();
// delay(1000);
i++;
Blynk.virtualWrite(V1, i);
delay(2000);
Blynk.disconnect();
delay(5000);
digitalWrite(11, LOW);
Serial.println("Power off");
delay(5000);
}
==========================================================================
Initializing modem...
[30726]
___ __ __
/ _ )/ /_ _____ / /__
/ _ / / // / _ \/ '_/
/____/_/\_, /_//_/_/\_\
/___/ v0.6.1 on Arduino Pro
[31824] Connecting to blynk-cloud.com:80
[108835] Disconnected
Power on
nö
[129857] Connecting to blynk-cloud.com:80
[135851] Connecting to blynk-cloud.com:80
[215865] Disconnected
Power off
Power on
nö
[236881] Connecting to blynk-cloud.com:80
[317890] Disconnected
Power off
Power on
nö
[340892] Connecting to blynk-cloud.com:80
[419914] Disconnected
Power off
Power on
nö
[442916] Connecting to blynk-cloud.com:80
[521937] Disconnected
Power off
Power on
nö
[543947] Connecting to blynk-cloud.com:80
[549941] Connecting to blynk-cloud.com:80
Blynk.begin() will do that networking connection based on the library and your settings, but will also block further code operation until such connection is made.
But what do you mean with: you MUST have previously setup your own network connection
If I power on my GSM Modul, it will connect to the internet within 8-12 Seconds!
I mean you must have code/drivers/whatever that tells your device how to use and connect to your GSM module, and thus connect your device to the internet… as if you were using it without Blynk.
PS, please do not create multiple topics for same general issue… I merged them both together.