We are building a product based on the Electron and currently we are trying to figure out what is the best way to safe data volume.
The product reads out a sensor every five minutes and sends its value to a backend using publish / subscribe methods.
After the sensor has been read out the device goes back into deep sleep to safe battery since the product will be solar powered.
In the documentation I read the following about optimising data consumption (link to quote):
From 0.6.0, the device determines that a full reinitialization isn't needed and reuses the existing session ...
as well as:
A key requirement for the device to be able to determine that the existing session can be reused is that the functions, variables and subscriptions are registered BEFORE connecting to the cloud.
There is also an example that shows how to register functions and subscriptions before connecting to the cloud:
// EXAMPLE USAGE
// Using SEMI_AUTOMATIC mode to get the lowest possible data usage by
// registering functions and variables BEFORE connecting to the cloud.
SYSTEM_MODE(SEMI_AUTOMATIC);
void setup() {
// register cloudy things
Particle.function(....);
Particle.variable(....);
Particle.subscribe(....);
// etc...
// then connect
Particle.connect();
}
So in my code I combined the information I got from the documentation and came up with this:
SYSTEM_THREAD(ENABLED);
SYSTEM_MODE(SEMI_AUTOMATIC);
FuelGauge fuel;
PMIC pmic;
long lastPublish = 0;
void setup() {
pmic.begin();
pmic.setChargeCurrent(0,0,1,0,0,0);
pmic.setInputCurrentLimit(1500);
Cellular.on();
Cellular.connect();
waitUntil(Cellular.ready);
Particle.connect();
waitUntil(Particle.connected);
Particle.publish("B",
"v:" + String::format("%.2f",fuel.getVCell()) +
",c:" + String::format("%.2f",fuel.getSoC()),
60, PRIVATE
);
lastPublish = 0;
}
void loop() {
if (millis() - lastPublish > 5000) {
System.sleep(SLEEP_MODE_DEEP, 240);
}
}
But using a Particle.io SIM card this leads almost 0.6 MByte / hour data consumption! Given the fact that a reconnection to the cloud needs almost 4,4KB and by recalculating how often it will reconnect I am pretty sure that the above code always does a handshake with the cloud and after every wake up a full reconnection is performed !!!
So I am currently having problems to set up Deep Sleep and Re-Connection as stated in the documentation!!!