Giter Club home page Giter Club logo

mqtt-io's Issues

How to update (virtualenv install) ?

I notice you updated the repository 18 days ago but as a Linux newb I have no idea how to update it on my system.

I followed the virtualenv installation recommendation.

question: refresh sensor values without retain?

The retain flag is the straightforward way to persist sensor data to be retrieved later, such as when a service looking at the status is restarted, it can obtain the "current" state.

This however is insufficient when you would like to ensure that the state you have is actually a really real current state, and not something stale that has simply failed to have been updated.

I suppose I could check the LWT status and then status all the sensors as "stale" if it's dead but that would be a lot of extra logic and duplicated for each and every sensor as well.

It would be nice if one or both of the following could be added (and I'd be willing to contribute code even)

a) a configuration option (global or per sensor) to send unsolicited sensor updates. In real life this might look like "pio/inputs/garage_door_closed = true" every 5 minutes or whatever.

b) respond to a new topic, "pio/query/garage_door_open" which would then trigger a fresh publish of the above topic on demand. It could even respond to "pio/query/" by publishing the current state of all inputs.

Feature request: (Optional feature) require_pin_off

Hi @flyte,

Is it possible to add something like this:

digital_outputs:
  - name: speed-1
    module: raspberrypi
    require_pin_off: 18,22
    pin: 17
    on_payload: "ON"
    off_payload: "OFF"
  - name: speed-2
    module: raspberrypi
    require_pin_off: 17,22
    pin: 18
    on_payload: "ON"
    off_payload: "OFF"

The reason for this is that I'm using 3 relays for 3 speeds of a ceiling fan. When speed-1 is on and speed-2 is started the pin for speed-1(17) should first be disabled before the pin of speed-2(18) is enabled. Else there are two relays in ON state and I guess the fan won't like this.

Or is there a better way to do this?

Thanks again for the effort!

No such file or directory: 'config.schema.yml'

I cannot install and start the program.

During install I get a warning that MANIFEST.in has an issue.

root@raspi01:~# pip3 install pi-mqtt-gpio
Downloading/unpacking pi-mqtt-gpio
  Downloading pi_mqtt_gpio-0.0.7.tar.gz
  Running setup.py (path:/tmp/pip-build-_j6w1ddf/pi-mqtt-gpio/setup.py) egg_info for package pi-mqtt-gpio
    your setuptools is too old (<12)
    setuptools_scm functionality is degraded
    zip_safe flag not set; analyzing archive contents...

    Installed /tmp/pip-build-_j6w1ddf/pi-mqtt-gpio/pytest_runner-2.11.1-py3.4.egg

    warning: manifest_maker: MANIFEST.in, line 2: 'recursive-include' expects <dir> <pattern1> <pattern2> ...

Downloading/unpacking paho-mqtt (from pi-mqtt-gpio)
  Downloading paho-mqtt-1.3.0.tar.gz (79kB): 79kB downloaded
  Running setup.py (path:/tmp/pip-build-_j6w1ddf/paho-mqtt/setup.py) egg_info for package paho-mqtt
    your setuptools is too old (<12)
    setuptools_scm functionality is degraded
    zip_safe flag not set; analyzing archive contents...

    Installed /tmp/pip-build-_j6w1ddf/paho-mqtt/pytest_runner-2.11.1-py3.4.egg

Downloading/unpacking PyYAML (from pi-mqtt-gpio)
  Downloading PyYAML-3.12.tar.gz (253kB): 253kB downloaded
  Running setup.py (path:/tmp/pip-build-_j6w1ddf/PyYAML/setup.py) egg_info for package PyYAML

Downloading/unpacking enum34 (from pi-mqtt-gpio)
  Downloading enum34-1.1.6-py3-none-any.whl
Downloading/unpacking cerberus (from pi-mqtt-gpio)
  Downloading Cerberus-1.1.tar.gz
  Running setup.py (path:/tmp/pip-build-_j6w1ddf/cerberus/setup.py) egg_info for package cerberus

Installing collected packages: pi-mqtt-gpio, paho-mqtt, PyYAML, enum34, cerberus
  Running setup.py install for pi-mqtt-gpio

    warning: manifest_maker: MANIFEST.in, line 2: 'recursive-include' expects <dir> <pattern1> <pattern2> ...

    Installing pi_mqtt_gpio script to /usr/local/bin
  Running setup.py install for paho-mqtt

  Running setup.py install for PyYAML
    checking if libyaml is compilable
    arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.4m -c build/temp.linux-armv7l-3.4/check_libyaml.c -o build/temp.linux-armv7l-3.4/check_libyaml.o
    build/temp.linux-armv7l-3.4/check_libyaml.c:2:18: fatal error: yaml.h: Datei oder Verzeichnis nicht gefunden
     #include <yaml.h>
                      ^
    compilation terminated.

    libyaml is not found or a compiler error: forcing --without-libyaml
    (if libyaml is installed correctly, you may need to
     specify the option --include-dirs or uncomment and
     modify the parameter include_dirs in setup.cfg)

  Running setup.py install for cerberus

Successfully installed pi-mqtt-gpio paho-mqtt PyYAML enum34 cerberus
Cleaning up...

When I try to start the server I get this:

root@raspi01:~# python3 -m pi_mqtt_gpio.server pi_mqtt_gpio.yml
Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.4/dist-packages/pi_mqtt_gpio/server.py", line 32, in <module>
    with open("config.schema.yml") as schema:
FileNotFoundError: [Errno 2] No such file or directory: 'config.schema.yml'

I used these commands to install the program:

apt-get install python3-pip
pip3 install pi-mqtt-gpio
Linux raspi01 4.9.0-2-rpi2 #1 SMP Raspbian 4.9.13-1+rpi3 (2017-05-18) armv7l GNU/Linux

Any idea what I am doing wrong?

on-off loop with door sensor

I am not sure, but it could be related with #48

I have RPi2 installed in my garage, with latest pi-mqtt-qpio & got similar to these reed switch sensor installed and configured in HomeAssistant.

whenever I open the garage door, sensor instead of keeping itself "open", it gives me on-off-on-off-on... readouts.

> cat /var/log/pi-mqtt-gpio.log

Input 'garagedoor' state changed to True
MQTT client: Sending PUBLISH (d0, q0, r0, m173), 'rpi/input/garagedoor', ... (2 bytes)
Input 'garagedoor' state changed to False
MQTT client: Sending PUBLISH (d0, q0, r0, m174), 'rpi/input/garagedoor', ... (3 bytes)
Input 'garagedoor' state changed to True
MQTT client: Sending PUBLISH (d0, q0, r0, m175), 'rpi/input/garagedoor', ... (2 bytes)
Input 'garagedoor' state changed to False
MQTT client: Sending PUBLISH (d0, q0, r0, m176), 'rpi/input/garagedoor', ... (3 bytes)

I can see the same thing in HomeAssistant's log:

08:58 Garage door turned off
08:58 Garage door turned on
08:58 Garage door turned off
08:58 Garage door turned on

my pi-mqtt-gpio sensor configuration is:

gpio_modules:
  - name: raspberrypi
    module: raspberrypi

digital_inputs:
  - name: garagedoor
    module: raspberrypi
    pin: 17
    on_payload: "ON"
    off_payload: "OFF"
    pullup: no
    pulldown: no

I tried with different pullup/pulldown combinations, but they didn't worked at all.

is there any solution at user-side [me, changing some config] or it's more like dev-related thing?

also: it would be great to have timestamp next to the log entries just to be able to read issues/problems more precisely :) [or is it my problem, because I didn't set up something?]

Payload b'ON' does not relate to configured on/off values

I cannot send a command via MQTT. :(

It always says Payload b'*' does not relate to configured on/off values.

root@raspi01:/usr/local/lib/python3.4/dist-packages/pi_mqtt_gpio# python3 -m pi_mqtt_gpio.server ~/pi_mqtt_gpio.example.yml
Module <module 'pi_mqtt_gpio.modules.stdio' from '/usr/local/lib/python3.4/dist-packages/pi_mqtt_gpio/modules/stdio.py'> has no extra requirements to install.
__init__(config={'module': 'stdio', 'name': 'dev'})
setup_pin(pin=21, direction=<PinDirection.OUTPUT: 1>, pullup=None, pin_config={'module': 'dev', 'off_payload': 'OFF', 'pin': 21, 'name': 'test', 'on_payload': 'ON'})
MQTT client: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b''
MQTT client: Received CONNACK (0, 0)
Connected to the MQTT broker with protocol v3.1.1.
Subscribed to topic: 'pimqttgpio/mydevice/output/test/set'
Subscribed to topic: 'pimqttgpio/mydevice/output/test/set_on_ms'
Subscribed to topic: 'pimqttgpio/mydevice/output/test/set_off_ms'
MQTT client: Received SUBACK
MQTT client: Received SUBACK
MQTT client: Received SUBACK
Input 'button' state changed to False
MQTT client: Sending PUBLISH (d0, q0, r0, m4), 'b'pimqttgpio/mydevice/input2/button'', ... (3 bytes)
MQTT client: Sending PINGREQ
MQTT client: Received PINGRESP
MQTT client: Sending PINGREQ
MQTT client: Received PINGRESP
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (2 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'ON'
Payload b'ON' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (2 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'on'
Payload b'on' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (3 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'off'
Payload b'off' does not relate to configured on/off values.
MQTT client: Sending PINGREQ
MQTT client: Received PINGRESP
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (2 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'ON'
Payload b'ON' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (2 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'ON'
Payload b'ON' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (2 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'ON'
Payload b'ON' does not relate to configured on/off values.
MQTT client: Sending PINGREQ
MQTT client: Received PINGRESP
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (2 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'ON'
Payload b'ON' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (2 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'ON'
Payload b'ON' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (1 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'1'
Payload b'1' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (4 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'true'
Payload b'true' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (4 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'True'
Payload b'True' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (4 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'TRUE'
Payload b'TRUE' does not relate to configured on/off values.
MQTT client: Received PUBLISH (d0, q0, r0, m0), 'pimqttgpio/mydevice/output/test/set', ...  (1 bytes)
Received message on topic 'pimqttgpio/mydevice/output/test/set': b'1'
Payload b'1' does not relate to configured on/off values.

The MQTT messages seem to be fine.

pimqttgpio/mydevice/output/test/set ON
pimqttgpio/mydevice/output/test/set on
pimqttgpio/mydevice/output/test/set off
pimqttgpio/mydevice/output/test/set ON
pimqttgpio/mydevice/output/test/set ON
pimqttgpio/mydevice/output/test/set ON
pimqttgpio/mydevice/output/test/set ON
pimqttgpio/mydevice/output/test/set ON
pimqttgpio/mydevice/output/test/set 1
pimqttgpio/mydevice/output/test/set true
pimqttgpio/mydevice/output/test/set True
pimqttgpio/mydevice/output/test/set TRUE
pimqttgpio/mydevice/output/test/set 1

Config

mqtt:
  host: localhost
  port: 1883
  user: "***"
  password: "****"
  topic_prefix: pimqttgpio/mydevice

gpio_modules:
  - name: raspberrypi
    module: raspberrypi

  - name: dev
    module: stdio

digital_inputs:
  - name: button
    module: raspberrypi
    pin: 22
    on_payload: "ON"
    off_payload: "OFF"
    pullup: no
    pulldown: yes

digital_outputs:
#  - name: bell
#    module: pcf8574
#    pin: 20
#    on_payload: "ON"
#    off_payload: "OFF"

  - name: test
    module: dev
    pin: 21
    on_payload: "ON"
    off_payload: "OFF"

Am I doing something wrong?
Why is there a "b" at the beginning of the value?

AttributeError: 'module' object has no attribute 'REQUIREMENTS'

Error when trying to run for the 1st time:

sudo python -m pi_mqtt_gpio.server /home/pi/code/config.yml
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/pi_mqtt_gpio/server.py", line 96, in <module>
    install_missing_requirements(gpio_module)
  File "/usr/local/lib/python2.7/dist-packages/pi_mqtt_gpio/server.py", line 29, in install_missing_requirements
    reqs = getattr(module, "REQUIREMENTS")
AttributeError: 'module' object has no attribute 'REQUIREMENTS'

RPi.GPIO is already installed:

pip install RPi.GPIO
Requirement already satisfied: RPi.GPIO in /usr/lib/python2.7/dist-packages

Config file:

mqtt:
  host: localhost
  port: 1883
  user: ""
  password: ""
  topic_prefix: pimqttgpio/mydevice

gpio_modules:
  - name: raspberrypi
    module: raspberrypi
  - name: dev
    module: stdio

digital_inputs:
  - name: button
    module: raspberrypi
    pin: 21
    on_payload: "ON"
    off_payload: "OFF"
    pullup: no
    pulldown: yes

digital_outputs:
  - name: test
    module: dev
    pin: 1
    on_payload: "ON"
    off_payload: "OFF"

Any ideas?

GPIO pull down

Hello!
I'm a newbie to python and I can't understand how to pull down input pin.
Even I write pulldown: on in config.yml or edit raspberrypi.py with

if pullup is None:
            pullup = PULLUPS[PinPullup.DOWN]
            #pullup = PULLUPS[PinPullup.OFF]
        else:
            pullup = PULLUPS[PinPullup.DOWN]
            #pullup = PULLUPS[pullup]

(commented existing settings to not miss a thing) I've got nothing.
Can you help me?
Thanks!

Status topic

How can i get the status topic for a specific gpio? The "status_topic: status" seems to always return running

Use interrupts where possible.

Polling sucks. The logical next step is to implement a module interface for interrupts using callbacks perhaps. This is an Issue to remind myself, or if somebody else fancies taking it on, PRs are welcome!

Any help would be great...

I have followed the Wiki install and get the following issues

pi@raspberrypi:~ $ python pi_mqtt_gpio.server config.yaml
python: can't open file 'pi_mqtt_gpio.server': [Errno 2] No such file or directory

Any help would be great...

Getting FATAL ERROR Message

Hi Flyte,

Thanks for the hard work on this. I installed the script last week and had no issues at all. Today I'm getting the following error.

pi@pi:~ $ pip install pi-mqtt-gpio
...
Successfully installed PyYAML-3.13 cerberus-1.2 enum34-1.1.6 paho-mqtt-1.3.1 pi-mqtt-gpio-0.2.5

pi@pi:~ $ python -m pi_mqtt_gpio.server pi-mqtt-gpio.yml
FATAL ERROR: The file at pi_mqtt_gpio/init.py should be replaced using 'make schema' before packaging.

I'm using the same Rasberry Pi 2B v1.1 as I used last week. Please let me know if you need any other information.

I'm grateful for any advice.

Thanks,
FreeDal.

No data Being sent across

Now, I'm trying to use your Service, but as of yet, I cannot get it to send data across to the Subscribing service. I have tested the Publish script I have and I am able to Publish and subscribe using the Normal mosquito Client. But your service is not working to send the data across and turn on the GPIO pins. I'm not getting any error messages and it's just sitting there with the message:
MQTT client: Sending PINGREQ
MQTT cleint: Receiving PINGRESP
Now, this is all its doing when I send the message to turn on the GPIO's. I'm new to this, could I please get some tips, please. Is there a step im missing ?

feature request: retain inputs

I just discovered your service and am testing it. I see that you recently added the option to configure outputs with retain = true. It would be great to have this option for inputs.

In my case, I'm using node-red. when I redeploy a flow, the client session is reset, and I don't get input status until it changes state. some of my sensors only change twice a day, so this is a problem for me.

Thanks for considering this request.

GPIO init at boottime

When the RPI gets a reboot the relay swtiches ON for 0.700ms. I think this has something to do with the server being started.

I've searched on Google what this might be, there are some pins (1-8) that are set to HIGH at boot time, and the rest are set to LOW, documentation is found here (See page 102):
https://www.raspberrypi.org/documentation/hardware/raspberrypi/bcm2835/BCM2835-ARM-Peripherals.pdf

I've changed the pins of the relay to GPIO 6, 12, 26 and 20 and when I remove the mqtt-server from crontab they stay OFF. But when I uncomment the rule again and the server starts the relays are pulled.

I've also tried to include a script at boot but that didn't work:

#!/bin/sh

echo "2" > /sys/class/gpio/export
gpio -g write 2 1
gpio -g export 2 out

But then again, I might use the script above in the wrong way.

Add support for MCP23017 16 bit I/O expander

Originally posted as a pull request by @eXCepT74 so I've moved it to an issue:

Is that possible to add support for MCP23017 - it has 16 I/O ports , I2C and each port can be loaded with 20mA , it has as well switchable active pullup resistors. I probably will use ur project to control my smart house based on PCF, but MCP is good idea as well. Anyway great project! Keep going like that!!! regards

Where's inputs?

Hello,

Am I missing something? I have a topic '/my/prefix' and a few GPIO pins setup. I can publish to /my/prefix/output/fan/set and it works, but I don't see any corresponding state in /my/prefix/input/fan

I would expect that I could see both the current state and set the state of a GPIO pin using these but I'm not sure where my inputs are...

RuntimeWarning: This channel is already in use, continuing anyway

When I cancel the program with Ctrl+C and restart it, I get the following warning:

root@raspi01:~# python3 -m pi_mqtt_gpio.server ~/pi_mqtt_gpio_2.yml
/usr/local/lib/python3.4/dist-packages/pi_mqtt_gpio/modules/raspberrypi.py:39: RuntimeWarning: This channel is already in use, continuing anyway.  Use GPIO.setwarnings(False) to disable warnings.
  self.io.setup(pin, direction, pull_up_down=pullup)
MQTT client: Sending CONNECT (u1, p1, wr0, wq0, wf0, c1, k60) client_id=b''
MQTT client: Received CONNACK (0, 0)
Connected to the MQTT broker with protocol v3.1.1.
Subscribed to topic: 'test/output/lights/set'
Subscribed to topic: 'test/output/lights/set_on_ms'
Subscribed to topic: 'test/output/lights/set_off_ms'

I do'#t know if this is causing any problem, but maybe it would make sense to include GPIO.cleanup().
see: http://raspi.tv/2013/rpi-gpio-basics-3-how-to-exit-gpio-programs-cleanly-avoid-warnings-and-protect-your-pi

btw: Is there a better way to exit the program?

Momentary output

There are cases where you absolutely want an output to be on (off) for a short period. It would be nice to have this contained in the raspi config and not count on a remote client sending the correct temporary command.

outputs pulled low at startup

It looks like digital outputs are pulled low when the program starts.

This isn't ideal, because it means if I reboot my raspberry pi (there is a power cut, for example) my boiler will fire itself up!

Could there be a "default" setting in the config?

Is it sensible for outputs to be deliberately set OFF on startup?

Happy to provide a pull request for either or both of those, if you think this is a good idea.

It's disappointing that mqtt doesn't remember the previous setting. Home Assistant knows that the boiler should be off, and it published home/boiler/output/boiler/set to OFF at some point in the past, but that fact isn't available any more.

Feature request: add SSL support

Hello,

Please add MQTT over SSL support to connect to the MQTT server even if it uses self signed certificate or cert issued by a local CA.

Question: Multiple output statements

Hi,

Thanks for writing this module! This makes life a lot easier and was exactly what I was looking for :)

At the moment I'm writing a small how-to on fully deploying a Pi with 4 realys and connecting them to Home Assistant (for automating a ceiling fan).

My question is: Is it possible to create a config file containing multiple output statements? Like speed-1, speed-2, speed-3, lights. Or should they get their own topics, it's all for the same device.

At the moment my config looks like:

mqtt:
  host: 192.xxx.xxx.xxx
  port: 1883
  user: "redacted"
  password: "redacted"
  topic_prefix: bedroom/ceiling-fan

gpio_modules:
  - name: raspberrypi
    module: raspberrypi

digital_outputs:
  - name: speed-1
    module: raspberrypi
    pin: 17
    on_payload: "ON"
    off_payload: "OFF"

digital_outputs:
  - name: speed-2
    module: raspberrypi
    pin: 18
    on_payload: "ON"
    off_payload: "OFF"

digital_outputs:
  - name: lights
    module: raspberrypi
    pin: 23
    on_payload: "ON"
    off_payload: "OFF"

One more ...

Thanks for your input!

DHT11 or DHT22 sensor

Hi
If this is a pull request sorry..

I have a few DHT11 sensors and was hoping I could add them to this setup, is it possible?

Cheers
Rich

No module name pi_mqtt_gpio script

I tried making a startup script for this but get:
"/usr/bin/python: No module named pi_mqtt_gpio"

when running:
sudo python -m pi_mqtt_gpio.server config.yml

In a startup.sh file. Works great when not in a .sh file.
Also i'm a noob so sorry if this is a dumb problem.

PWM

Hello,

it works all very good, thanks for your script...

Could you still install PWM for all GPIO?

Feature request

Hi @flyte

Is it possible to add the options to provide a protocol and a websocket port? Home Assistant requires these to function :)

Below is a example of the defaults that should be entered in a config Link

Host: localhost
Port: 1883
Protocol: 3.1.1
User: homeassistant
Password: Your API password
Websocket-port: 8080

pi-mqtt-gpio + VN + Pi2B

Hey Ellis,

got an issue using your example code on a raspberry pi 2B.
Error log looks like this:

Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/pi/ve/lib/python2.7/site-packages/pi_mqtt_gpio/server.py", line 473, in <module>
    gpio_config)
  File "/home/pi/ve/lib/python2.7/site-packages/pi_mqtt_gpio/server.py", line 414, in configure_gpio_module
    return gpio_module.GPIO(gpio_config)
  File "/home/pi/ve/local/lib/python2.7/site-packages/pi_mqtt_gpio/modules/raspberrypi.py", line 16, in __init__
    import RPi.GPIO as gpio
ImportError: No module named RPi.GPIO

I've tried to use this one within the vn, but unfortunately it didn't work. :/

pip install RPi.GPIO

Add `inverted` config for digital outputs

In order to add topic suffixes such as /set_on_ms and /set_off_ms we need to make sure that 'on' does indeed turn on the device. /set has been able to handle this in the past using on_payload and off_payload but it doesn't cut the mustard for explicit on/off topics.

It makes more sense to just add an inverted config value for each digital output so that it can be handled once and for all while setting up the output configuration.

Two piface2 modules on same board

Would it be possible to add support for two piface2 modules? At the moment only the first piface2 seems to be supported, and there does not seem to be an option to select the second one on a different address. With the address jumpers 4 modules in total are allowed on the same Pi.

I would like something like this:

gpio_modules:
  - name: piface2-1
    module: piface2
    chip_select: 0

  - name: piface2-2
    module: piface2
    chip_select: 1

New issue after upgrade "Config did not validate"

I've been using mqtt-gpio for a few months to monitor door sensors via RPi's GPIO pins and it's been working great. However after upgrading yesterday, I'm getting an error I'm not quite sure what to make of. Here's the error thrown (and my config file below that):

Config did not validate:

digital_inputs:
- 0:
  - initial:
    - unknown field
  1:
  - initial:
    - unknown field
  2:
  - initial:
    - unknown field

And here's my config.yml file

mqtt:
  host: localhost
  #port: 1883
  #user: ""
  #password: ""
  topic_prefix: home/sensors

gpio_modules:
  - name: raspberrypi
    module: raspberrypi

digital_inputs:
  - name: TV_SGD
    module: raspberrypi
    pin: 27
    on_payload: "OPEN"
    off_payload: "CLOSED"
    initial: low  
    retain: yes

  - name: Kitchen_Door
    module: raspberrypi
    pin: 17
    on_payload: "OPEN"
    off_payload: "CLOSED"
    initial: low  
    retain: yes 

  - name: TV_SGD_BOARD
    module: raspberrypi
    pin: 11
    on_payload: "OPEN"
    off_payload: "CLOSED"
    initial: low  
    retain: yes 

Thanks for any suggestions.

Install trouble - ImportError: No module named commands.install

pi-mqtt-gpio is rolling reboot. see log snapshot below. any suggestions? thanks.

Last will set on 'home/garage/status' as 'dead'.
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/pi/ve/lib/python2.7/site-packages/pi_mqtt_gpio/server.py", line 449, in <module>
    gpio_config)
  File "/home/pi/ve/lib/python2.7/site-packages/pi_mqtt_gpio/server.py", line 389, in configure_gpio_module
    install_missing_requirements(gpio_module)
  File "/home/pi/ve/lib/python2.7/site-packages/pi_mqtt_gpio/server.py", line 215, in install_missing_requirements
    from pip.commands.install import InstallCommand
ImportError: No module named commands.install

Add Banana Pi/Pro Module

Hi, this project looks awesome.
I would love to use it on my Banana Pro board. Unfortunatly I have no Python skills to implement it on my own. Therefore, I would ask you/the community to adapt the raspberry pi module to the wiriningPi library for Banana Pi/Pro

Official BPI-WiringPi2-Python library

Thank you very much!

Add local logic to connect inputs to outputs without relying on external control

hi,
For my home automation project, i was looking for a way to control a set of relays using mqtt (and Openhab). And as an added feature, i wanted to use a switch array (connected to separate GPIOs on my PI zero) to control these relays. I tried writing my own python program but failed miserably at it. Recently i came across your implementation and tested it. It is working very well in controlling the relays using mqtt and capturing the button press. However, i was trying to find a way to control the relay when a button is pressed.

button 1(GPIO 19) -> "ON" -> publish mqtt status
|---> pull up (GPIO 4) to control the relay.

One implementation option is subscribe to the mqtt input status message and send a new output message to switch on. This has to be done by Openhab or any other python routine. Is there any other way to achieve this?

Thanks
Sudhansu

Cannot define digital_outputs with raspberrypi module

I cannot get the program started wehen I define digital_outputs with raspberrypi module.

my config:

mqtt:
  host: localhost
  port: 1883
  user: "***"
  password: "*****"
  topic_prefix: test

gpio_modules:
  - name: raspberrypi
    module: raspberrypi

digital_outputs:
  - name: lights
    module: raspberrypi
    pin: 21
    on_payload: "ON"
    off_payload: "OFF"

Error:

root@raspi01:/usr/local/lib/python3.4/dist-packages/pi_mqtt_gpio# python3 -m pi_mqtt_gpio.server ~/pi_mqtt_gpio_2.yml
Traceback (most recent call last):
  File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
    "__main__", mod_spec)
  File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/usr/local/lib/python3.4/dist-packages/pi_mqtt_gpio/server.py", line 419, in <module>
    initialise_digital_output(out_conf, GPIO_MODULES[out_conf["module"]])
  File "/usr/local/lib/python3.4/dist-packages/pi_mqtt_gpio/server.py", line 378, in initialise_digital_output
    gpio.setup_pin(out_conf["pin"], PinDirection.OUTPUT, None, out_conf)
  File "/usr/local/lib/python3.4/dist-packages/pi_mqtt_gpio/modules/raspberrypi.py", line 35, in setup_pin
    pullup = PULLUPS[0]
KeyError: 0

DS18B20 support

Request for support for the DS18B20;

#32 (comment)

No, as far as I know, one wire from dht11 and one wire from ds18b20 are incompatible. So you should create a new issue for ds18b20, if you want it to be supported. Maybe you could try a library, that should be supported and mention it there. (e.g. https://github.com/timofurrer/w1thermsensor)

Docker Support

Does somebody know, if this project was already ported into a docker container?
Reason: my Smart Home concept completly rely on Docker (simplified lifecycle, easy to maintain).

I know that i have to connect the necessary hardware devices to the container ...

Status Topic Help and advice - Home Assistant switch feedback status

Hi Great project i'm hoping to move all my lighting switching over to MQTT I'm just doing some tests and getting setup I've got it working to a point with home assistant.

I can toggle the switch from within home assistant and the topic is sent and i see its received on the pi running mqttt-gpio and sure enough the relay toggles as expected. The problem is im not getting the return msg to home assistant to keep the switch in the on position... the switch bounces back after a couple off seconds to the off position ( the bounce back isn't sent as an MQTT msg )

Home Assistant

  - platform: mqtt
    name: "MQTT2GPIO"
    state_topic: "pibox/switch/output/1/state"
    command_topic: "pibox/switch/output/1/set"
    payload_on: "ON"
    payload_off: "OFF"
    state_on: "ON"
    state_off: "OFF"
    optimistic: false
    qos: 0
    retain: true

And MQTT-gpio

mqtt:
host: localhost
port: 1883
user: “****”
password: “******”
topic_prefix: pibox/switch

gpio_modules:

name: raspberrypi
module: raspberrypi
digital_outputs:

name: ‘1’
module: raspberrypi
pin: 17
on_payload: “ON”
off_payload: “OFF”

Any help will be much appreciated i understand this isn't an "issue" its just my lack of knowlage , If anyone has an example code for both home assistant and mqtt-gpio i could use that would be great.... my requirements are for just simple switching of lights , boiler and security system i/o

Run at boot time + log location?

Hello, just wanted to say thank you for creating and sharing this program. Super easy to use and works well.

I want to make sure it runs properly at boot time, and I need to be able to access the logs. What is the best way to accomplish this? Thanks!

Add bouncetime? Problems with Bouncing on digital input!

Hello.
My first garagdoor automation setup works really fine.
The only problem is, that i have a "bouncing", everytime from "CLOSED-OPEN-CLOSED" on my reed switchs and i can see it switching in your log.

There should be a function for setting the bouncetime:
https://sourceforge.net/p/raspberry-gpio-python/wiki/Inputs/

add rising edge detection on a channel, ignoring further edges for 200ms for switch bounce handling

GPIO.add_event_detect(channel, GPIO.RISING, callback=my_callback, bouncetime=200)

Ist it possible to set the bouncetime for each digital input in the yml?
e.g. bouncetime: 200 in the yml?
and if bouncetime >0 then run GPIO.add_event_detect?

Would be a great help if you could bring this in!

Greetings charly

Problem with PCF8574

Here my problem:

python -m pi_mqtt_gpio.server config.yml
Downloading/unpacking pcf8574
  Downloading pcf8574-0.0.5.tar.gz
  Running setup.py (path:/tmp/pip-build-0xzCvc/pcf8574/setup.py) egg_info for package pcf8574
    your setuptools is too old (<12)
    setuptools_scm functionality is degraded
    zip_safe flag not set; analyzing archive contents...
    
    Installed /tmp/pip-build-0xzCvc/pcf8574/pytest_runner-2.11.1-py2.7.egg
    
Downloading/unpacking smbus-cffi (from pcf8574)
  Downloading smbus-cffi-0.5.1.tar.gz
  Running setup.py (path:/tmp/pip-build-0xzCvc/smbus-cffi/setup.py) egg_info for package smbus-cffi
    
    Installed /tmp/pip-build-0xzCvc/smbus-cffi/cffi-1.10.0-py2.7-linux-armv7l.egg
    Traceback (most recent call last):
      File "<string>", line 17, in <module>
      File "/tmp/pip-build-0xzCvc/smbus-cffi/setup.py", line 48, in <module>
        'Topic :: System :: Hardware',
      File "/usr/lib/python2.7/distutils/core.py", line 111, in setup
        _setup_distribution = dist = klass(attrs)
      File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 266, in __init__
        _Distribution.__init__(self,attrs)
      File "/usr/lib/python2.7/distutils/dist.py", line 287, in __init__
        self.finalize_options()
      File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 301, in finalize_options
        ep.load()(self, ep.name, value)
      File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2190, in load
        ['__name__'])
    ImportError: No module named setuptools_ext
    Complete output from command python setup.py egg_info:
    

Installed /tmp/pip-build-0xzCvc/smbus-cffi/cffi-1.10.0-py2.7-linux-armv7l.egg

Traceback (most recent call last):

  File "<string>", line 17, in <module>

  File "/tmp/pip-build-0xzCvc/smbus-cffi/setup.py", line 48, in <module>

    'Topic :: System :: Hardware',

  File "/usr/lib/python2.7/distutils/core.py", line 111, in setup

    _setup_distribution = dist = klass(attrs)

  File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 266, in __init__

    _Distribution.__init__(self,attrs)

  File "/usr/lib/python2.7/distutils/dist.py", line 287, in __init__

    self.finalize_options()

  File "/usr/lib/python2.7/dist-packages/setuptools/dist.py", line 301, in finalize_options

    ep.load()(self, ep.name, value)

  File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 2190, in load

    ['__name__'])

ImportError: No module named setuptools_ext

----------------------------------------
Cleaning up...
Command python setup.py egg_info failed with error code 1 in /tmp/pip-build-0xzCvc/smbus-cffi
Storing debug log for failure in /home/pi/.pip/pip.log
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 162, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/usr/local/lib/python2.7/dist-packages/pi_mqtt_gpio/server.py", line 99, in <module>
    GPIOS[gpio_config["name"]] = gpio_module.GPIO(gpio_config)
  File "/usr/local/lib/python2.7/dist-packages/pi_mqtt_gpio/modules/pcf8574.py", line 23, in __init__
    from pcf8574 import PCF8574
ImportError: No module named pcf8574

Not tolerant to connection refused error.

If I reboot my MQTT server pi-mqtt-gpio gets a connection refused error but only tries to reconnect once, then gets stuck. It doesn't exit, so (for example) systemd won't restart it.

What's a nice way to handle this?

Disconnected from MQTT server with code: 1
Exception in thread Thread-1:
Traceback (most recent call last):
  File "/usr/lib/python3.4/threading.py", line 920, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 2606, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 1470, in loop_forever
    rc = self.loop(timeout, max_packets)
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 995, in loop
    rc = self.loop_read(max_packets)
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 1275, in loop_read
    return self._loop_rc_handle(rc)
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 1754, in _loop_rc_handle
    self.on_disconnect(self, self._userdata, rc)
  File "/usr/local/lib/python3.4/dist-packages/pi_mqtt_gpio/server.py", line 93, in on_disconnect
    rc = client.reconnect()
  File "/usr/local/lib/python3.4/dist-packages/paho/mqtt/client.py", line 887, in reconnect
    sock = socket.create_connection((self._host, self._port), source_address=(self._bind_address, 0))
  File "/usr/lib/python3.4/socket.py", line 509, in create_connection
    raise err
  File "/usr/lib/python3.4/socket.py", line 500, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

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.