• 10 dec 2017: forum version update. In case of issues use this topic.
  • 30 nov 2017: pilight moved servers. In case of issues use this topic.
Hello There, Guest! Login Register


need help with gui / gpio / python
#1
pilight verion installed  8.1.5

Hello,

I want from the gui a switch on/off, that should switch a gpio on a raspberry and with a python script,  the on /off
status from switch in  the gui should  print if it is on or off.

the .json look like this:
 
                "Switch3": {
                        "protocol": [ "relay" ],
                        "id": [{
                                "gpio": 3
                        }],
                        "state": "off"
If I switch the on /off button in the gui  I can see with, "gpio  readall",  that gpio 3 go high and low.
With BCM gpio3 is  gpio 22.

The python script looks like this:


Code:
#!/usr/bin/env python3

import gpiozero
from gpiozero import Button
import time
from time import sleep


button = Button(22, pull_up=True)   # GPIO 22 / Pin 15


while True:
    sleep(1)
    if button.is_pressed:            # this is signal high
        print("On")

    if not button.is_pressed:        # this is signal low
        print("Off")

All above works more or less, if I switch on in the gui, it will print on, if I switch off in the gui it will print off, but only if the python script is already running.

The problem now is, that even if with  "gpio allreadall" I can see that the gpio 22 is high or low, the python script
only prints on /off after I switch the on/off switch in the gui a few times.

If gpio 22 is high and I start the python script it prints off, only after switching in the gui again off /on it starts to work as expected, but every time I stop the python script and restart it, even the gui switch stayed on, it begins to
print off.

What is the problem, that the python script is not getting the same info from the gpio allreadall status??

best regards
tom
 
Reply
#2
So pilight works as expected?
 
Reply
#3
(08-06-2019, 08:58 AM)curlymo Wrote: So pilight works as expected?

Yes, I think pilight is working ok so far, it is the reading of the gpio 22  in the raspberry that is not correct.

How can I read the information from the pilight web-gui in a python script correctly??

Thanks and regards
tom
 
Reply
#4
If pilight works correctly, but your python script doesn't, you should ask for help somewhere else. Python scripting is not something i can give support in.
 
Reply
#5
(08-06-2019, 06:10 PM)curlymo Wrote: If pilight works correctly, but your python script doesn't, you should ask for help somewhere else. Python scripting is not something i can give support in.

Hi curlymo,
how exactly is  protocol "relay" and  "gpio" working in .json??
What and how is it working in the Raspberry?
Is there a documentation?, examples?
Thanks and regards
tom
 
Reply
#6
You can check the source code of pilight and wiringx on github and read the manual of both projects.
 
Reply
#7
(08-07-2019, 06:50 AM)curlymo Wrote: You can check the source code of pilight and wiringx on github and read the manual of both projects.

Thank for the info.
My project is working now, I changed my script.  reading with a input, the output signal from GPIO 4.
All I had to do is put a wire from GPIO4  to another GPIO.

best regards

tom
 
Reply
  


Forum Jump:


Browsing: 1 Guest(s)