Hi,
I having problem with blynk cloud. I want to see an analog value and send a notification if the value is smaler that my analog read value! Evrithyng works for 1-2 minutes then i get the notification in app “your device is offline”. My power supply is a 5Vdc 2A power adapter(mobile phone charger) and I put a 3300uF capacitor near to SIM800L V2 modul!
Thank you.
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID "YourTemplateID"
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE
// 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[] = "Qz7bDuRDBxrzAlYePU2dJHpYVAotQrmb";
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "ipfix.vodafone.ro";
char user[] = "";
char pass[] = "vodafone";
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
int senzorpin = A0;
int valoare;
TinyGsm modem(SerialAT);
void setup()
{
// Debug console
Serial.begin(9600);
delay(10);
// Set GSM module baud rate
SerialAT.begin(9600);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
modem.restart();
// Unlock your SIM card with a PIN
modem.simUnlock("");
Blynk.begin(auth, modem, apn, user, pass);
}
void loop()
{
Blynk.run();
valoare = analogRead(senzorpin);
if (valoare <= 400)
{
Blynk.notify("Alarma nivel minim, Se incearca recuperarea");
}
}
I cleen de loop and is working fine but in the app I get this message after every 5minutes “Your device disconected”.
In serial monitor everything is fine:
[3127] Modem init…
[3351] Connecting to network…
[3445] Network: CONNEX GSM
[3446] Connecting to ipfix.vodafone.ro …
[9623] Connected to GPRS
[9696] Connecting to blynk-cloud.com:80
[12295] Ready (ping: 1536ms).
Code:
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill-in your Template ID (only if using Blynk.Cloud) */
//#define BLYNK_TEMPLATE_ID "Tanc Apa"
// Select your modem:
#define TINY_GSM_MODEM_SIM800
//#define TINY_GSM_MODEM_SIM900
//#define TINY_GSM_MODEM_M590
//#define TINY_GSM_MODEM_A6
//#define TINY_GSM_MODEM_A7
//#define TINY_GSM_MODEM_BG96
//#define TINY_GSM_MODEM_XBEE
// 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[] = "Qz7bDuRDBxrzAlYePU2dJHpYVAotQrmb";
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "ipfix.vodafone.ro";
char user[] = "";
char pass[] = "vodafone";
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
// or Software Serial on Uno, Nano
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
int senzorpin = A0;
int valoare;
TinyGsm modem(SerialAT);
BlynkTimer timer;
int sensorValue;
void setup()
{
timer.setInterval(1000L, sensorDataSend);
// Debug console
Serial.begin(9600);
delay(10);
// Set GSM module baud rate
SerialAT.begin(9600);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
// Unlock your SIM card with a PIN
modem.simUnlock("");
Blynk.begin(auth, modem, apn, user, pass);
}
void loop()
{
Blynk.run();
timer.run();
}
void sensorDataSend()
{
sensorValue = analogRead(A0); // reading sensor from analog pin
sensorValue = map(sensorValue, 200, 1023 , 0, 10000 ); // maping 1-5V
Blynk.virtualWrite(V0, sensorValue); // sending sensor value to Blynk app
}
Thank for the help now it seems to be working well. Ping is 300ms! Pleas help me with an idea to do a notificaction function that sends me x notifications and then stops if the analog value is <= y and a notification one time if the analog value >= y and then stops
Thank you in advance
Thank you, it seems to work but a I was forced to use 6 second delay to send 5 notifications. That delay is ok? If I want to use AT commands for example call comand how can I do it? Can I make in this void?
void sensorDataSend()
{
valoaresenzor = analogRead(senzorpin); // reading sensor from analog pin
valoaresenzor = map(valoaresenzor, 200, 999 , 0, 10000 ); // maping 1-5V
Blynk.virtualWrite(V0, valoaresenzor); // sending sensor value to Blynk app
if ((valoaresenzor <= 2000) && (min_notifications <=5))
{
Blynk.notify("Alarma nivel minim, Se incearca recuperarea");
min_notifications ++ ;
max_notifications = 0 ;
delay (6000) ;
}
else if ((valoaresenzor >= 2500) && (max_notifications <= 1))
{
Blynk.notify("Nivel apa recuperata");
max_notifications ++ ;
min_notifications = 0 ;
delay (2000) ;
}
}
makes no mention of delays between notifications, yet it appears that delays play a part in what you want to achieve.
Without fully understanding your overall goal, it’s difficult to advise further.
Probably a bad choice, but without understanding your goal it’s difficult to advise.
My goal is to send 3 notifications if analog valuae is smaller than X and one notification if analog value is biger then Y!
This code worked well, if I removed “delay” then I only received one notification instead of five in Blynk app
LE: I think I need a break(delay) between notifications
void sensorDataSend()
{
valoaresenzor = analogRead(senzorpin); // reading sensor from analog pin
valoaresenzor = map(valoaresenzor, 200, 999 , 0, 10000 ); // maping 1-5V
Blynk.virtualWrite(V0, valoaresenzor); // sending sensor value to Blynk app
if ((valoaresenzor <= 2000) && (min_notifications <=5))
{
Blynk.notify("Alarma nivel minim, Se incearca recuperarea");
min_notifications ++ ;
max_notifications = 0 ;
delay (6000) ;
}
else if ((valoaresenzor >= 2500) && (max_notifications <= 1))
{
Blynk.notify("Nivel apa recuperata");
max_notifications ++ ;
min_notifications = 0 ;
delay (2000) ;
}
}
You need to work within the limitations of the Notifications system:
Limitations:
Maximum allowed body length is 120 symbols;
Every device can send only 1 notification every 5 seconds;
but changing the timer that controls how often your void sensorDataSend() function is called would resolve that without the need for delays or timeout timers.