@alexsh1
Here's a bit of code I use to send an SMS once in a while. Providers will disable your simcard if you don't do anything that makes them money once in a while. Perhaps you can use it to reset.
#ifdef SEND_SMS_EVERY_49_DAYS
// This is an optional feature.
// Every 49,7 days (using the millis() rollover) the system sends out an SMS. This helps keep the simcard active and registered on the GSM network.
// Use at your own risk: if the system experiences a power loss, the timer starts at 0 again. If your experience frequent powerlosses, then the simcard might be-deregistered anyway, since the keep-alive SMS's won't get sent.
// A slight delay is built in: the first sms is sent a week after the smart lock becomes active. This avoid sending a lot of SMS's if you are still playing with setting up the device, and powerlosses may be frequent.
// This smart lock also offers another option. You can let the controller trigger the sending of the sms using the 'send test sms' button. Of course, your controller could also be down when you scheduled to trigger the button.
static bool keepAliveSMSsent = false; // used to make sure an SMS is only sent as the milliseconds starts, and not during every loop in the millisecond.
if(millis() < 5){
keepAliveSMSsent = false; // when the clock rolls over, set the variable back so that a new SMS can be sent.
}
if (millis() > 604800000 && millis() < 604800010 && keepAliveSMSsent == false){ // 604800000 = 1 week in milliseconds. Sending the first keep-alive SMS after a week avoids sending a lot of SMS-es while testing the system (which may involve a lot of reboots).
keepAliveSMSsent = true;
sendStatusSMS();
}
#endif
Alternatively, you could check out the smart alarm clock code. It will show you how to request the time from the controller, turn that into a human readable time, and then you can do your thing.
uint32_t unixTime = 0;
void receiveTime(unsigned long controllerTime) {
Serial.print(F("Received time: ")); Serial.println(controllerTime);
unixTime = controllerTime;
breakUpTime(unixTime);
}
void breakUpTime(uint32_t timeInput)
{
// Break the given time_t into time components.
// This is a more compact version of the C library localtime function
// Note that year is offset from 1970!
uint32_t time;
time = (uint32_t)timeInput;
uint32_t Second = time % 60;
time /= 60; // now it is minutes
minutes = time % 60;
time /= 60; // now it is hours
hours = time % 24;
time /= 24; // now it is days
//int Wday = ((time + 4) % 7) + 1; // Which day of the week is it. Sunday is day 1
Serial.print(F("Calculated time: "));
Serial.print(hours);
Serial.print(F(":"));
Serial.println(minutes);
}