Page 1 of 1

Problem getting GPIO to work[solved]

Posted: Friday 07 June 2019 20:21
by ulfh2018
I want to use GPIO to turn on some relays and LEDs. I have defined the following in /etc/init.d/domoticz.sh:

Code: Select all

gpio export 4 out
gpio export 14 out

sudo sh -c "echo '1' >> /sys/class/gpio/gpio4/active_low"
sudo sh -c "echo '1' >> /sys/class/gpio/gpio14/active_low"
These devices shows up with index 20 and 26

I have also set up a setpoint and a temperature sensor with index 13 (sensor) and 16 (setpoint)

I want to use gpio 4 (index 20) to control the relay and gpio 14 (index 26) to control a LED.

When I test different values for setpoint, gpio 14 will work, but gpio 4 will not, thoug I can manually switch the value.

I have the created the following script:

Code: Select all

return {
    on = {       timer = { 'every minute'  } },
        execute = function(domoticz)
        local Sensor    = domoticz.devices(13)  -- Temperature
        local SETPOINT  = domoticz.devices(16) -- SetPoint
        SETPOINT.updateSetPoint(SETPOINT.setPoint)  -- This will refresh the setPoint with current value
        if (Sensor.temperature <= (SETPOINT.setPoint - 0.2)) then -- turn on heat   
        domoticz.devices(20).switchOn().checkFirst()
        domoticz.devices(26).switchOff().checkFirst()
        elseif (Sensor.temperature >= (SETPOINT.setPoint + 0.2)) then -- turn off hea
        domoticz.devices(20).switchOff().checkFirst()
        domoticz.devices(26).switchOn().checkFirst()
        else
            -- within hysteresis range
        end
    end
}
Can someone see what I might be doing wrong?

Best regards

Ulf

Re: Problem getting GPIO to work

Posted: Friday 07 June 2019 20:48
by waaren
ulfh2018 wrote: Friday 07 June 2019 20:21 Can someone see what I might be doing wrong?
The dzVents seems OK. Don't understand why you have the 'refresh' line but it should not harm the flow of the code.
Do you see anything in the domoticz log ?
If not; may I suggest to add some log statements in the code ?

Re: Problem getting GPIO to work

Posted: Friday 07 June 2019 21:41
by ulfh2018
Hi Waaren
Thank you for having a look!

I found the problem. I had used similar names for some of the devices, when I changed that, everything worked as expected. The name of the sensor and the name of the switch was the same. Stupid me!
I thought the refresh was to avoid the setPoint becoming red after a while, or am I wrong?

Re: Problem getting GPIO to work

Posted: Friday 07 June 2019 23:57
by waaren
ulfh2018 wrote: Friday 07 June 2019 21:41 Hi Waaren
Thank you for having a look!

I found the problem. I had used similar names for some of the devices, when I changed that, everything worked as expected. The name of the sensor and the name of the switch was the same. Stupid me!
I thought the refresh was to avoid the setPoint becoming red after a while, or am I wrong?
Good that you found it and yes the refresh prevent the inactive color to come up.