Blynk taking to much data

Hello everyone! I have an arduino uno and sim900 gsm shield with things mobile sim card. It almost takes a whole megabyte a single day. For example, i have a relay that i control with blynk and when i press go on my app the relay almost clicks immediately and it would not have to… it could wait till a minute.

Would there be a way to slow the process down so that it would not take so much data?

Im wondering if you re-established communication every minute just to update the pin, if it would end up being the same amount of traffic. Im running some traces right now on my nodemcu to see how much data it uses with each type of config.

Just so i can share my results pertinent to you faster, are you running just a basic blynk starter sketch, where you are using the app to change the Dpin or something with some Vpins in it and more than one pin being called?

Blynk needs to talk to the server constantly to check for any changes resulting from widget operations in the app. I think it maybe does this each time Blynk.run executes.

You could do a Blynk.disconnect, then have a timer do a Blynk.connect every minute. It would probably need to be followed by a Blynk.syncVirtual(vPin) then another Blynk.disconnect.

The disadvantage is that the device would show as offline in the app most (if not all) of the time.

Pete.

thank you PeteKnight and lvennard. here is my sketch;

#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM900
// 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 <BlynkSimpleSIM800.h>
#define TINY_GSM_DEBUG Serial
uint32_t rate = 9600;
BlynkTimer timer;
char auth[] = "*****************************************";
char apn[]  = "TM";
char user[] = "";
char pass[] = "";
#include <SoftwareSerial.h>
SoftwareSerial SerialAT(2, 3); // RX, TX
TinyGsm modem(SerialAT);



WidgetLED preAlarm_led(V5);
WidgetLED exercise_led(V7);
WidgetLED run_led(V13);
WidgetLED air_led(V12);
int preAlarmState = 0;
int vac_pin = A0;
int vac=0;
int rssi = 0;
int engineSig =0;
int temp_pin = A3;
float temperature;
float millivolts = 0;
int sensorValue = 0;
int tempAjust=0;
int dumpcount = 0;
int exerciseDump = 0;
int exerciseState = 0;
int exerciseSwitch =0;
int exerciseOverWrite =0;
int dumptrue=0;
int dumpPin = 4;
int airCounter = 0;

void(* resetFunc) (void) = 0; //declare reset function @ address 0


BLYNK_WRITE(V10){//// 
  int bstate = param.asInt(); 
  if(bstate ==1){
    Blynk.disconnect();
  }
 }

BLYNK_WRITE(V6){////temp ajustment
  tempAjust = param.asInt();
}

BLYNK_WRITE(V4){//// RESET DUMPS BUTTON
  int bstate = param.asInt(); 
  if(bstate ==1){
    dumpcount =0;
  }
 }

BLYNK_WRITE(V8){//// START ENGINE
  if(param.asInt() == 1){
   engineSig =1;
   digitalWrite(10,HIGH);
   exerciseState = 0;
   exercise_led.off();
  }
  if(param.asInt() == 0 && exerciseState == 0){ 
    engineSig =0;
    digitalWrite(10,LOW);
  }
}

BLYNK_WRITE(V9){//// exerciseSwitch(Automatic or not)
   if(exerciseOverWrite == 0){
   exerciseSwitch = param.asInt();
   }
  }

BLYNK_WRITE(V11){//// manual air valve
  if(param.asInt() == 1){
   digitalWrite(11,HIGH);
  }
  else{digitalWrite(11,LOW);}
  }
  
void exerciseTimer(){
  if(exerciseSwitch == 0){
  if(digitalRead(10)==HIGH && exerciseState == 1){
    airCounter++;
   }
  if(digitalRead(10)==LOW){
   if(temperature >= tempAjust){
      digitalWrite(10,HIGH);
      if(airCounter > 2){
    digitalWrite(11,HIGH);
    }
      exerciseState = 1;
      exercise_led.on();
     }
  }
  else if(digitalRead(10)==HIGH && exerciseState == 1 && exerciseDump == 0 && engineSig ==0){
    digitalWrite(10,LOW);
    if(airCounter > 2){
    digitalWrite(11,LOW);  
    airCounter = 0;
    }
    exerciseState = 0;
    exercise_led.off();
  }
  exerciseDump = 0;
   } 
 }



void myTimerEvent(){
  
  if(digitalRead(7) == LOW){
    exerciseSwitch = 0;
    exerciseOverWrite = 1;
  }
  else{exerciseOverWrite = 0;}
  
  if(digitalRead(5) == LOW){
    preAlarm_led.on();
    if(preAlarmState == 0){
      Blynk.notify("Sap Engine preAlarm!!");
      preAlarmState = 1;
    }
  }
  else{preAlarm_led.off(); preAlarmState = 0;}

  if(digitalRead(6) == LOW){
    run_led.on();
  }
  else{run_led.off();}

  if(digitalRead(11) == HIGH){
    air_led.on();
  }
  else{air_led.off();}
  
  
  delay(1000);
  sensorValue = analogRead(temp_pin);
  millivolts = sensorValue*5.0;
  millivolts /= 1024;
  temperature = (millivolts - 0.5) *100;
  
  
  
  vac = analogRead(vac_pin);
  vac = map(vac,0,884,30,0);
  
  if(Blynk.connected()==false){
    digitalWrite(9,LOW);
    delay(100);
    resetFunc();  //call reset
   }
  else if(Blynk.connected()==true){
    digitalWrite(9,HIGH);
    Blynk.syncAll();
  }
  SerialAT.write("AT+CSQ\r\n");
  delay(150);
 if(SerialAT.available()>=19) {
      for (int i = 1; i<9; i++) {
      byte discardByte = SerialAT.read(); 
      }
      // SerialMon.write(SerialAT.read());
      rssi= SerialAT.parseInt();
      while(SerialAT.available()){
      byte discardByte = SerialAT.read();  
    }
  }
  
  Blynk.virtualWrite(V0, rssi);
  Blynk.virtualWrite(V1,temperature);
  Blynk.virtualWrite(V2,vac);
  Blynk.virtualWrite(V3, dumpcount);

}

void setup()
{
  pinMode(9,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(13,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(A3,INPUT);
  pinMode(A0,INPUT);
  Serial.begin(9600);
  delay(10);
  SerialAT.begin(9600);
  delay(3000);
  // Restart takes quite some time
  // To skip it, call init() instead of restart()
  Serial.println("Initializing modem...");
  modem.restart();
  Blynk.begin(auth, modem, apn, user, pass);
  timer.setInterval(60000L, myTimerEvent);///////60000L
  timer.setInterval(1800000L, exerciseTimer);/////1800000L
  if(Blynk.connected()==false){
    digitalWrite(9,LOW);
  }
  else if(Blynk.connected()==true){
    digitalWrite(9,HIGH);
    Blynk.syncAll();
    exercise_led.off();
  }
}

void loop()
{
  Blynk.run();
  timer.run();

  if(digitalRead(dumpPin)==HIGH){
    dumptrue=0;
   }
   
  if(digitalRead(dumpPin)==LOW){
    if(dumptrue==0){
    dumpcount++;
    exerciseDump++;
    }
    dumptrue=1;
   }
  }
    ```

You need to edit your last post so that the code displays correctly:

Blynk%20-%20FTFC

Pete.

Ya sorry i was hoping it would not do that i got it now :grinning:

Sorry there i did not get it to take less data… would it work to do a disconnect every minute?

What does your sketch with the 1 minute Blynk disconnect look like?

Any comments I make about what may and may not work are just speculation - I haven’t tried this approach and don’t have the hardware that you’re using, so it’s really down to see what works - I’m just trying to feed you ideas.

Other may have tried what you’re attempting and have some insight as a result - if so then I’m sure they’ll chip-in.

Pete.

I ran just a connectivity script. No PIN data was sent back and forth. My client and my phone app stayed connected for 1.5 hours.
It showed 100K or traffic. 66.6K sent by the client 33.3K sent by the server.

Resulting in :
1.5 hours X 8 = 24 hours
100K X 8 = 1.5MB

In one full 24 hour day, 1.5MB would be sent/recieved.

I’ll run another study after supper where i disconnect and reconnect again every minute. (i have to write it first)

1 Like

Really big thank u lvennard and peteKnight. Looking forward to the results

Heres the code i ran, notice i did add a virtual write in there… just a tiny one. to make sure i had real life scenario connectivity. I wasnt sure if the write would always be successful before the disconnect. It turns out it was always successful, but if i were you i would still put an extra check before the disconnect. Im on my local lan, so my connectivity would be optimal compared to gsm.


#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "<auth>";
char ssid[] = "<ssid>";
char pass[] = "<pass>";


BlynkTimer timer;

void runME() {
  Blynk.begin(auth, ssid, pass, IPAddress(10,9,8,7), 8080);
  while (Blynk.connect() == false) {
    // do nothing but wait
  }
  Serial.println("Fully Connected");
  Blynk.virtualWrite(V1, 1);
  Serial.println("Updateing V1");
  Blynk.disconnect();
  Serial.println("Disconnecting");
}

void setup()
{
  Serial.begin(9600);
  timer.setInterval(60000, runME);
}

void loop()
{
  timer.run();
}

It ended up, the data usage was worse because of the data needed to build the connection. In the end we would pull
**

2.1MB per day

**

1 Like

doing some math… every 2 mins would be 1MB of data

Constant Connection Per day
1.5 Mb
Every 1 min - REconnect
2.1 Mb
Every 2 mins - REconnect
1 Mb
Every 3 mins - REconnect
0.71 Mb

Of course, this doesnt include all your data, but gives you a start.

Good luck man… Im curious to know how you come out on this .

1 Like

Thank you for taking the time to help me! I’ll do more work on that but im installing this operation tomorrow so times kinda up! It just will cost around 50$ max a month. It only gets used a couple month’s a year. I will also be installing more. I emailed blynk and this is what they said

Hi Daniel,

You can use Blynk HTTP API and potentially Particle Webhooks https://docs.particle.io/reference/device-cloud/webhooks/

Or Blynk Webhooks + Particle HTTP API

Also, some information here:

What do u think about this?

Interesting…in a good way.

we really need gunner and dmitriy to chime in for sure since that library is aged. but it looks like we can manually change it in BlynkConfig.h

#define ANIT_USE_128_VPINS  // Uncomment this 

#ifndef BLYNK_HEARTBEAT
#define BLYNK_HEARTBEAT      10  // change this out to adjust

I like the sound of it, but its way past my network brain. I have to bow out at this point.

EDIT: pete might know as well, but not sure if he was a blynker back that far.

1 Like

There are things you need to check:

  • In case of the local server - check the logs (in the trace mode) so you can see how many times hardware reconnects during the day. It may happen that the main issue is due to often connections drop;
  • How exactly do you use the app? During this testing day what functions do you use? Do you have some timers, eventors, SYNCs?

It sounds like it’s too late to come-up with a workable solution at this stage in the game, but there’s obviously a need to have something better in future, so here’s my thoughts on what’s been said so far…

With @lvennard’s test code, I don’t know if there’s any benefit in doing a Blynk.begin in void setup, followed by blynk.connect and blynk.disconnect in the void runME() function?

If you were going down the webhooks route then you don’t need any Blynk code at all, so the Blynk heartbeat settings are irrelevant.
You’d need to create an HTTP client object and make GET calls to check on the button state. The Blynk API allows GET to be used as PUT, so GET can be used for inbound and outbound API calls - if there any need to upload data as well as look for “instructions” in the form of button widget changes.
I rejected the idea of using webhooks when @danhoo first outlined his problem, as the amount of data that needs to be sent to make the API call is quite large. There might be a better way to make the call that uses less data - it’s not something I’ve ever tried.
Webhooks are great when you want a device to wake-up, connect to the network and quickly exchange some data then go back to sleep. Speed is good, but I think the quantity of data exchanged is probably fairly high.

I think the best option might be a different type of SIM contract, which maybe allows data bundles to be purchased at a lower cost than if you’re just paying by the megabyte.

Pete.

Only posting this for the curious minded.
I did run the code with your recommendations @PeteKnight . Much better results.

Constant Connection Per day
1.5 Mb
Every 1 min - REconnect OLD METHOD
2.1 Mb

Every 1 min - REconnect NEW METHOD (code below)
1.3 Mb per day
Every 2 min - REconnect NEW METHOD (code below)
0.65 Mb per day

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "<auth>";
char ssid[] = "<ssid>";
char pass[] = "<pass>";

BlynkTimer timer;
void runME() {
  while (Blynk.connect() == false) {
    // do nothing but wait
  }
  Serial.println("Fully Connected");
  Blynk.virtualWrite(V1, 1);
  Serial.println("Updateing V1");
  Blynk.disconnect();
  Serial.println("Disconnecting");
}

void setup()
{
  Blynk.begin(auth, ssid, pass, IPAddress(10,9,8,7), 8080);
  Serial.begin(115200);
  timer.setInterval(60000, runME);
}

void loop()
{
  timer.run();
}
1 Like