Syed Anwaarullah
Created August 18, 2019 © CERN-OHL

MeshyClocks: Synchronized LED Clocks

Digital NTP Clocks deployed in an Organization, each fetching time from the Network can be optimized by using the Mesh functionality.

IntermediateFull instructions provided3 hours23
MeshyClocks: Synchronized LED Clocks

Things used in this project

Hardware components

Argon
Particle Argon
×1
P10 LED Dot Matrix Display Module
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Gateway

Gateway

Code

Endpoints.ino

C/C++
This code will go into the meshed Endpoints, to which an LED Panel is connected on the Serial Port. This endpoint will receive the updated time from the Gateway and send it over the Serial port which will then be shown on the Display.
void timeHandler(const char *event, const char *data){
    Serial.println(String(data));
}

void setup() {
	Serial.begin(115200);
  Mesh.subscribe("timeUpdate",timeHandler);
}

void loop() {
}

Gateway.ino

C/C++
This code will go into the meshed Gateway which will fetch the NTP, and send it across to the endpoints. This Gateway is also connected to an LED Panel through the Serial Port which will also display the Time.
#include <ntp-time.h>

NtpTime* ntpTime;

String hhmmss(unsigned long int now)  //format value as "hh:mm:ss"
{
   String hour = String(Time.hourFormat12(now));
   String minute = String::format("%02i",Time.minute(now));
   String second = String::format("%02i",Time.second(now));
   return hour + ":" + minute + ":" + second;
};

void setup() {
    Serial.begin(115200);
    ntpTime = new NtpTime(15);  // Do an ntp update every 15 minutes;
    ntpTime->start();
}

void loop() {
    static unsigned long waitMillis;
    struct epochMillis now;  //holds the unix epoch time to millisecond resolution
    if(millis() > waitMillis) {
        ntpTime->nowMillis(&now);  //get the current NTP time
        Particle.publish("NTP clock is: ", hhmmss(now.seconds) + "." + String::format("%03i",now.millis));
        Particle.publish("System clock is: ", hhmmss(Time.now()));
        Mesh.publish("timeUpdate", hhmmss(now.seconds)); // Push Time across Nodes
        waitMillis = millis() + (15*1000);  // wait 15 seconds
    }
    Serial.println(hhmmss(Time.now())); // Send the synced System Time to Serial Port to display on LED Panel
    delay(500);
}

Credits

Syed Anwaarullah

Syed Anwaarullah

9 projects • 53 followers
Ex-Hackster.io India Ambassador. Maker, Speaker, Educator and Dreamer. ♥ Tinkering with Embedded, Android, Open Soft/Hard/Firmware, Robotics

Comments