Calculating Data Use

Is there a simple way to forecast/calculate my expected data usage? I am pulling 60 bytes of data every minute 24/7, and would like to send that data on either a 1, 5, 10, 15 or 20 minute interval. I’m trying to figure out what my data usage, including overhead would amount to there.

Thanks,
Aaron

You’re not the first to ask
Have you browsed through these threads?
https://community.particle.io/search?q=data%20usage

I have browsed most of them, I was never able to discern a clear answer (though that could just be because this is all over my head).

For example, in one of those threads it reads like one comment says to expect that with every post there will be 8 bytes of UDP header, adn ~20bytes of IPv4 header. There are 122 bytes for the Ping every 23 minutes (which I assume does not come into play if I’m communicating at sub 23 minute intervals).

The comment immediately below that seems to say that each Post comes with 130 bytes of overhead, and does not acknowledge the previous comment (side note, does this mean that overhead is 50% of the total publishable size for any given message)?

Further down, it looks like you can out 61 bytes of overhead by not having the system acknowledge the electron when it publishes.

Again, I fully admit that I’m in over my head here - just trying to ballpark what data sizes might be.

Is there just a simple cheat sheet somewhere that says, here is the largest message you can publish, here is the fixed overhead for a message?

Thanks,
Aaron

One easy way to know for sure is to declare your publish_delay as an integer and create a Particle.Function that allows you to change the publish_delay from the Particle Console “on-the-fly”.

Let your code run for a day or two with a 5 min publish_delay. If the data usage is too high, you can quickly increase it with the Function without re-flashing your entire Code OTA.

Once you feel comfortable with your Data Usage, Re-Flash with the publish_delay you want - because the Electron will revert back on every reboot and forget what you’ve changed it to via the Function.

Something Like This :


SYSTEM_THREAD(ENABLED); 
     
int publish_delay =  300000;   // 300000 = 5 minutes
unsigned long now = millis(); 
unsigned int lastPublish = 0;  

void setup() { 

  // Register Particle Function to allow user to remotely Change the Publish Delay.   
  Particle.function("setDelay", setPublishDelay);

} // End Setup


void loop() {
    
  now = millis();   // update the Time each Loop
  
  
/////  Your Main Code Goes Here /////



  if (abs(now - lastPublish) > publish_delay) {  // Only publish after the publish_delay has elapsed. 
       
     ///// Your Publish Code Goes Here /////
    lastPublish = now; 
  }  

}  // End Loop



//Funciton to change the Publish Delay remotely, without needing to reflash the Firmware.  
int setPublishDelay(String command) {
publish_delay = ( command.toInt() * 60000 );
//send the # of MINUTES as an Argument to the setPublishDelay FUNCTION. Value must be an Integer....1,2,3, etc in Minutes.
}


I don’t think the Absolute Value (abs) is required, but it doesn’t seem to hurt.
I’m sure there are ways to improve this code, but it should get you started.

1 Like