GithubHelp home page GithubHelp logo

rwpalmer / set-mpu-local-time-via-mqtt Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 0.0 24 KB

Configure IOT devices local time settings via MQTT. Includes a Linux script that uses Mosquitto to publish local timezone information with the retain flag set. Also includes C++ code snippets for a Particle MPU to parse the MQTT message and update local time settings.

Shell 100.00%
particle timezone daylight-savings dst mqtt cpp linux

set-mpu-local-time-via-mqtt's Introduction

Set-MPU-Local-Time-via-MQTT

Concept:


A Linux system runs a script that ...

  • Looks up time-zone information based on the time-zone database that exists on its own file system.
  • Format an MQTT message that contains the time-zone information IOT devices need to configure their own local time settings and to perform DST transitions when they are scheduled.
  • Publishes the MQTT message with the 'retain' flag on.
  • For the sake of this discussion, the MQTT topic is "time/zone".

IOT MPUs would do the following ...

After each reboot:

  • Subscribe to the "time/zone" topic. Since the 'retain' flag is on, the MQTT broker will send the latest message under this topic to the MPU each time it subscribes to the topic.

Whenever an MQTT message with the "time/zone" topic is received:

  • Configure the MPU's local time settings based on the information in the 'time/zone' message
  • Store DST transition information in RAM

When DST transitions occur

  • Switch the MPU's setting between standard and daylight savings time based on the DST transition data stored in its RAM.

Status: PROTOTYPING

Prototype 1:

  • Linux script publishes the information Particle MPUs need to configure their time zone and DST offset to match the Linux system. The current year's DST transition times for the Linux systems's timezone is also included.
  • The MQTT message is in a flat JSON format. (no nesting, no arrays). This simplifies parsing.
  • MQTT code snippets include
    • Global Definition and Initialization
    • DST transition logic
    • MQTT callback logic (based on Particle MQTT library v0.4.29)
    • JSON parsing functions used by the callback log

Activity:

  • 05 Mar 2019 - Prototype 1, Linux Code uploaded (documentation included in code)
  • 06 Mar 2019 - Prototype 1, MPU code snippets uploaded.
  • 07 Mar 2019 - Prototype 1, DST transition testing completed ... one minor fix posted to MPU snippets.
  • 10 Mar 2019 - Prototype 1, Local time was changed correctly on the second when the real DST transition occurred. Also ran validation tests to assure that the device's local time was set properly after reboots.

Status:

Prototype 1 proves that the concept is sound, and the code is relatively simple. The author is running this code on all of his devices that run with MQTT because it works so well and has very low overhead. The Linux script runs on the MQTT broker, and is kicked off via a cron on a selected date in early January each year.


Future Direction: TBD

  • The Linux script used in Prototype 1 could be used to create data for another timezone, a group of timezones, or for all timezones.
  • The Linux script could also generate a different data format, or multiple data formats
  • If MPUs from other manufacturers need additional data, that data can be added to the existing data, or separate messages can be published based on the MPU manufacturer.
  • Please feel free to open an issue if you have other ideas, recommendations, or requirements ... also if you any bugs or compatibility issues in prototype 1.

set-mpu-local-time-via-mqtt's People

Contributors

rwpalmer avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.