Giter Club home page Giter Club logo

mcce's Introduction

MCCE - Monitor Collect power Consumptions servicE

๐Ÿ“˜ Description

I had been given this electricity monitoring and control system device, very simple to configure and to use as monitor system (with the integrated LCD display). But a nightmare as control and data analyzer system, because the device is shipped with a closed source (windows exe) software, with ugly UI, to read the stored data using a serial USB connection, with no possibility to interact or export easily the power consumptions.

drawing drawing

โญ Features

So I'd like to turn it into something more advanced:

  • Parse the instantaneous values using a Raspberry Pi (im my case a Pi 2) with python script reading from USB serial connector

    [!NOTE]
    The first difficulty was to understand how to start the serial flow after the serial connection ... yes, the device not stream nothing by default, a particolar hex code must be send to it to start the bytes streaming. After a little reverse engineering using wireshark usb tool, the code has been found.

    [!NOTE]
    The second difficulty was to understand how to read the bytes flow and convert it to decimal values, that must be equal to the power consumptions show by the device display.

    Look at day_loop.py for the solutions

  • Notify with an alarm tone, when the instantaneous value reach the cap (in my case 4.2 kWh for a max of few minutes) imposed by electricity contract provider

    Below the wiring scheme needed to use alarm4200.py

    drawing

    Components:

    • 12V 1A DC
    • Buzzer audio
    • Raspberry Pi 2 (GPIO)
    • Driver A4988 for step motor (used as audio amplifier)
  • Record at the end of the day (midnight) inside database:

    • electric power consumption history with different time resolution
    • electric consumption average

    Look at day_digest.py

  • With these stats stored, to visualize/analyze them I created simple dash-app

๐Ÿš€ Getting started

The idea is to use a main service mcce-mcce.service that must always run, executing day_loop.py and only once a day service mcce-digest.service to digest/store the power consumption recorded during the day, executing day_digest.py

A little description for the last one, it can be started using scheduler as cron or more easily using systemd-timer, as I do, linked with the service. The are two environment variables that must be set inside mcce-digest.service:

  • $MIN_TIME_RES the time resolution in minute to use for the power consumptions history of the day
  • $DATABASE_URL that can be a file path where the std package sqlite3 will create and write a local sqlite db every year

By the way, before start with setup, hardware prerequisites:

  1. The most difficult: have a MCEE device to hack
  2. Raspberry Pi (with a Debian distro)
  3. Components needed for the alarm circuit
  4. Build the circuit

Steps to run repo/project:

  1. Libgpiod library (needed for alarm4200.py) needs to be installed system-wide, on debian systems:

    sudo apt install python3-libgpiod
    
  2. Clone the repo

    git clone https://github.com/andros21/mcce.git
    
  3. Create a python environment with packages needed

    python -m venv --system-site-packages .venv
    source .venv/bin/activate
    python -m pip install --upgrade requirements/requirements.txt
    
  4. Copy systemd service template files inside /etc/systemd/system/

  5. Change file permissions, that must be -rw-r----- root root

  6. Patch them, edit them as you need/want

  7. Reload new unit files:

    sudo systemctl daemon-reload
    
  8. Enable and start he main service

    sudo systemctl enable --now mcce-mcce.service
    
  9. Enable and start the timer that will be triggered at the specify hour/minute, responsible of the related service activation

    sudo systemctl enable --now mcce-digest.timer
    

    [!WARNING]
    Not select an hour before midnight, for mcce-digest.timer

  10. Check with some systemctl status or using journalctl if everything went well

  11. Enjoy ๐Ÿ˜„ and not forget to check out related web UI repo pwrApp

mcce's People

Contributors

andros21 avatar dependabot[bot] 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.