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 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;
}
}
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.
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??
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.
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?
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.