letscontrolit / ESPEasy

Easy MultiSensor device based on ESP8266/ESP32
http://www.espeasy.com
Other
3.28k stars 2.21k forks source link

MQTT lost connection and device lost ping for 3 sec after gpio,x,x command #1228

Closed erokoder closed 5 years ago

erokoder commented 6 years ago

Hello all,

I am developing home bridge plugin with mqtt broker for up and down blinds. So, I want "up and down" blinds with Home App, and also I want "up and down" blinds with with a physical wall switch. Physical wall switch connected to GPIO0 AND GPIO9 (Sonoff Dual r2, lastes firmware v2.0-20180322) Control even is [Import#moving] that show // 0 = Stoped , 1=Moving Up , Moving Down. When app start moving down, App publish 1, after blinds moving finished, sonoff publish 2. So, I have problem with publish 2. For some reason after gpio,12,0 mqtt lost connection and dont publish 2, and also mqtt import dont update state moving to 2. A couple of times pass without problems, but every some time the connection is lost, and this is always on this part after gpio,12,0 or gpio,5,0. Also when mqtt lost connection, sonoff device lose ping and freezing browser for 3 sec.

I make some things easier with mqtt, and never lost connection to the same device son off dual r2. (So, The device is okay)

All Rules Code:

on Import#moving=0 do 
        gpio,12,1
        Delay [Import#time]
        gpio,12,0
        Publish RoletneMalaSobaWC/currentPosition,[Import#target]
        Publish RoletneMalaSobaWC/statePosition,2
endon

on Import#moving=1 do 
        gpio,5,1
        Delay [Import#time]
        gpio,5,0
        Publish RoletneMalaSobaWC/currentPosition,[Import#target]
        Publish RoletneMalaSobaWC/statePosition,2
endon

on TipkaUp#Stanje=0 do
     if [Import#moving]=2 
        Publish RoletneMalaSobaWC/targetPosition,100
        Publish RoletneMalaSobaWC/time,10000
        Publish RoletneMalaSobaWC/statePosition,1
     endif
endon

on TipkaUp#Stanje=1 do 
     if [Import#moving]=2 
        Publish RoletneMalaSobaWC/targetPosition,100
        Publish RoletneMalaSobaWC/time,10000  
        Publish RoletneMalaSobaWC/statePosition,1
     endif
endon

on TipkaDown#Stanje=0 do
     if [Import#moving]=2 
        Publish RoletneMalaSobaWC/targetPosition,0
        Publish RoletneMalaSobaWC/time,10000
        Publish RoletneMalaSobaWC/statePosition,0
     endif
endon

on TipkaDown#Stanje=1 do 
     if [Import#moving]=2 
        Publish RoletneMalaSobaWC/targetPosition,0
        Publish RoletneMalaSobaWC/time,10000  
        Publish RoletneMalaSobaWC/statePosition,0
     endif
endon

Picture

erokoder commented 6 years ago

@TD-er @Grovkillen @giig1967g @Oxyandy Please set log in spoiler. I can find it. TD or other admin. In log you can see correct behavior. But when include Delay, after few times, Mqtt lost, and that repeats every few time.

TD-er commented 6 years ago

@radebebek Tomorrow I have more time to look at this. What do you mean by "set log in spoiler" ?

erokoder commented 6 years ago

@TD-er Spoiler for hide text. Similarly to the forum site but it looks like there is no such possibility.

giig1967g commented 6 years ago

Hi @radebebek I can confirm that setting a delay of 10 seconds the UNIT disconnects from MQTT for me too. I am using shorter tdelays (500ms) and it works fine. Maybe a timeout?

A workaround could be to set a timer instead of a such long delay.

erokoder commented 6 years ago

I also try workaround decision and working withour problems for now. I'll test for a couple of days to confirm. So Action Delay definitely has a problem. @giig1967g also confirm. So @TD-er We have a cause problem, now it just needs to be fix for the rest of the community.

on Import#moving=0 do 
        gpio,12,1
        timerSet,1,10
endon

on Import#moving=1 do 
        gpio,5,1
        timerSet,2,10
endon

on Rules#Timer=1 do 
        gpio,12,0
        Publish SonoffDual/currentPosition,[Import#target]
        Publish SonoffDual/statePosition,2
endon

on Rules#Timer=2 do
        gpio,5,0
        Publish SonoffDual/currentPosition,[Import#target]
        Publish SonoffDual/statePosition,2
endon
Grovkillen commented 5 years ago

Is this still an issue? If so open.