Data consumption under normal use

Hi,
I have recently just installed a particle photon which polls a node.js web app hosted on a pi for a message. When the message is received the photon toggles a relay which in turn turns on a mains powered light. The pi is hosted locally on the same wifi network as the photon and the wifi network is a mobile broadband router. Since installing the photon I have seen my data consumption shoot up massively. I’ve consumed 10GB of data in the past 3 days alone and being mobile data is costing a fortune.
The photon sketch doesn’t ever connect to the internet - just a local IP address and my photon is pretty much how it was configured out of the box except with the small sketch i’m running on it which doesn’t explain the data usage. How much data does the photon use under normal conditions? I’m guessing it’s constantly checking for updated sketches etc?

@JammyBrand82, this sounds very suspicious. I can’t even imagine a situation where the Photon could produce 10GB of data on the internet in 3 days, let alone a month! Can you post your app? What system mode are you running?

Have you looked at your rPi as a probable source?

1 Like

Photon does not call home, except cloud housekeeping (time and date, etc.) if you are using the default system mode. An sketch (and maybe a new firmware image) will be updated only if you push it to the Photon.
I also would suspect that the PI is doing such a massive traffic.

1 Like

Hi @JammyBrand82,

That’s correct, if you’ve turned off the cloud connection it should not be reaching out to the internet unless your firmware asks it to. I recently held a workshop using a cellular broadband router, and I had more than 40 people flashing apps all day to 40 photons, and all told all the photons used about 20 megs of data. So if you’re seeing extremely high data usage I would not expect that to be normal behavior.

Does your mobile router allow you to track data usage per device? Can you share your source code / maybe we can see if there are problems there?

Even if the photon is connected to the cloud, by default it should be using less than a few kilobytes of bandwidth a day while idling. (very rough estimate)

Thanks,
David

Great, thanks for the feedback. I don’t think it is the photon but it’s just weird how all of a sudden the data usage has shot right up.The Pi is running the same code it was running before the photon was installed so I’m not convinced the problem is there either. I’m starting to wonder if the wifi might have been hacked.

My code is below. It’s not calling anything “Internet” related and only calls the PI every 0.5 seconds to check to see if there is a cloud to device message in the Pi’s buffer. I’ve also checked the rest_client library out and can’t see any thing there that could be causing the issue.

Thanks

#include "rest_client.h"

const int flashInterval = 1000;
const int flashDuration = 30000;

int RELAYPIN = 7;
bool pinActive = false;
bool flash = false;

unsigned long previousMillis = 0;
unsigned long startMillis = 0;

String deviceId = "1fa70b8e-2148-467d-b7e4-305c89347fa1";

void setup() 
{
    pinMode(RELAYPIN, OUTPUT);
}

void loop() 
{
    unsigned long currentMillis = millis();
    
    if (flash == true)
    {
        if (currentMillis - previousMillis >= flashInterval)
        {
            previousMillis = currentMillis;
            
            if (pinActive == false && flash == true)
            {
                digitalWrite(RELAYPIN, HIGH);
                pinActive = true;
            }
            else if (flash == true)
            {
                digitalWrite(RELAYPIN, LOW);
                pinActive = false;
            }
            if (currentMillis - startMillis >= flashDuration)
            {
                flash = false;
                digitalWrite(RELAYPIN, LOW);
            }
        }
    }
    else
    {
        // Only check for messages if flash is false
        RestClient client = RestClient("192.168.1.124", 8080);
    
        String response = "";
        int statusCode = client.get("/deviceMessages?deviceid=" + deviceId, &response);
        
        if (response.indexOf("flash") > 0 && response.indexOf(deviceId) > 0)
        {
            flash = true;
            startMillis = millis();
        } 
        else
        {
             delay(500);
        }
    }
}

One thing to consider too is the granularity your provider measures data usage.
Quite a few don’t do it on a byte by byte basis, but “charge” you in chunks of e.g. 100kB even if you only have a 50byte request.

I have no knowledge of the RestClient implementation, but could it be that providing the IP as a string causes a remote DNS lookup each time you try to access your local server?

1 Like

If you are able to press reset button when new code is needed, you could disconnect from the cloud after a short timeout.

As @ScruffR says mobile dataplans often charge you in blocks of 10-100kB per connection, so if the router disconnects from the mobile network because theres no activity, and the photon then tries to reconnect to the cloud then it would reconnect and start a new connection.

There may also be a setting on the router not to disconnect when idle.

Thanks for all the suggestions. I think there were several issues - As @ScruffR said the way the provider measures my data - along with the PI polling for cloud to device messages for the photon too often.

3 Likes