So, I have a strong suspicion that this is a problem with the library implementation on the Particle Web IDE not compiling the Blynk library properly, but I really don’t know.
Basically everything works, works so great in fact that I would totally still be using Blynk if it wasn’t for how much data it’s consuming right now (2.5MB / day).
Essentially I am posting 4 bytes every 5 minutes and seeing this data usage. Confirmed exactly what I am sending to their servers so I am assuming the issue is with the Heartbeat and Keepalive settings not being called correctly from their library. I assumed (it would seem wrongfully so) that they had been the ones that posted their library on the Particle Web IDE.
In any case, I have an exceedingly simple sketch, and basically the high data usage is seen when Blynk.run(); is just sitting in the loop. If anyone can take a quick look I would appreciate it, I tried moving the Blynk run into my millis loop but without the code respecting the Keepalive and Heartbeat settings I think it times out waiting for a response from my Electron and not getting it…
Code below, if anyone would be so kind as to have a look:
//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
// 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);
//Initial Humidity read *** IF THIS READ IS INACCURATE ALL FURTHER READINGS WILL FAIL
HumiDiff = dht.getHumidity(); // Read humidity
delay(2000);
//Initial Temp Read *** IF THIS READ IS INACCURATE ALL FURTHER READINGS WILL FAIL
TempDiff = dht.getTempFarenheit(); // Read temperature as Farenheit
Particle.keepAlive(PARTICLE_KEEPALIVE); //Blynk Requirement
Blynk.begin(auth, BLYNK_IP); //Blynk Requirement
//Spark.publish("Leaving Setup", "Leaving Setup"); //DEBUG
Serial.print("Program Starting");
//Turn off LED (or change colors)
RGB.control(true);
int r = 0;
int g = 2;
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) {
//ubidots.add("H", Humi);
//ubidots.add("T", Temp);
//ubidots.add("DeviceName", DevName);
//ubidots.setMethod(TYPE_TCP); //Set to TCP the way to send data
//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;
}
}