Data usage with Electron

New to Blynk and have some experience with Particle, but am still a newbie trying to learn the ropes.

I purchased an Electron with Relay board in order to control electric heat at our cottage. I am really only interested in controlling the main heater at this point in time, so one relay. I eventually want to install a temperature reading as well but for now am trying to start simple.

I used Blynk to generate the following code and it works fine, but my data use is quite high.

#define BLYNK_PRINT Serial
#define BLYNK_IP        IPAddress(45,55,130,102)
#define BLYNK_HEARTBEAT 1200
#define PARTICLE_KEEPALIVE 150

#include <blynk.h>

char auth[] = "123";

BlynkTimer timer;

void myTimerEvent()
{

  Blynk.virtualWrite(V5, millis() / 1000);

}

void setup()
{

  Serial.begin(9600);

  delay(2000);

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

  timer.setInterval(1000L, myTimerEvent);
}

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

I set the Blynk Heartbeat and Particle Keepalive to higher levels as I read that in some other postings they could reduce traffic. Last night I uploaded the code, added the button to Blynk and turned on the relay from my phone. I left it turned on for one hour and my data usage jumped to 0.89MB!

I assume there is a better way to do this. I will really only be using this app over the winter so the Electron will sit dormant for a couple of months then be activated on a Friday afternoon once winter hits. I need to keep the relay active for the weekend (while at the cottage) then turn it off when I leave. It will sit dormant for another couple of weeks until I head up again. I therefore really only want to transmit commands to the device when I need to turn on the relay only. Most of the time it will be inactive. I assume both Blynk and Particle need some form of keep alive to ensure they can see the device, but I was hoping to control this device within the 1MB/month which is supplied by default.

Any suggestions?

You can also read about a simular issue in this topic, but please keep your discussions about your issue in your topic so as not to get the two mixed up to much :wink:

Also, it sounds like deep sleep might be an option for your situation as well… Sleep, wake, check situation, adjust control, sleep again for a few minutes/whatever, repeat…

I assume you mean this command?

System.sleep(long seconds) does NOT stop the execution of application code (non-blocking call). Application code will continue running while the cellular module is in standby mode.

Once I turn the relay on I will need to ensure the microcontroller stays powered on, but I don’t need the cellular signal. I assume this is the best command to allow this? Is there a limit to how many seconds you can enter in this field?

If you are using the very old Arduino core (2.3.0) then it’s around 72 “ESP minutes”. If you are using the latest version of the core then it’s around 200 “ESP minutes”. It’s not an exact figure as it’s based on the precise clock frequency of your ESP from one minute to the next and no two ESP’s are identical.

“ESP minutes” are approximately 98% of an atomic clock minute.

Thanks for the reply Costas.

So if I put the unit to sleep for 60 minutes, but leave the controller running, what happens? In my code it is expecting to connect to Blynk every 20 minutes. Likewise Particle is expecting a connection every 23 minutes. When the unit comes out of sleep mode I assume it needs to authenticate again with both services. Does that use more data than just leaving it enabled?

Can my existing code be optimized to minimize the data use? I re-flashed my Electron with Tinker and I have only used 0.02 MB of data to enable the relay (D3) over the past 48 hours. Really all I’m trying to do is turn that relay on and off remotely, but I was hoping to use Blynk to pretty it up (as other family members will need to use this as well). If the existing code could be optimized to only use data levels like Tinker that would be the best solution.

Please don’t create new threads if there’s an open discussion on the topic.