Blynk / Electron Data Usage EXTREMELY HIGH

I have adjusted the code pushed to my Electrons 3 times now and seen NO reduction in data usage on any of my cores…

Current values in the code are:

 #define BLYNK_HEARTBEAT 300     //was 60
 #define PARTICLE_KEEPALIVE 300   //was 20

After that change I am still seeing Blynk eat up huge amounts of data… What is going on? Why is this having no effect?!?

I am pulling 2 values every 5 minutes from 4 sensors and somehow this is costing me almost 3MB of data PER DAY on these devices…

HELP!

If the above is not showing effect, then that is probably because something else is using the data. Show the rest of your code…

Have you done the math on this? I am no good at math, so here’s hoping I don’t do a faceplant :stuck_out_tongue: But assuming 1KB per sensor (just a big fat guess here) * 2 (values) * 4 (sensors) * 288 times a day = aprox 2.4MB plus any connection overhead.

I would hope it isn’t 1K per sensor, the values are 2 bytes for each sensor, not sure if the connection is made via TCP or UDP but anything above those 2 bytes is essentially overhead, hard to believe that would require another 998 bytes.

Here’s full code:

//Libraries
#include <Adafruit_DHT.h>                           //DHT22 Sensor Library
#include <cstdlib>                                  //for comparing past and present sensor values
#include <cmath>                                    //for comparing past and present sensor values, floats wont compare without this
#include <blynk.h>                                  //Phone Visualization / App Integration Library

#define DHTTYPE DHT22                               // Sensor type DHT11/21/22/AM2301/AM2302
#define DHTPIN D1                                   // what pin we're connected to     


//Blynk Code Start
#define BLYNK_PRINT Serial  // Set serial output for debug prints
//#define BLYNK_DEBUG       // Uncomment this to see detailed prints

// Run "ping blynk-cloud.com", and set Blynk IP to the shown address
#define BLYNK_IP        IPAddress(45,55,96,146)

// Set Blynk hertbeat interval.
// Each heartbeat uses ~90 bytes of data.
#define BLYNK_HEARTBEAT 300     //was 60

// Set Particle keep-alive ping interval.
// Each ping uses 121 bytes of data.
#define PARTICLE_KEEPALIVE 300   //was 20

//Auth Codes for Blynk


char auth[] = "<redacted>";                      //Blynk Auth Token
//Blynk Code End

/*
//Device and Sensor Labels
String DevName   = "WAS_001";
String HumName   = "_Humidity";
String TempName  = "_Temperature";
String CO2Name   = "_CO2";
String LightName = "_Light";
*/

// adafruit lib instantiate
DHT dht(DHTPIN, DHTTYPE);


// Spark Variables
int temp = 0;
int hum = 0;

//Main Loop Sensor Vars
long SenseMillis     = 0;       //Storage variable for loop timing
long SenseInt        = 300000;   //This is how often the sensor is read
int Temp             = 0;       //Current Temperature Reading
int Humi             = 0;       //Current Humidity Reading
int TempDiff         = 0;       //Differential between last and current value of sensor read
int HumiDiff         = 0;       //Differential between last and current value of sensor read
int lastTempUpdate   = 0;       //Last value seen by the sensor
int lastHumiUpdate   = 0;       //Last value seen by the sensor
int TempSensorFilter = 10;      //These would be roughly equivalent to temperature degrees
int HumiSensorFilter = 10;      //These would be roughly equivalent to each % of humidity


void setup() {
    delay(5000);
    Serial.begin(9600);
    dht.begin();
    delay(2000);
    HumiDiff = dht.getHumidity();            // Read humidity
    delay(2000);
	TempDiff = dht.getTempFarenheit();       // Read temperature as Farenheit

    Particle.keepAlive(PARTICLE_KEEPALIVE); //Blynk Requirement
    Blynk.begin(auth, BLYNK_IP);            //Blynk Requirement

   
    //Turn off LED (or change colors)
    RGB.control(true);
    int r = 0;
    int g = 0;
    int b = 0;
    RGB.color(r, g, b);
}


void loop() {
    Blynk.run();
    //Spark.publish("Entering Loop", "Entering Loop");              //DEBUG
    unsigned long currentSenseMillis = millis();
    if(currentSenseMillis - SenseMillis > SenseInt) {
        SenseMillis = currentSenseMillis; // save the last time you ran this code
        
        
        Temp = dht.getTempFarenheit();       // Read temperature as Farenheit
	    delay(2000);
        Humi = dht.getHumidity();            // Read humidity
        
        Serial.print("Humi: ");
        Serial.println(Humi);
        Serial.print("Temp: ");
        Serial.println(Temp);
        
        TempDiff = std::abs(Temp-lastTempUpdate);   //Check current reading against previous, report the difference
        HumiDiff = std::abs(Humi-lastHumiUpdate);   //Check current reading against previous, report the difference
        
        //Check Temperature Reading and Report
        if (TempDiff < TempSensorFilter  && HumiDiff < HumiSensorFilter) { 
            Blynk.virtualWrite(V0, Temp);
            Blynk.virtualWrite(V1, Humi);
        }

        
        
        
        //Watchdog, restart Electron if it can't connect to the cloud
        if( ! Spark.connected()) {
            Spark.publish("Restarting", "Restarting");
            System.reset();
        }
        
    lastTempUpdate = Temp;
    lastHumiUpdate = Humi;
    }
}

Ya, 1K was easy for me to calculate :wink:

Each virtualwrite will be about 5 bytes, plus data, which on a DHT11 may be around 2 bytes or so per sense (temp and Hum), so aprox 14+ bytes per data transmission. Plus 5 Bytes per heartbeat and keepalive?.. and who knows what else.

https://github.com/blynkkk/blynk-server/blob/master/docs/README_FOR_APP_DEVS.md#protocol-messages

Perhaps enable Debug and see what else might be going on.

Also, perhaps reduce the data to every 30 minutes? Every 5 minutes for Temperature and Humidity is like that annoying “are we there yet” in the back seat.

The reason it isn’t 30 minutes is because this is tied (or will be) to an alarm trigger, logging and historical data is 1/2 the reason for the sensor, the other half is for emergency alerting “Temp is too high”, if I find out 30 minutes later the heat is too high, then it’s already 25 minutes too late.

Each transaction is roughly 8 bytes, so 288 transactions in a day is only 2,304 Bytes, or 2.3KB, which is an order of magnitude smaller than 2.4MB per day. You were off by three zeros basically.

I will try the debug and see what the hell is happening.

That is easily done in code… regular reading every 30+ minutes, unless conditions prompt immediate notification alerts… Extra code logic (in of itself) will not increase data transmission… but poor event reporting structure can (every 5min vs. every 30min plus alerts).

That would be per virtualWrite, so double the daily data with two virtual writes… and that is NOT counting heartbeats and such… If I understand the GitHub document those are all min 5 bytes each as well??

regular reading every 30+ minutes, unless conditions prompt immediate notification alerts

Not a bad point. Still I don’t think the resolution of the graphs would be where I want it to be, but your point is well taken regarding changing how I do the alerts themselves.

That would be per virtualWrite, so double the daily data with two virtual writes

Yeah, even doubling that gets us to 4.6K / Day, something is still horrendously wrong with the amount of data that’s currently being transferred.

Getting absolutely nothing on the serial console when I enable Debug printing btw… I have my standard serial prints from my own Debug stuff but nothing from Blynk processes are posting ANYTHING.

I have a sneaking suspicion that anything in the code itself is being overridden or just generally ignored… I am doing all the code via the standard include of the Blynk library on the Particle Web IDE so maybe something about the library included automatically there is having some problems where it isn’t respecting the values in the compiled .ino or something. Going to see if bringing this all to a local IDE with the libraries will fix it.

@jboswell what makes you think the issue is within Blynk? You need to check few things:

  1. Remove Blynk.begin(auth, BLYNK_IP); and Blynk.run(); and Blynk.virtualWrite from your code and repeat test. Do you see same consumption?
  2. If consumption is decreased dramatically - the issue is with Blynk; So now just remove Blynk.virtualWrite. Do you still see high consumption?
  3. If yes, poroblem either in PING packets or with something not visible in code you provided. Do you have “reading widgets” within app?

P. S. I did some calculations. PINGs in worst case will take 10kb a day. virtualWrite will take 20kb a day in worst case for you.

This code was using Ubidots for logging as of about a month ago, fraction of the data usage I am seeing now in Blynk.

I have 2 widgets per sensor and a historical graph for each sensor pulling the same two variables from the same sensors.

Basically 8 different data streams at the moment. I don’t see any data usage when I remove Blynk, this code has been running the same way for more than 6 months, didn’t like GUI that Ubidots had, nor the stability of the Dashboards. Love the dashboards that Blynk has, and the stability, so far though the data usage is insane. I will disconnect the graphs, maybe those are the issue?

Nope. What widgets do you have? And what are their settings?

@jboswell maybe you have this - http://docs.blynk.cc/#blynk-main-operations-get-data-from-hardware-perform-requests-by-widget ?

4 Historical Graphs, 1 for each sensor.
8 Value Displays, 2 for each sensor, reading data every 5 min.

Code from the Particle Web IDE has the heartbeat and keep-alive’s set at 5 min, noticed absolutely no difference in data usage when changing those.

Please post screenshot here of value display widget.

Checked multiple times, all at 5 min rates.

That’s wrong. You need to select “PUSH” mode.

Done. Wouldn’t it be basically the same, if I poll every 5 min, or Blynk polls every 5 min, it’s still 5 min…

No. With Reading Widgets you have next flow:

server -> hardware -> server -> app

With Widgets in PUSH mode:

hardware -> server -> app

So you save at least 1 message per widget.

However 3 MBs a day still seems to me too much even in that case.

Yeah, so at least those sensors are now only pulling data once, but even if they were all pulling data as inefficiently as possible I would have to work REALLY hard to get 2.5MB/day on each sensor… Only when I started using Blynk did I see usage this high, normally, even on Ubidots I was seeing maybe 5MB/month.