mudpi / mudpi-core

Configurable automation library for linux SBC boards including raspberry pi
https://mudpi.app
274 stars 40 forks source link

Support for other boards #15

Closed SecT0uch closed 3 years ago

SecT0uch commented 3 years ago

Would you consider support for other boards ?

I have a setup with a Pine64, started developping something similar and came across your project (which is awesome btw).

One blocking problem is the dependency RPi.GPIO, which works with Raspberry Pi only. One possible solution would be to migrate to python-periphery.

I'm willing to contribute to the project in a separate branch to go in that direction if you're OK with that.

yeyeto2788 commented 3 years ago

Hey @olixr,

I tried to test on Opi Lite (Armbian) the relay, sequence, action, and button but I got this error:


 __  __           _ _____ _
|  \/  |         | |  __ (_)
| \  / |_   _  __| | |__) |
| |\/| | | | |/ _` |  ___/ |
| |  | | |_| | (_| | |   | |
|_|  |_|\__,_|\__,_|_|   |_|
_________________________________________________

Eric Davisson @theDavisson
https://mudpi.app
Version:  0.8

Initializing Logger...                   Complete
Initializing Garden Control...           Complete
Preparing Threads for Workers...         Complete
Pi Camera...                             Disabled
MudPi Shutting Down...
MudPi Shutting Down...                   Complete
Mudpi is Now...                          Offline
Traceback (most recent call last):
  File "mudpi.py", line 198, in <module>
    pw = LinuxControlWorker(
  File "/home/yeyeto2788/workspace/mudpi-core/workers/linux/control_worker.py", line 19, in __init__
    self.init()
  File "/home/yeyeto2788/workspace/mudpi-core/workers/linux/control_worker.py", line 32, in init
    imported_control = self.dynamic_import(control_type)
  File "/home/yeyeto2788/workspace/mudpi-core/workers/linux/worker.py", line 68, in dynamic_import
    module = getattr(module, component)
AttributeError: module 'controls' has no attribute 'linux'

The configuration I used is this one:

{
  "name": "MudPi",
  "version": 0.8,
  "debug": false,
  "redis": {
    "host": "127.0.0.1",
    "port": 6666
  },
  "relays": [
    {
      "pin": "PA10",
      "normally_open": true,
      "group": "",
      "name": "Relay Name",
      "key": "freaking key needed",
      "topic": "garden/pi/relays/",
      "tag": "relay_1"
    }
  ],
  "actions": [
    {
      "type": "event",
      "name": "Toggle Pump ON",
      "key": "toggle_pump_on",
      "action": { "event": "Toggle" },
      "topic": "garden/pi/relays/1"
    },
    {
      "type": "event",
      "name": "Toggle Pump OFF",
      "key": "toggle_pump_off",
      "action": { "event": "Toggle" },
      "topic": "garden/pi/relays/0"
    }
  ],
  "sequences": [
    {
      "name": "Example Watering Sequence",
      "key": "example_sequence",
      "sequence": [
        {
          "actions": ["toggle_pump_on"],
          "duration": 2
        },
        {
          "actions": ["toggle_pump_off"],
          "duration": 2
        }
      ]
    }
  ],
  "triggers": [
    {
      "type": "time",
      "key": "timed_trigger",
      "name": "timed triggered sequence",
      "sequences": ["example_sequence"],
      "schedule": "* * * * *"
    }
  ],
  "workers": [
    {
      "type": "control",
      "controls": [
        {
          "type": "Button",
          "pin": "PG7",
          "key": "button_1"
        }
      ]
    }
  ],
  "nodes": []
}

It is weird that we do that kind of import. Is it possible to refactor that part?

Maybe it's just me configuring wrongly the core. 😛

SecT0uch commented 3 years ago

Hey guys,

I just had a mountain of work coming in, and will be quite busy this week-end. I will try to test all that when I find some time. (On mi Pi Zero W first, and on my SoPine + baseboard later on).

olixr commented 3 years ago

@yeyeto2788 Try the latest push I just did to feature. Its seems like we just had more missing imports.

So when we took out most of that sys.append it means we needed more explicit imports for the files. So in the workers I have been making sure to import the sensors or controls.

I updated the control worker with

from controls.linux.button_control import (ButtonControl)
from controls.linux.switch_control import (SwitchControl)

This is what your error was talking about and should resolve the problem.

@SecT0uch no worries. When you have time post what you can test. If we can test one 1 or 2 boards other than the Pi that would be great. I don't expect us to test every board now possible.

SecT0uch commented 3 years ago

Also not a big deal but kinda annoying seeing De-initializing self.pulse_in every time getting printed by the library. I wish they would make that optional.

Just added a PR upstream to fix that. :)

yeyeto2788 commented 3 years ago

@olixr I'll pull the changes tomorrow, if by any chance you pull also @SecT0uch changes I can test on my board the code.

yeyeto2788 commented 3 years ago

Hello guys!

I finally got it to work but I actually don't see the relay going on and off. This is the output of the code running successfully:

 __  __           _ _____ _
|  \/  |         | |  __ (_)
| \  / |_   _  __| | |__) |
| |\/| | | | |/ _` |  ___/ |
| |  | | |_| | (_| | |   | |
|_|  |_|\__,_|\__,_|_|   |_|
_________________________________________________

Eric Davisson @theDavisson
https://mudpi.app
Version:  0.8

Initializing Logger...                   Complete
Initializing Garden Control...           Complete
Preparing Threads for Workers...         Complete
Pi Camera...                             Disabled
Button Control PG7...                    Ready
Controls...                              Initializing
Relay Worker freaking_key_needed...                      Initializing
2 Actions...                             Initializing
1 Sequences...                           Initializing
Triggers...                              Initializing
MudPi Garden Controls...                 Initialized
Engaging MudPi Workers...
Pi Control Worker [1 Controls]...        Online
Relay Worker freaking_key_needed...                      Online
Sequence Worker [Example Watering Sequence]...   Online
Trigger Worker [1 Triggers]...           Online
MudPi Garden Control...                  Online
_________________________________________________
Sequence Example Watering Sequence Started
Sequence Example Watering Sequence Started
^CMudPi Shutting Down...
Relay Worker freaking_key_needed Shutting Down...        Complete
Pi Control Worker Shutting Down...       Complete
Sequence Worker Shutting Down...         Complete
Trigger Worker Shutting Down...          Complete
MudPi Shutting Down...                   Complete
Mudpi is Now...                          Offline

I filed a PR due to missing dependency and a typo on pin argument getter.

olixr commented 3 years ago

After a few months of work I am back with updates. I took off from where we started on this and decided to just do the full system overhaul I have been wanting.

In the process I have completely separated out the need for RPIGPIO. This now opens up MudPi to run all linux boards. I also made it so the GPIO isnt event a hard requirement. Instead areas of the system that are not supported will just disable allowing everything else to run. I am now able to run MudPi on my mac even for testing which is great. It just gets the board errors and then disables the GPIO components as needed.

Check out the big updates: https://github.com/mudpi/mudpi-core/commit/809f998aeec62af7ddef827326065177e5bf7c50

I will be working on docs and testing before the final merge. I think though this covers the original adding more board support though. I will be closing this after some more tests.

olixr commented 3 years ago

Board support added. Closing original issue.

SecT0uch commented 3 years ago

Just a small update to say I've been using the feature branch of MudPi for a week without issues on a Sopine + baseboard running armbian.

Here is my working configuration:

{
  "mudpi": {
    "name": "MudPi Example",
    "debug": true,
    "unit_system": "metric",
    "events": {
      "redis": {
        "host": "127.0.0.1",
        "port": 6379
      }
    }
  },
  "sensor": [
    {
      "interface": "t9602",
      "address": 40,
      "key": "temp_hum_sensor",
      "name": "Climate Sensor T9602"
    }
  ],
  "trigger": [
    {
      "key": "humidity_low",
      "interface": "state",
      "source": "temp_hum_sensor",
      "nested_source": "humidity",
      "name": "Humidity is low",
      "frequency": "once",
      "actions": [
        ".humidifier.turn_on"
      ],
      "thresholds": [
        {
          "comparison": "lt",
          "value": 43
        }
      ]
    },
    {
      "key": "humidity_high",
      "interface": "state",
      "source": "temp_hum_sensor",
      "nested_source": "humidity",
      "name": "Humidity is high",
      "frequency": "once",
      "actions": [
        ".humidifier.turn_off"
      ],
      "thresholds": [
        {
          "comparison": "gt",
          "value": 57
        }
      ]
    },
    {
      "key": "every_min_day",
      "interface": "cron",
      "schedule": "* 6-23 * * *"
    },
    {
      "key": "every_min_night",
      "interface": "cron",
      "schedule": "* 0-5 * * *"
    },
    {
      "key": "check_temp_min_day",
      "interface": "state",
      "source": "temp_hum_sensor",
      "nested_source": "temperature",
      "name": "Check min allowed temp during day",
      "frequency": "once",
      "thresholds": [
        {
          "comparison": "lt",
          "value": 25
        }
      ]
    },
    {
      "key": "check_temp_max_day",
      "interface": "state",
      "source": "temp_hum_sensor",
      "nested_source": "temperature",
      "name": "Check max allowed temp during day",
      "frequency": "once",
      "thresholds": [
        {
          "comparison": "gt",
          "value": 30
        }
      ]
    },
    {
      "key": "check_temp_min_night",
      "interface": "state",
      "source": "temp_hum_sensor",
      "nested_source": "temperature",
      "name": "Check min allowed temp during night",
      "frequency": "once",
      "thresholds": [
        {
          "comparison": "lt",
          "value": 22
        }
      ]
    },
    {
      "key": "check_temp_max_night",
      "interface": "state",
      "source": "temp_hum_sensor",
      "nested_source": "temperature",
      "name": "Check max allowed temp during night",
      "frequency": "once",
      "thresholds": [
        {
          "comparison": "gt",
          "value": 27
        }
      ]
    },
    {
      "key": "day_temp_low",
      "interface": "group",
      "name": "Day temperature is low",
      "actions": [
        ".heating.turn_on"
      ],
      "triggers": [
        "every_min_day",
        "check_temp_min_day"
      ]
    },
    {
      "key": "day_temp_high",
      "interface": "group",
      "name": "Day temperature is high",
      "actions": [
        ".heating.turn_off"
      ],
      "triggers": [
        "every_min_day",
        "check_temp_max_day"
      ]
    },
    {
      "key": "night_temp_low",
      "interface": "group",
      "name": "Night temperature is low",
      "actions": [
        ".heating.turn_on"
      ],
      "triggers": [
        "every_min_night",
        "check_temp_min_night"
      ]
    },
    {
      "key": "night_temp_high",
      "interface": "group",
      "name": "Night temperature is high",
      "actions": [
        ".heating.turn_off"
      ],
      "triggers": [
        "every_min_night",
        "check_temp_max_night"
      ]
    }
  ],
  "toggle": [
    {
      "key": "light",
      "interface": "gpio",
      "pin": "D26",
      "invert_state": true,
      "name": "Light - Plug 1"
    },
    {
      "key": "humidifier",
      "interface": "gpio",
      "pin": "D19",
      "invert_state": true,
      "name": "Humidifier - Plug 2"
    },
    {
      "key": "heating",
      "interface": "gpio",
      "pin": "D13",
      "invert_state": true,
      "name": "Heating - Plug 3"
    }
  ]
}

@olixr I'm not 100% sure it's the intended way to control a parameter with different settings during the day and at night. In this example, I set the temperature between 25 and 30°C during the day and between 22 and 27°C during the night.

Is there any other way to achieve that ?