Report Bugs Here

Moderator: Mmiscool

User avatar
By perozonp
#59961 Just flashed my first sonoff and running the blink example (runs fine). I modified it to toggle the relay and the led with a button each but after several tests I found that every time I read the pin with io(pi,x) it resets the pin:

Relay pin (gpio 12) gets set to 0
Led pin (gpio 13) gets set to 1

Am I making something wrong? has anyone else tested this in a sonoff device?

this is the full code I have come up to effectively toggle the Relay and the Led (a button for each) but the previous status is based on the variable internally set, I can't read the actual status, as soon as I press the "Read" button it resets the ouputs...

noOfBlinks = 0
pin = 0
blinkDelay = 1000
Led = 0
Relay = 0
[top]
print "How many times to blink"
textbox noOfBlinks
print "Pin To use"
textbox pin
print "Blink Delay"
textbox blinkDelay
button "Blink Me Please", [blinkMe]
button "Relay",[ToggleRelay]
button "Led",[ToggleLed]
button "Read",[Read]
button "Exit", [getMeOutOfHere]
wait


[blinkMe]
for x = 1 to noOfBlinks
io(po,pin,1)
delay blinkDelay
io(po,pin,0)
delay blinkDelay
next x
wait

[ToggleLed]
if Led = 0 then
Led = 1
else
Led = 0
end if
io(po,13,Led)
wait

[ToggleRelay]
if Relay = 0 then
Relay = 1
else
Relay = 0
end if
io(po,12,Relay)
wait

[Read]
print "Led:" & str(io(pi,13))
print "Relay:" & str(io(pi,12))
wait

[getMeOutOfHere]
end