Skip to content

honeytreelabs/homeautomation-plc

Repository files navigation

HomeAutomation PLC

General Description and Features

This SoftPLC framework allows for developing applications using the cyclic execution pattern typically found in PLCs. The guiding principle is to provide all that's needed for the application logic (such as IO states) as variable values. Application developers can therefore fully focus on creating the actual application logic without having to deal with low-level system details.

All that's required to be passed to the resulting binary is a configuration in YAML format. This file may even contain the PLC application logic in Lua (optional).

Example for two port expanders attached to the I2C bus of a Raspberry Pi:

tasks:
  - name: main
    interval: 25000  # us
    programs:
      - name: BlindLogic
        type: Lua
        script: |
          local blind

          -- called once before cyclic execution
          function Init(gv) blind = Blind.new(BlindConfigFromMillis(500, 50000, 50000)) end

          -- called every cycle
          function Cycle(gv, now)
          	gv.outputs.blind_up, gv.outputs.blind_down =
          		blind:execute(now, gv.inputs.button_up, gv.inputs.button_down)
          end
    io:
      - type: i2c
        bus: /dev/i2c-1
        components:
          0x3b:  # i2c address
            type: pcf8574
            direction: input
            inputs:
              0: button_up
              1: button_down
          0x20:  # i2c address
            type: max7311
            direction: output
            outputs:
              0: blind_up
              1: blind_down

Also see the introductory article on our website (more to come):

Supported featuers:

  • Scheduler supporting an arbitrary number of tasks.
  • Implementation of programs in C/C++ and Lua.
  • I2C, ModBus, MQTT IO variables.
  • A small standard library containing useful and tested logic blocks.
  • A comprehensive build framework with multitude of tests.
  • A statically linked binary with batteries included.

This project is licensed under the terms of the GNU Lesser General Public License v3.0.

Getting started

Requirements:

The Conan package manager will be installed in a Python 3 venv.

Currently, the following platforms are currently supported:

  • Native (most likely this is x86_64)
  • Raspberry Pi 4 (use Raspberry Pi 3 target)
  • Raspberry Pi 3
  • Raspberry Pi 2

Building:

  • make deps-install: install required packages (Debian/Ubuntu Linux only)
  • make conan-install: install the conan package manager
  • make conan-install-deps-native: build and install dependencies for native platform
  • make conan-install-deps-rpi3: build and install dependencies for Raspberry Pi 3 (and 4)
  • make conan-install-deps-rpi2: build and install dependencies for Raspberry Pi 2
  • make native: build tests for native platform
  • make test: build and run tests locally directly on the build platform
  • make rpi3: build for Raspberry Pi 3 (and 4) platform
  • make rpi2: build for Raspberry Pi 2 platform

Roadmap

The following list is a living document mentioning what is planned in the future.

IEC 61131-3 Programs

In central Europe, PLCs used in typical industrial automation scenarios are programmed according to the IEC 61131-3 standard. Therefore, on the middle or long run, we want to implement an interpreter which is capable of executing such logic.

Integration of a Prometheus Client

For better analysis of what happened when and how often, we want to integrate a Prometheus Client, such as prometheus-cpp.

Improved Testing Capabilities

For inlined Lua application logic I want to implement a testing framework that allows for making formally sure that the contained application behaves as expected.

Command and Control Interface

This interface allows for Starting/Stoping/Pausing the runtime dependening on commands received via different channels, such as MQTT and/or HTTP push mechanisms.

Global Variables with Logic

Changes in the values of global variable values (= events) invoke callbacks that can be registered with them:

  • Variable value changed.
  • Get all variable values.

time_points/durations as simple 64-bit values

This allows for easier interaction with interpreters and conversion between different time bases.

References

I wrote a couple of articles about the protocols mentioned in this project. Unfortunately, they are in German. But most likely, it is possible to translate them with some available online tools: