CELLULAR USAGE Statistic and explanation [Solved]

Hello,
Question how traffic counting is working.

I in program send each 1hour two publish with 250 chars. And eat on 2 day 25Mb. How it is possible?

Is webhooks data traffic counting too in this CELLULAR USAGE?

My account royn@rco.com
SIM ended on …6087

Is there any satistic for what this traffic was used?

Thank you.

To explain that we might need to know more about your code.
Could you share it?

There are other things that also consume data. So for example does every disconnect/reconnect to the cell towers cost up to 6KB.
Also whether you’re using a Particle or a 3rd party SIM makes a difference.

Here is code

// This #include statement was automatically added by the Particle IDE.
#include "/ParticleFtpClient/ParticleFtpClient.h"
#include <time.h>

//#define FTP
#define PUBL

//#define NOT_SLEEP
#define SLEEP

PRODUCT_ID(1303);
PRODUCT_VERSION(2);

using namespace particleftpclient;

String hostname = "------------";
String username = "------";
String password = "-------------";

int timeout = 5;

ParticleFtpClient ftp = ParticleFtpClient();

SYSTEM_MODE(SEMI_AUTOMATIC);

float MoistFilt[10];
float TempFilt[10];

int mesuring_done = 0;
int CellCon = 0;
int ReadyToSleep = 0;
int PublishDone = 0;

void setup()
{
 Time.zone(-4);
 Serial.begin(9600);
 Particle.subscribe("D", myHandler);
}

void myHandler(const char *event, const char *data)
{
if (strcmp(event,"D")==0) {ReadyToSleep = ReadyToSleep + 1;}
}

float Temperature()
{
int A1_Raw;
float tmp;
float Temp;
float Sum;
float y;


for (int i = 0; i < 10 ; i ++)
{
	 A1_Raw = analogRead(A1);
	 y =  A1_Raw;
	 tmp = (3.3*y)/4096;	 
	 Temp = tmp*75.006 - 40;
	 TempFilt[i] = Temp;
}
	 Sum = 0;
	 for (int i = 0; i < 10 ; i++) {Sum = Sum + TempFilt[i];}
	 Sum = Sum / 10;
 return Sum;

}

float Moisture()
{
int A0_Raw;
float tmp;
float Moist;
float Sum;
float y;


for (int i = 0; i < 10 ; i ++)
{
	 A0_Raw = analogRead(A0);
	 y =  A0_Raw;
	 tmp = (3.3*y)/4096;	 
	 if (tmp > 0 and tmp <= 1.1){  Moist = 10*tmp-1; }
	 if (tmp > 1.1 and tmp <= 1.3){  Moist = 25*tmp-17.5; }
	 if (tmp > 1.3 and tmp <= 1.82){  Moist = 48.08*tmp-47.5; }
	 if (tmp > 1.82){  Moist = 26.32*tmp-7.89; }
	 MoistFilt[i] = Moist;
}
	 Sum = 0;
	 for (int i = 0; i < 10 ; i++) {Sum = Sum + MoistFilt[i];}
	 Sum = Sum / 10;
 return Sum;
}

void loop()
{
     Serial.println("Looping call");

   int index = 0;
   float value = 0;
   String stringOne = "";
   String sensorRecordId = "232312";
   int intervalSeconds = 1800;
   bool sent = false;
   String startDateTime = Time.format(Time.local()-1800*48, "%Y-%m-%d  %H:%M:%S");// "2016-08-05 00:00:00";
   String userrecordid = "411337";
   String orgnum = "8";


   EEPROM.get(0, index);

   if (mesuring_done == 0) 
   {


	   value = Moisture();

	   EEPROM.put(index*4, value);

	   Serial.println(String::format("Moist = %3.1f",value));   
	   Serial.println(index);


	   value = Temperature();

	   EEPROM.put(index*4+300, value);

	   Serial.println(String::format("Temp = %3.1f",value));   
	   Serial.println(index);

	   index = index + 1;

	   EEPROM.put(0, index);

	   mesuring_done = 1;           
   }
 
   if (index > 47)
   {
     if (Particle.connected() == false) 
		{
		        
			if (CellCon = 0) { Cellular.on(); CellCon = 1;}
			
			if (!Cellular.ready()) {Cellular.connect();}
		        if (Cellular.ready())  {Particle.connect();}

		}

#ifdef FTP
     if (PublishDone == 1) {ReadyToSleep = 2;}
#endif
     
     if (Particle.connected() == true && PublishDone == 0 &&  System.updatesPending() == false)
     {
	     Serial.println("Cloud ready");

#ifdef PUBL
	     stringOne = "1,1800,";

	     for(int i=1;i<49;i++)
		{
			EEPROM.get(i*4,value);
			stringOne = stringOne + String::format("%3.1f",value) +",";
		}

	     stringOne = stringOne.remove(stringOne.length()-1);

	     Serial.println(stringOne);
	    
	     stringOne = String(stringOne);

	     Serial.println(stringOne);
	     sent = Particle.publish("D", stringOne);


	     stringOne = "2,1800,";

	     for(int i=1;i<49;i++)
		{
			EEPROM.get(i*4+300,value);
			stringOne = stringOne + String::format("%3.1f",value) +",";
		}

	     stringOne = stringOne.remove(stringOne.length()-1);

	     Serial.println(stringOne);
	    
	     stringOne = String(stringOne);

	     Serial.println(stringOne);
	     sent = Particle.publish("D", stringOne);




#endif

#ifdef FTP
    if (!ftp.open(hostname, timeout)) {
      Serial.println("Couldn't connect to ftp host");
    
    }
    else {
    if (!ftp.user(username)) {
      Serial.println("Bad username");
    
    }
    else {
    if (!ftp.pass(password)) {
      Serial.println("Bad password");
    
    }
    else {
    if (!ftp.type("A")) {
      Serial.println("Couldn't set file type");
    } 
    else {         
         
         
        String final_file_name = String("/weather/")+String(Time.format(Time.now(), "%Y%m%d-%H%M"))+"-2-"+orgnum+"-"+userrecordid+".csv";
        	Serial.println(final_file_name);
    	 
         if (!ftp.stor(final_file_name)) {
      		Serial.println("Couldn't STOR data CSV");
    	} else {
    		Serial.println("STOR data CSV");
           
         time_t Time_Now = Time.now();
         
          for(int i=1;i<48;i++)
		  {
			EEPROM.get(i*4,value);
			
			time_t  Time_Mesur = Time_Now - (49-i)*1800;
			String DateTime_Mesu = Time.format(Time_Mesur, "%Y-%m-%d %H:%M:%S");
			
			stringOne = "\"O\",\"H\",\"\",\"\",\"SensorData20-"+String(Time_Mesur)+"-615624-411337\",\"Managers\",\"Rise West\",\"8\",\""+ String::format("%3.1f",value) +"\",\""+DateTime_Mesu+"\",\"Vegetronix VH 400\",\"665945\"\r";

                Serial.println(stringOne);
    	     
                ftp.data.write((const uint8_t*)stringOne.c_str(), strlen(stringOne));
	        ftp.data.flush();

		  }
            }
      Serial.println("Flush data");


      Serial.println("Stop file upload");

      if (!ftp.finish()) {
        Serial.println("Couldn't stop file upload");
      }         
     
      Serial.println("Exit FTP");

      sent = ftp.quit();
      }}}}         
#endif         
         
	     if ( sent == true) 	     {
		Serial.println("Data send to Cloud good");	 
	     	PublishDone = 1;
		}
     }
   
   
    if (ReadyToSleep == 2  &&  System.updatesPending() == false)
	{
	     index = 0;
	     EEPROM.put(0, index);   
#ifdef SLEEP
	     Particle.disconnect();
	     Cellular.off();
#endif
 	     Serial.println("Go to sleep!");
	     delay(5000);
	}
    }



#ifdef NOT_SLEEP
	if (index < 48)  
	{
		delay(5000);
		mesuring_done = 0;
		CellCon = 0;
		ReadyToSleep = 0;
		PublishDone = 0;
		mesuring_done = 0;
	}
#endif

#ifdef SLEEP
	if (index < 48)  
	{
		Cellular.off();
		System.sleep(SLEEP_MODE_DEEP, 1800);
	}
#endif
}

Hey there,

Server-side webhooks usage is not included in your data consumption. For more information, we have a full explanation of cellular data usage in our documentation, here:

https://docs.particle.io/guide/getting-started/data/electron/

Specifically, the section called What consumes data? is important to read.

I also highly recommend you set up data consumption alerts and hard caps in the Particle Console at http://console.particle.io

This might be a dangerous one, since this will have each and every event of every device in the Particle world that starts with “D” trigger your handler!
Subscribe sets a prefix filter.

This could well explain your excessive data consumption!
To test this theory, just put a Serial.print() or any other feedback you like into the handler to see how often it gets triggered.

You should at least use

Particle.subscribe("D", myHandler, MY_DEVICES);

And as noted before, your Cellular.off() and System.sleep(SLEEP_MODE_DEEP, 1800) will consume 6K on reconnect.
You should rather keep the radio powered (aka no Cellular.off()) and use System.sleep(SLEEP_MODE_DEEP, 1800, SLEEP_NETWORK_STANDBY) (providing you’ve already upgraded to 0.6.0-rc.2).

And finally - just for completness - your FTP transfer will eat into your data quota too.

BTW, I’ve not followed the frequency of your EEPROM writes, but keep flash wear in mind when doing lots of write cycles.

1 Like

Thank you for advice.

  1. Particle.subscribe can will be problem then we have a lot of device, yes. Now we have only one. And there is no another way to see that cloud get our publish as i understand. (from another my topic just reading of feedback from publish func not working)

  2. 6K for reconnect is clear

  3. FTP - it is just implemented and not using for now in programm

  4. ther is not so much writings to EEPROM, 2 per hour will be.

But issue still open, where i can see exactly how much traffuc for witch data or handshaking was counting?

(i mean i give from my application to you firmware 512 bytes per 1 hour, you firmware send somthink to you cloud and you counting traffic … need to know for what? thanks for understanding)

Have you seen this function
https://docs.particle.io/reference/firmware/electron/#getdatausage-

Oki will try from my side to counting data during session. But how you counting this one from cloud side? You have some statistic for online sessions?

  1. And this one System.sleep(SLEEP_MODE_DEEP, 1800, SLEEP_NETWORK_STANDBY working only in 0.6.0-rc.2? And in this case when i wake up (disconnect/reconnect to the cell towers will be 0Kb) because it must not connecting to then network att all. ?

  2. Another question with 0.5.2 (as i use now) i make Cellular.off then going deep sleep then wake up in SEMI_AUTOMATIC and not execute func Cellular.on(), why i spend 6Kb, in SEMI_AUTOMATIC it say that not connected to cloud (without my command) … i miss somethink here? (how can i doing not connected to cell and not spend 6Kb each time on firmware 0.5.2?)

(i wake 48 time in 1 hour - look like spend 300kb for nothink that is look like reason… In one day i will spend 7Mb (without any useful data transmission)

I read through your code but didn’t really get into the actual code flow how often and under what circumstances you do perform a cell connect.
But if you really don’t connect on wake, you won’t see any data usage, but if you would reconnect you’d have to know that before the previous sleep, since once you have disconnected you’ll inevitably use 6K on reconnect.
That’s up to you to estimate how often you’ll actually reconnect and which of the two scenarios will cost least.

No guarantees given. One other thing you need to keep an eye on is the keepAlive time for the connection, which is 23min with Particle SIM. Sleeping longer than that will invalidate the connection and you’ll see reconnect costs again.

But there are already several threads duscussing Electron sleep data usage in more detail.

To preserve data you can use this with 0.5.2

 System.sleep(WKP, RISING, 900, SLEEP_NETWORK_STANDBY);  // wake every 15min for keep alive.

And don’t call Cellular.off() or Particle.disconnect().

BTW, how does this work out?

1800sec sleep would be waking twice per hour not 48 times :confused:

1800 twicein hour yes.

with this code how much traffic will be for day? 0Kb or not, if not then how much (how much time board will be reconnect to cell mult on 6Kb as i understand(if it will)?

Just simple question :smile:

SYSTEM_MODE(SEMI_AUTOMATIC);

void setup()
{
}

void loop()
{
System.sleep(SLEEP_MODE_DEEP, 1800);
}

Roughly speaking yes.

The RGB LED will give you a clue whether the device tries to connect to the network and the cloud.

Como on you sell this board. You can make test on 0.5.2 and answer exactly on question?

You are mixing things up here - I’m not selling anything!

Elites are just volunteers privately answering peoples questions on this forum for free.

1 Like

ok. sorry … you know maybe some official email for support?

Have you checked the support page?
https://docs.particle.io/support/support-and-fulfillment/menu-base/

@murdemon at the site that Moors7 linked, is a way to contact the Particle team directly.

ok thanks… I send official question.

But maybe somebody try System.sleep(SLEEP_MODE_DEEP, 1800, SLEEP_NETWORK_STANDBY) (providing you’ve already upgraded to 0.6.0-rc.2).

It will be reonnect each time when i wake up or not? (but get more power during sleeping as i understand)

Thank you.

This might have some answers:

Thanks Moors7… bigest problem look like Data Usage Handshake, In realy not clear if i wake up for second from deep_sleep to mesure 1 analog data and save to EEPROM What for i need connect to Cell… Must be posibility Off Gsm modem at all if it not needed.