Dear all
Apology for a rookie question and if it has been covered before (my prior search had brought nothing relevant though).
I have this firmware (below) which was written a couple of years ago for Particle Electron 2G (SARA G350). It used to work ok. I now wonder if this code can work on Boron 2G/3G Global like this one Boron 2G/3G Global Starter Kit with EtherSIM – Particle Retail and what to bear in mind (like minimum OS requirements, what libraries from the ones I use should be different)? Sorry if this is not specific enough or too generic.
Firmware (designed to put the device in deep sleep, then wake up, hook to cellular, parse its ID, post it, repeat)
pragma PARTICLE_NO_PREPROCESSOR
#include "Particle.h"
SYSTEM_MODE(AUTOMATIC);
SYSTEM_THREAD(ENABLED);
char cellular_data[200] = "";
int cb(int type, const char* buf, int len, char* cellular_data);
//This function to use instead delay() to avoid blocking code - period in milli seconds
void mydelay(int period);
//This function to start deep sleep mode
void sleepInMinutes(void);
void setup () {
mydelay(70000);// need to wait for 70 sec to allow enough time for cellular and particle connect if possible
//I use serial for debugging purpose only
Serial.begin(9600);
}
void loop() {
if ((RESP_OK == Cellular.command(cb, cellular_data, 10000, "AT+CGED=3\r\n"))
&& (strcmp(cellular_data, "") != 0)) {
Serial.printlnf("Cellular info: %s\r\n", cellular_data);
}
else {
Serial.printlnf("Cellular info not found");
}
if (strlen(cellular_data) > 0) {
Particle.publish("cellData", cellular_data, PRIVATE);
//To obey publish limit
mydelay(1000);
//Reset string to not publish the same one again
cellular_data[0] = '\0';
}
sleepInMinutes();
}
int cb(int type, const char* buf, int len, char* cellular_data) {
if ((type == TYPE_PLUS) && cellular_data) {
if(sscanf(buf, "\r\n+CGED: %[^\r]\r\n", cellular_data) == 1)
/*nothing*/;
}
return WAIT;
}
void sleepInMinutes(void) {
//Cellular.on();
//Particle.connect();
Particle.publish("Sleep", "Go To Deep Sleep For 3 minutes", PRIVATE);
Particle.disconnect();
mydelay(5000);
Cellular.disconnect();
Cellular.off();
//sleep for 20 minutes
System.sleep(SLEEP_MODE_DEEP, 180 );
}
void mydelay(int period) {
int time_now = millis();
while(millis() < time_now + period) {
//wait delay ms
}
}