ESP8266 (sonoff basic) and PCF8574 reboot problem

Moderators: Voyager, BertB, rtenklooster, Stuntteam, grovkillen, TD-er

Post Reply
Message
Author
dilpish
Normal user
Posts: 2
Joined: 13 Feb 2019, 21:29

ESP8266 (sonoff basic) and PCF8574 reboot problem

#1 Post by dilpish » 13 Feb 2019, 22:08

hello :) may be someone can help me

ver: mega-20190202

1) Sonoff and PCF8574 are connected via i2c
2) Three buttons are connected to PCF8574 (1,2,3 inputs) and 3 LEDs (4,5,6 inputs through 100 kOhm resistor)
3) It is also connected via i2c to oled for diagnostics, BH1750 as a working sensor
4) dht-11 is connected to gpio-14

In normal mode, everything works.

But, if you press a button (any connected to PCF8574) more than 2 times per second, or just all three buttons at the same time, the sonoff goes into reboot.

Image

Rules:

Code: Select all

on PCF8574_1#switch do
 if [PCF8574_1#switch]=1 
  if [led#led_01]=0
   TaskValueSet,4,1,1
   TaskRun,4
  else
   TaskValueSet,4,1,0
   TaskRun,4
 endif
endon 

on PCF8574_2#switch do
 if [PCF8574_2#switch]=1 
  if [led#led_02]=0
   TaskValueSet,4,2,1
   TaskRun,4
  else
   TaskValueSet,4,2,0
   TaskRun,4
 endif
endon 

on PCF8574_3#switch do
 if [PCF8574_3#switch]=1 
  if [led#led_03]=0
   TaskValueSet,4,3,1
   TaskRun,4
  else
   TaskValueSet,4,3,0
   TaskRun,4
 endif
endon 


on led#led_01 do
 if [led#led_01]=0
   PCFGPIO,5,0
   OLED,4,1,###
  else
   PCFGPIO,5,1
   OLEDCMD,on
   OLED,4,1,___
 endif
endon

on led#led_02 do
 if [led#led_02]=0
   PCFGPIO,6,0
   OLED,4,5,###
  else
   PCFGPIO,6,1
   OLEDCMD,on
   OLED,4,5,___
 endif
endon

on led#led_03 do
 if [led#led_03]=0
   PCFGPIO,7,0
   OLED,4,10,###
  else
   PCFGPIO,7,1
   OLEDCMD,on
   OLED,4,10,___
 endif
endon
Weblog part with reboot when clicking :)

Code: Select all

345558: Lev.1: [else]=false
345578: EVENT: led#led_03=0.00 Processing time:137 milliSeconds
345581: EVENT: led#=0.00
345632: EVENT: led#=0.00 Processing time:51 milliSeconds
345640: Lev.2: [else]=false
345684: EVENT: PCF8574_1#Switch=1.00 Processing time:658 milliSeconds
345942: PCF : Port=1 State=0 Output value=0
345946: EVENT: PCF8574_1#Switch=0.00
345958: Lev.1: [if 0=1]=false
346066: EVENT: PCF8574_1#Switch=0.00 Processing time:121 milliSeconds
>> NetworkError when attempting to fetch resource. <<
8581: PCF : Port=1 State=1 Doubleclick=3
8584: EVENT: PCF8574_1#Switch=3.00
8597: Lev.1: [if 3=1]=false
8666: EVENT: PCF8574_1#Switch=3.00 Processing time:82 milliSeconds
8777: PCF : Port=1 State=0 Output value=0
8780: EVENT: PCF8574_1#Switch=0.00
8792: Lev.1: [if 0=1]=false

dilpish
Normal user
Posts: 2
Joined: 13 Feb 2019, 21:29

Re: ESP8266 (sonoff basic) and PCF8574 reboot problem

#2 Post by dilpish » 17 Feb 2019, 22:14

OK, I solved the problem.

TaskRun takes a very long time and apparently the stack. I replaced it with an event. Here such code works for 300 ms.

Code: Select all

on PCF8574_1#switch do
 if [PCF8574_1#switch]=1 
  if [led#led_01]=0
   TaskValueSet,4,1,1
   event led#led_01
  else
   TaskValueSet,4,1,0
   event led#led_01
  endif
 endif
endon 

on led#led_01 do
 if [led#led_01]=0
   PCFGPIO,5,0
   OLED,4,1,###
  else
   PCFGPIO,5,1
   OLEDCMD,on
   OLED,4,1,___
 endif
endon

Code: Select all

1299971: Command: taskvalueset
1299971: TaskValueSet,4,1,0
1299975: ACT : event led#led_01
1299983: Command: event
1299983: event led#led_01
1299984: EVENT: led#led_01
1300038: Lev.1: [if 0=0]=true
1300040: ACT : PCFGPIO,5,0
1300043: PCF : GPIO OUTPUT 5 Set to 0
1300046: Lev.1: [else]=false
1300065: UDP : DC:4F:22:CB:47:3C,192.168.1.105,10
1300075: EVENT: led#led_01 Processing time:91 milliSeconds
1300116: EVENT: PCF8574_1#Switch=1.00 Processing time:201 milliSeconds
1300127: PCF :SafeButton 1st click.
1300225: PCF : Port=1 State=0 Output value=0
1300228: EVENT: PCF8574_1#Switch=0.00
1300244: Lev.1: [if 0=1]=false
1300319: EVENT: PCF8574_1#Switch=0.00 Processing time:91 milliSeconds
As a result, the system is not overloaded on the push-button DDoS attack :). Probably I should handle everything on the first event, but I am planning a complex handler.

ps: I think it's worth writing to the wiki that the event is preferable to ThaskRun.

the next question is how to handle LongClick event, without handeling click event when LongClick is :)

For example - LongClick:

Code: Select all

1612674: ACT : event led#led_01
1612682: Command: event
1612683: event led#led_01
1612683: EVENT: led#led_01
1612740: Lev.1: [if 0=0]=true
1612742: ACT : PCFGPIO,5,0
1612745: PCF : GPIO OUTPUT 5 Set to 0
1612747: Lev.1: [else]=false
1612770: EVENT: led#led_01 Processing time:87 milliSeconds
1612812: EVENT: PCF8574_1#Switch=1.00 Processing time:197 milliSeconds
1613612: PCF : LongPress: Port= 1 State=1 Output value=11
1613616: EVENT: PCF8574_1#Switch=11.00
1613628: Lev.1: [if 11=1]=false
1613701: EVENT: PCF8574_1#Switch=11.00 Processing time:85 milliSeconds
1614213: PCF :SafeButton 1st click.
1614312: PCF : Port=1 State=0 Output value=0
1614315: EVENT: PCF8574_1#Switch=0.00
1614330: Lev.1: [if 0=1]=false
1614403: EVENT: PCF8574_1#Switch=0.00 Processing time:88 milliSeconds

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 0 guests