GPIO working with Wiring pi but not with Domoticz ...

Post Reply
Loops
Posts: 8
Joined: Wednesday 22 October 2014 21:15
Target OS: Raspberry Pi
Domoticz version:
Contact:

GPIO working with Wiring pi but not with Domoticz ...

Post by Loops » Tuesday 14 June 2016 20:05

Hi All !

I'm trying to use the GPIO from my Pi Zero in Domoticz (Version: 3.4834).
I've installed Wiring Pi. OK
Ive added this /usr/local/bin/gpio export 17 in in the /etc/init.d/domoticz.sh file and rebooted the Pi.

Now i connect the Pin 11 (GPIO 17) to the ground. The gpio exports give me :

Code: Select all

[email protected]:~$ gpio exports
GPIO Pins exported:
  17: in   0  none    
Next i connect the pin 11 (GPIO 17) to 3.3V pin and the gpio exports give me :

Code: Select all

[email protected]:~$ gpio exports
GPIO Pins exported:
  17: in   1  none    
all seem's good ! No ?

Next step, I configure a new switch "contact" in DZ with the gpio 17.
For inputs
Select the GPIO port hardware you just configured, give it a name, select the "Contact" switch type and a "GPIO" type. You can now select the pin in the list. Obviously, the ones you configured above should not start with the "! NON EXPORTED" mention. Then click "Add Device". The mention "open/closed" corresponds to a switch connected between the pin and the ground, with the pin also connected to a pull-up (as you have read on the wiringPi website, some GPIO have an internal permanent pull-up.
DZ.png
DZ.png (72.28 KiB) Viewed 5600 times
The switch status is always Closed.
When the GPIO exports is 17: in 0 none, the switch is closed
When the GPIO exports is 17: in 1 none, the switch is closed

i don't understand.

somebody have any idea ?

Thank's a lot an sorry for my bad english :(

User avatar
cyberclwn
Posts: 105
Joined: Thursday 20 August 2015 22:53
Target OS: Raspberry Pi
Domoticz version: beta
Location: The Netherlands
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by cyberclwn » Tuesday 05 July 2016 0:13

Hey,

In the wiki (https://www.domoticz.com/wiki/GPIO) it says:

Code: Select all

For outputs:
gpio export <BCM PIN #> out
Example: 
gpio export 17 out

For inputs:
gpio export <BCM PIN #> in
gpio edge <BCM PIN #> both
Example:
gpio export 18 in
gpio edge 18 both
Since you said:
Loops wrote: Ive added this /usr/local/bin/gpio export 17 in in the /etc/init.d/domoticz.sh file and rebooted the Pi.
I assume you need gpio 17 as an input, so where is your second line needed for inputs ? :)
3xPi 2B (Domoticz "live", Domoticz "sandbox", PhotoFrame)
RFXCom433(E), KaKu, Oregon Scientific, Keyes 2-relay, Logitech Media Server, MiLight, Smartwares heating controller(2x), IR Send/Receive, Keyes PIR, XH-M131 DuskSensor, DHT22/11

MichaelM
Posts: 22
Joined: Thursday 12 February 2015 0:03
Target OS: Raspberry Pi
Domoticz version:
Location: Belgium
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by MichaelM » Thursday 07 July 2016 1:39

I'm having the exact same issue on rpi2.
And as suggested I did set the "gpio edge ## both"

Anyone?

Norway
Posts: 10
Joined: Saturday 21 May 2016 15:09
Target OS: Raspberry Pi
Domoticz version: Latest B
Location: Sorumsand, Norway
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by Norway » Saturday 16 July 2016 18:32

Maybe you need to "Accept new hardware", in settings.

Draakje
Posts: 93
Joined: Thursday 22 October 2015 21:14
Target OS: Linux
Domoticz version: 3.5468
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by Draakje » Thursday 21 July 2016 23:14

I have a kinda similar problem.

I can use gpio exports and I did set the out and in (with both) in the domoticz.sh (like the wiki states)

But I don't see the GPIO hardware in the list..

Where should I look for help?

What can be the problem?

Working on Raspberry pi3 with ubuntu 16.04 and latest Domoticz version
Hardware: Raspberry Pi 3, OTGW, 433MHz Superheterodyne 3310 RF Link
Software: Ubuntu 16.04, Domoticz v3.5468, WiringPi, rc-switch

jstam84
Posts: 3
Joined: Monday 11 July 2016 21:38
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by jstam84 » Sunday 24 July 2016 16:05

Hi all!

I actually had the same problem. The following script seems to work perfectly, so I've added that to /etc/rc.local (with trailing &) to run in the background. Doesn't hog CPU and works like a charm. I use it to control two kaku light switches (IDX 168 and 65). Put it in /usr/local/bin/ or something like that and add it to /etc/rc.local (don't forget the trailing & !!!). Then, change the switch dictionary to reflect your setup (Format: PIN:IDX). If applicable, change 'localhost' to your liking.

Note: You'll have to install wiringpi (see: http://raspi.tv/how-to-install-wiringpi ... spberry-pi)
Note2: The requests module uses SSL which unfortunately contains a bug; importing this module takes about 1.3s. This is fixed upstream but not yet available in Debian Wheezy. Since it causes no issues, I didn't bother to look into it. ;)

Code: Select all

#!/usr/bin/python

import wiringpi
import requests
from time import sleep
import json

url = 'http://localhost:8080/json.htm'
switch = {2:168,3:65}				# Format: PIN:IDX
switch_state = {}
args = { 'type':'command','param':'switchlight','idx':'','switchcmd':'' }

wiringpi.wiringPiSetup()

for s in switch:
  wiringpi.pinMode(s, 0)
  wiringpi.pullUpDnControl(s, 2)
  switch_state[s] = wiringpi.digitalRead(s)

while True:
  for s in switch:
    pin = wiringpi.digitalRead(s)
    if pin != switch_state[s]:
      switch_state[s] = pin

      req=requests.get(url+'?type=devices&rid=%i' % switch[s])
      j=req.json()
      args['switchcmd'] = j['result'][0]['Status'] == 'Off' and 'On' or 'Off'
      args['idx'] = switch[s]
      requests.get('http://localhost:8080/json.htm',params=args)

  sleep(0.05)

SteveR
Posts: 1
Joined: Thursday 27 October 2016 15:51
Target OS: Raspberry Pi
Domoticz version: 3.4834
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by SteveR » Thursday 27 October 2016 16:12

Just been trying to get a Contact to work with RPI 3 on pin 18 and found that I needed in /etc/init.d/domoticz.sh

#Run export GPIO Raspberry
# pin 18, input, edge trigger, pull up
/usr/local/bin/gpio export 18 in
/usr/local/bin/gpio edge 18 both
/usr/local/bin/gpio -g mode 18 up

It looks like the web interface/server is edge triggered

at which point (without actually using a real switch) and without any additional scripts

gpio -g mode 18 down
gave me Closed

and

gpio -g mode 18 up
gave me Open

changes were reflected on the web page :)

User avatar
sisaenkov
Posts: 70
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by sisaenkov » Friday 23 December 2016 10:27

jstam84 wrote:

Code: Select all

#!/usr/bin/python

import wiringpi
import requests
from time import sleep
import json

url = 'http://localhost:8080/json.htm'
switch = {2:168,3:65}				# Format: PIN:IDX
switch_state = {}
args = { 'type':'command','param':'switchlight','idx':'','switchcmd':'' }

wiringpi.wiringPiSetup()

for s in switch:
  wiringpi.pinMode(s, 0)
  wiringpi.pullUpDnControl(s, 2)
  switch_state[s] = wiringpi.digitalRead(s)

while True:
  for s in switch:
    pin = wiringpi.digitalRead(s)
    if pin != switch_state[s]:
      switch_state[s] = pin

      req=requests.get(url+'?type=devices&rid=%i' % switch[s])
      j=req.json()
      args['switchcmd'] = j['result'][0]['Status'] == 'Off' and 'On' or 'Off'
      args['idx'] = switch[s]
      requests.get('http://localhost:8080/json.htm',params=args)

  sleep(0.05)
To match gpio pin numbers with it's titles on RPi you need to initialise GPIO mode.
Change wiringpi.wiringPiSetup() to wiringpi.wiringPiSetupGpio()

Trippleblack
Posts: 2
Joined: Tuesday 27 December 2016 22:37
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by Trippleblack » Tuesday 27 December 2016 23:12

Okay, after struggeling for a few days now I can usesome help.

Raspberry pi 3 and door contact conneted to GPIO 27, declared import and exports the right way in /etc/init.d/domoticz.sh. ( /usr/local/bin/gpio export 27 in, /usr/local/bin/gpio edge 27 both, /usr/local/bin/gpio -g mode 27 up)

in SSH I can confirm the gpio pin changes by using the "gpio readall" command

The problem is the slow response of the switches in Domoticz. after opening the door it takes anywhere between 3 and 20 seconds to update the switch.

So I figured the above script would be the perfect solution for me ....

After changeing the pin layout to match my IDX and GPIO pin, I added the folowing line to /etc/rc.local:
sudo python /home/pi/domoticz/scripts/gpio-script.py $

and can confirm it runs the script at startup. so far so good. but no result.

If I browse to the machine:8080/json.htm it shows the following error:
{
"status" : "ERR"
}


All elp is appreciated!!, for example, How do I check where the script goes wrong?

User avatar
sisaenkov
Posts: 70
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by sisaenkov » Wednesday 28 December 2016 10:18

"status: ERR" is normal for the page with empty json request.
Are you sure that status changing in Domoticz is slow, but not dashboard refresh?

For autostart script on RPi boot you can use init script (named gpioinputs).

Create /etc/init.d/gpioinputs and put next there:

Code: Select all

#!/bin/sh

### BEGIN INIT INFO
# Provides:          gpioinputs
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: GPIOinputs
# Description:       Domoticz GPIO inputs status daemon
### END INIT INFO

# Change the next 3 lines to suit where you install your script and what you want to call it
DIR=/usb/domoticz/scripts
DAEMON=$DIR/gpioinputs.py
DAEMON_NAME=gpioinputs

# Add any command line options for your daemon here
DAEMON_OPTS=""

# This next line determines what user the script runs as.
# Root generally not recommended but necessary if you are using the Raspberry Pi GPIO from Python.
DAEMON_USER=root

# The process ID of the script when it runs is stored here:
PIDFILE=/var/run/$DAEMON_NAME.pid

. /lib/lsb/init-functions

do_start () {
    log_daemon_msg "Starting system $DAEMON_NAME daemon"
    start-stop-daemon --start --background --pidfile $PIDFILE --make-pidfile --user $DAEMON_USER --chuid $DAEMON_USER --startas $DAEMON -- $DAEMON_OPTS
    log_end_msg $?
}
do_stop () {
    log_daemon_msg "Stopping system $DAEMON_NAME daemon"
    start-stop-daemon --stop --pidfile $PIDFILE --retry 10
    log_end_msg $?
}

case "$1" in

    start|stop)
        do_${1}
        ;;

    restart|reload|force-reload)
        do_stop
        do_start
        ;;

    status)
        status_of_proc "$DAEMON_NAME" "$DAEMON" && exit 0 || exit $?
        ;;

    *)
        echo "Usage: /etc/init.d/$DAEMON_NAME {start|stop|restart|status}"
        exit 1
        ;;

esac
exit 0
You need to specify some init-script's parameters:
DIR=/usb/domoticz/scripts - dir path where python script is located.
DAEMON=$DIR/gpioinputs.py - python script name.

Trippleblack
Posts: 2
Joined: Tuesday 27 December 2016 22:37
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by Trippleblack » Wednesday 28 December 2016 13:38

Thank you Sisanenkov!

Now you mention it ... I think it is the dashboard refresh rate :oops:

Can this be changed?

User avatar
sisaenkov
Posts: 70
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by sisaenkov » Wednesday 28 December 2016 14:37

Nope.

Kruu
Posts: 14
Joined: Tuesday 17 January 2017 21:27
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by Kruu » Saturday 21 January 2017 15:45

Any fix on this? I've put magnet sensor and PIR sensor in my home, but domoticz is slow reading. gpio export reads instantly but domoticz needs 5-10 seconds. My door opens and closes and there is no notifications in domoticz, because door needs to be opened for minimum 10 seconds.

User avatar
sisaenkov
Posts: 70
Joined: Friday 27 May 2016 7:21
Target OS: Raspberry Pi
Domoticz version: 3.8
Location: Moscow, Russia
Contact:

Re: GPIO working with Wiring pi but not with Domoticz ...

Post by sisaenkov » Saturday 21 January 2017 18:50

Kruu wrote:Any fix on this? I've put magnet sensor and PIR sensor in my home, but domoticz is slow reading. gpio export reads instantly but domoticz needs 5-10 seconds. My door opens and closes and there is no notifications in domoticz, because door needs to be opened for minimum 10 seconds.
It's only WebGUI reflesh slowness.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest