Giter VIP home page Giter VIP logo

mfm2mqtt's Introduction

mfm2mqtt

A tiny middleware to forward the data from mains frequency measurement board to mqtt This Python scripts grabs content of the mfm-board and publishes the data to an MQTT-Broker. the mfm-board hardware is described in detail in the "mains-frequency-measure" repo.

Why MQTT? MQTT was chosen, because it is (from my point of view) the most flexible solution to process the data further on. In my use case, there is a telegraf instance running, that forwards all MQTT data to InfluxDB, thus no additional Interface from "field level" to the monitoring instance. A nice benefit is the possibility to integrate the MQTT stream into Node-Red or any other automation system such as OpenHAB etc.

Setup

** CAUTION** From IT_Security Point-of-View, the whole script might be a nightmare! Feel free to enhance and contribute!

Verify access to serial connection

run the script in folder `python3 /debug/mfm_serial_test.py' for a first vaildation of the connectivity to your mfm-board

Set environment variables with the relevant details (e.g. via docker-compose)

*** noch nicht implementiert!***

  • For Interface to mfm-ATMega328p Board
    • MFM_SERIAL_PORT=/dev/ttyS0`
    • NOMINAL_FREQUENCY=50
    • SCRAPE_INTERVAL=0.1 # os.environ.get('SCRAPE_INTERVAL')
  • For MQTT Broker:
    • MQTT_TOPIC = "MFM"
    • MQTT_HOST ="127.0.0.1"
    • MQTT_USERNAME=<your_username> < Runs currently without authentification!
    • MQTT_PASSWORD=<your_password> < Runs currently without authentification!

Internal variables, that can be easily added to the environment variables as well:

  • MQTT_PORT=1883
  • MQTT_CLIENT_ID=""
  • MQTT_KEEPALIVE=60
  • MQTT_WILL=None
  • MQTT_TLS=None
  • SCRAPE_INTERVAL

create docker container

build the container from a terminal: sudo docker build -t mfm2mqtt .

sudo docker run mfm2mqtt

building the container with docker-compose docker-compose up

  • Run python3 mfm2mqtt.py

Description or the runtime sequence

  • get data
  • convert to json
  • create mqtt message
  • publish message

Missing features:

  • exception handling not yet implemented
    • connection errors
      • route to mfm-board
      • route to MQTT Broker
    • data inconsistency
    • etc. etc.
  • interface to docker logging console

Problems to be solved:

  • Docker container environment ==>
  • how to make sure that the latest lib is used?
  • container stops with "exit code 1" after almost any issue ==> the solution shall be robust against any external connectivity problems such as a restart of another instance of loss of communication
  • runtime monitoring shall provide (detailed) information on the issue causing the container to break.

use cases for data consumption

Grafana

By logging the data with this script it's easily possible to create a nice Grafana Dashboard to display some of the interesting data.

NODE-RED

... to be developped

Note

This is just a quick-and-dirty script to grab to content

mfm2mqtt's People

Contributors

wuifi avatar

Watchers

 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.