Set time based on MQTT or Particle Publish?


#1

I’ve not had any success with the built in Particle time sync maintaining accurate time on a daily, weekly, monthly basis.

Could I set time from a ‘master’ device on my network sending an MQTT or Particle Publish message at 12:00 and when it’s received by the Photon or Core, the Particle device would set its internal clock to 12:00 ?

I’m aware the above process is not infallible and does not have the built in NTP safeguards etc, but I’m willing to risk it.

Anyone do this now or anything like it?

Thanks!!


#2

Are you saying that Cloud time sync isn’t working? There may be an issue with the RTC on your Photon. I have not seen such an issue with near enough 1000 Photons.

How are you doing the time sync, using time and how often are you re-syncing?

Perhaps you could share the code that isn’t working.

Gen3 devices are a different matter - there is no RTC and thus an add-on is required which needs to be synced - with a device on mesh only this then requires a time sync service.


#3

thanks armor. So, at 21:55, I set my Core to update its time. I know this code executed 'cos the sound file (mp3 5) played.

void SyncTime() {
        time_t lastSyncTimestamp;
        unsigned long lastSync = Particle.timeSyncedLast(lastSyncTimestamp);
        unsigned long cur = millis();
                Particle.syncTime();
                // Wait until Core receives time from Particle Device Cloud (or connection to Particle Device Cloud is lost)
                waitUntil(Particle.syncTimeDone);
                // Check if synchronized successfully
                if (Particle.timeSyncedLast() >= cur) {
                        // Print current time
                                myDFPlayer.playMp3Folder(5);

                }
                      
}

however, the next queued event, for 22:00:00, happened thirty seconds early, at 21:59:30. Again, I use time.is for an accurate reflection of the current atomic time. My computer is also in sync with time.is because Apple’s OS X NTP updates are in sync with time.is.


#4

EDIT: There is an internal RTC in the STM32F103CB on which the core is based - so this is unlikely to be the issue and therefore as you state below must be related to code - if possible, share the whole app (or at least as much as presents the error) and I will test on my core!


#5

Hi Shane - thanks, but that’s not the problem. The problem is that Particle.syncTime() which is being called daily, isn’t having an effect, probably due to my code! The Core’s software ‘clock’ only drifts at most a second or two a day. Thanks


#6

Cool - didn’t see this until now (sorry) as your edit didn’t show up as a new ‘reply’.

Could I PM you download locations for my code? Would that be OK? It’s a zip file you see as multiple files.


#7

Yup do that, I will take a look