Here’s the serial1 output (with annotation{}) I get using stop mode sleep. If I’m going about this wrong someone please tell me:
Read counters of sent or received PSD data!
CID: 31 SESSION TX: 12789 RX: 8355 TOTAL TX: 12789 RX: 8355
31,12789,8355,12789,8355
{before any reset}
Publish some data!
{"e1", "0MSSA"}
Read counters of sent or received PSD data!
CID: 31 SESSION TX: 12983 RX: 8538 TOTAL TX: 12983 RX: 8538
31,12983,8538,12983,8538
{yields 194, 183}
Read counters of sent or received PSD data!
CID: 31 SESSION TX: 13044 RX: 8599 TOTAL TX: 13044 RX: 8599
31,13044,8599,13044,8599
{just wakeup and get new data usage - 61, 61}
Read counters of sent or received PSD data!
CID: 31 SESSION TX: 13105 RX: 8660 TOTAL TX: 13105 RX: 8660
31,13105,8660,13105,8660
{just wakeup and get new data usage - 61, 61}
Reset counter of sent/received PSD data!
Read counters of sent or received PSD data!
CID: 31 SESSION TX: 61 RX: 61 TOTAL TX: 61 RX: 61
31,61,61,61,61
{usage reported with wakeup only, no publish, after reset}
{CODE used}
#include "Particle.h"
SYSTEM_MODE(SEMI_AUTOMATIC);
char publishStr[10];
int sleepInterval = 0;
bool pubsuccess;
uint32_t start;
void readCounters() {
Serial1.println("Read counters of sent or received PSD data!");
CellularData data;
if (!Cellular.getDataUsage(data)) {
Serial1.print("Error! Not able to get data.");
}
else {
Serial1.printlnf("CID: %d SESSION TX: %d RX: %d TOTAL TX: %d RX: %d",
data.cid,
data.tx_session, data.rx_session,
data.tx_total, data.rx_total);
Serial1.println(data);
}
}//void resentCounters()
void setCountersto1000() {
Serial1.println("Set all sent/received PSD data counters to 1000!");
CellularData data;
data.tx_session = 1000;
data.rx_session = 1000;
data.tx_total = 1000;
data.rx_total = 1000;
if (!Cellular.setDataUsage(data)) {
Serial1.print("Error! Not able to set data.");
}
else {
Serial1.printlnf("CID: %d SESSION TX: %d RX: %d TOTAL TX: %d RX: %d",
data.cid,
data.tx_session, data.rx_session,
data.tx_total, data.rx_total);
Serial1.println(data);
}
}//void setCountersto1000()
void resetCounters() {
Serial1.println("Reset counter of sent/received PSD data!");
if (!Cellular.resetDataUsage()) {
Serial1.print("Error! Not able to reset data.");
}
}//void resetCounters()
void publishData() {
Serial1.println("Publish some data!");
sprintf(publishStr, "%iMSSA",sleepInterval);
Particle.connect(); //do we need this??? apparently DO if
//sleep duration > 25 mins
waitUntil(Particle.connected);
//do we need this??? apparently DO if
//sleep duration > 25 mins
start = millis();
while (millis() - start < 6000UL) {Particle.process();}
pubsuccess = Particle.publish("e1", publishStr, 60, PRIVATE);
//do we need this??? apparently DO if
//sleep duration > 25 mins
start = millis();
while (millis() - start < 6000UL) {Particle.process();}
}//void publishData()
void setup() {
pinMode(D1, INPUT);
pinMode(WKP, INPUT);
Serial1.begin(9600);
Particle.connect();
waitUntil(Particle.connected);
start = millis();
while (millis() - start < 2000UL) {Particle.process();}
}//setup()
void loop() {
System.sleep(D1, RISING, SLEEP_NETWORK_STANDBY);// wake on pin D1
start = millis();
while (millis() - start < 6000UL) {Particle.process();}
while (!Serial1.available()) {}
char c = Serial1.read();
if (c == '1') {
readCounters();
}
else if (c == '2') {
setCountersto1000();
}
else if (c == '3') {
resetCounters();
}
else if (c == 'p') {
publishData();
}
while (Serial1.available()) Serial1.read(); // Flush the input buffer
}//loop