Is there a method or possibility of getting time from the local cell tower like a cell phone does?
Having the user set a timezone is fine but I feel like the system should do this automatic.
Is there a method or possibility of getting time from the local cell tower like a cell phone does?
Having the user set a timezone is fine but I feel like the system should do this automatic.
This was posted by @shanevanj on a topic about Daylight Saving. There might be something here to apply to UTC to get local time.
You could use a Particle.fucntion to set the lat, lon when a customer “registers” the installation ? I use a function that takes a 3 letter timezone code as an override in addition to the IP based auto detect just in case it doesn’t pick the correct zone
Ok, after enabling +CTZU with Cellular.command() I got the Boron to spit out the local timezone based on the cell tower. My code is a bit ugly but it works for now.
SYSTEM_MODE(MANUAL);
char buffer[18] = "";
float zone;
void setup() {
Serial.begin();
while(!Serial){} //wait for Serial
Cellular.on();
if (RESP_OK == Cellular.command(callbackClock, buffer, 10000, "AT+CTZU=1\r\n")){ //This has to be set before cellular registration.
Serial.println("+CTZU Success");
}else{
Serial.println("+CTZU Fail");
}
Particle.connect();
}
void loop() {
Particle.process();
if((millis() % 1000) == 0){
if (RESP_OK == Cellular.command(callbackClock, buffer, 10000, "AT+CCLK?\r\n")){
Serial.println(zone);
}else{
Serial.println("+CCLK Fail");
}
}
}
int callbackClock(int type, const char* buf, int len, char* buffer){
char buffer2[18] = "";
char buffer3[18] = "";
sscanf(buf, "%[^\"]%*c%17s%3s\r\n", buffer, buffer2, buffer3);
zone = ((((int)buffer3[1] - 48) * 10) + ((int)buffer3[2] - 48)) / 4;
if (buffer3[0] == '-'){
zone = -zone;
}
return RESP_OK;
}
int callbackZone(int type, const char* buf, int len, char* buffer){
return RESP_OK;
}
And the output:
-6.00
Which is correct! The Time Zone information is expressed in steps of 15 minutes so -24 = -6 which is MST.
I feel this should really be part of the core time library since +CTZU should work in most places.
Also if anyone has some more robust code for sscanf I would appreciate it.
Ah nice, I tried that some time ago (with only AT+CCLK?) but that only replied an offset (since the modem was powered on) of the preset time.
I’ll try that some time with the +CTZU command .
By the way, is there a simple way to determine the next change of a daylightsaving? Even the google-api just tells the current state not the change-dates … I don’t want to lookup the time that often and maybe just store the dates and determine it locally.
Edit: I tried it and it sadly looks like my carrier (Vodafone in Germany) doesn’t support that feature . It responds with success but the offset is always 0.