Problem with a rule for MQ-7 Gas sensor

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
tparvais
Normal user
Posts: 99
Joined: 28 Oct 2015, 23:13

Problem with a rule for MQ-7 Gas sensor

#1 Post by tparvais » 31 Mar 2020, 09:11

[I moved my question from viewtopic.php?f=4&t=7328 here, as problem is not directly related to MQ-7]

Hello

I implemented same MQ-7 for CO detection.

I've set a rule for managing heating/measurements/calibration

The idea is to be able to launch the calibration during 48 when pressing the button GPIO4 or to stop it by pressing again.
I use a dummy variable "Calibration_MQ7" that is 1 if calibration is on, and 0 if off...

By pressing the push switch, I shgall inverese the state of this variable

I shall be stupid because it does not work... :-(

( the others timers for heating/measuring are ok)

any idea ?


Thank you

Thomas

Code: Select all

on System#Boot do
  timerSet,1,5
  taskvalueset 8,1,0 // état calibration à 0
endon

on [MQ7_Calibration_Start-Stop#etat]=1 do //switch pressed
  if [Calibration_MQ7#etat]=1
    TaskValueSet 8,1,0 // inverse state + stop calibration
    gpio,13,0
    timerSet,4,0
  else
    TaskValueSet 8,1,1 // inverse state + start calibration
    gpio,13,1 //power on heating
    timerSet,2,0
    timerSet,3,0
    timerSet,4,172800  // Calibrate 48h
    gpio,13,0 //stop heating
  endif
endon

on Rules#Timer=1 do 
 gpio,13,1
 timerSet,2,60
endon

on Rules#Timer=2 do 
 gpio,13,0 
 timerSet,3,45  
endon

on Rules#Timer=3 do 
 TaskValueSet 7,1, [Mesure_MQ7_CO#Analog] 
 timerSet,1,45 
endon
Here are my tasks :

Image

and how I configure the switch to launch calibration (this is a push button, normally closed, between GND & GPIO4):

Image

GravityRZ
Normal user
Posts: 206
Joined: 23 Dec 2019, 21:24

Re: Problem with a rule for MQ-7 Gas sensor

#2 Post by GravityRZ » 01 Apr 2020, 14:43

is the problem not that you do a check on an ON statement

i am not an experienced ESPEasy rules guru bu can you try

Code: Select all

on MQ7_Calibration_Start-Stop#etat do //switch pressed
TaskValueSet 8,1,[MQ7_Calibration_Start-Stop#etat] set switch pressed setting to Calibration_MQ7#etat
  if [Calibration_MQ7#etat]=1

tparvais
Normal user
Posts: 99
Joined: 28 Oct 2015, 23:13

Re: Problem with a rule for MQ-7 Gas sensor

#3 Post by tparvais » 02 Apr 2020, 20:13

Hi

It does not work.

I simplified it as with the follwoing code, when pressing the button, Q7_Calibration_Start-Stop#etat is inverted properly each time

My problem is that it does not execute the IF test if [MQ7_Calibration_Start-Stop#etat]=0

Code: Select all

on System#Boot do
  timerSet,1,5 // wait 5s then start
  taskvalueset 9,1,0 // état calibration à 0
endon

on [MQ7_Calibration_Start-Stop#etat] do //switch pressed
  if [MQ7_Calibration_Start-Stop#etat]=0
      gpio,13,0 // stop calibration
      timerSet,1,1 // wait 1s then restart normal cycle
  else
    gpio,13,1 //power on heating to calibrate
    timerSet,3,0 // stop timer 3
    timerSet,1,0 // stoptimer 1
    timerSet,2,20  // Calibrate 20s
  endif
endon

on Rules#Timer=1 do 
 gpio,13,1 //heat before measure
 timerSet,2,5
endon

on Rules#Timer=2 do 
 gpio,13,0 // stop heating before measure
 timerSet,3,5  
endon

on Rules#Timer=3 do 
 TaskValueSet 7,1, [Mesure_MQ7_CO#Analog] 
 timerSet,1,1 //go back to begining
endon

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Problem with a rule for MQ-7 Gas sensor

#4 Post by Domosapiens » 02 Apr 2020, 20:24

[MQ7_Calibration_Start-Stop#etat]=0
the name contains the "-" minus sign.
I can imagine that ...

Try using the "_" underscore instead, in Task and in the rule ??
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

tparvais
Normal user
Posts: 99
Joined: 28 Oct 2015, 23:13

Re: Problem with a rule for MQ-7 Gas sensor

#5 Post by tparvais » 02 Apr 2020, 22:14

Hi

good idea, I changed - by _
no effect

when I press the push-switch, the state ofMQ7_Calibration_Start_Stop changes properly in task/device view.

Is there a way to debug ?

I add a tasksetvalue in #8 to a dummy variable as output to check if the IF condition is executed (or ELSE). nada.

I shorten the variable length. nada

Code: Select all

on System#Boot do
  timerSet,1,5 // wait 5s then start
  taskvalueset 9,1,0 // état calibration à 0
taskvalueset 8,1,0 //for debugging
endon

on [MQ7#etat]=0 do //switch pressed
      gpio,13,0 // stop calibration
      taskvalueset 8,1,0
      timerSet,1,1 // wait 1s then restart normal cycle
endon

on [MQ7#etat]=1 do //switch pressed
    taskvalueset 8,1,99
    gpio,13,1 //power on heating to calibrate
    timerSet,3,0 // stop timer 3
    timerSet,1,0 // stoptimer 1
    timerSet,2,60  // Calibrate 48h
endon

on Rules#Timer=1 do 
 gpio,13,1 //heat before measure
taskvalueset 8,1,1
 timerSet,2,5
endon

on Rules#Timer=2 do 
 gpio,13,0 // stop heating before measure
taskvalueset 8,1,2
 timerSet,3,5  
endon

on Rules#Timer=3 do 
 TaskValueSet 7,1, [Mesure_MQ7_CO#Analog] 
taskvalueset 8,1,3
 timerSet,1,5 //go back to begining
endon


tparvais
Normal user
Posts: 99
Joined: 28 Oct 2015, 23:13

Re: Problem with a rule for MQ-7 Gas sensor

#6 Post by tparvais » 02 Apr 2020, 22:36

I found it myself:
there is no need to use [] in on .... do statement...

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Problem with a rule for MQ-7 Gas sensor

#7 Post by grovkillen » 03 Apr 2020, 05:42

tparvais wrote: 02 Apr 2020, 22:36 I found it myself:
there is no need to use [] in on .... do statement...
The brackets turn the name into a value.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

tparvais
Normal user
Posts: 99
Joined: 28 Oct 2015, 23:13

Re: Problem with a rule for MQ-7 Gas sensor

#8 Post by tparvais » 03 Apr 2020, 11:17

grovkillen wrote: 03 Apr 2020, 05:42 The brackets turn the name into a value.
Worthwhile to add it to the doc :)

btw, is that possible to put a text in a dummy variable/task ? or is this only numbers ?

Thank you

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Problem with a rule for MQ-7 Gas sensor

#9 Post by TD-er » 03 Apr 2020, 11:37

Right now we don't have the option to use strings as values.
The support for strings is very preliminary and it is not yet possible to store them in variables or in Dummy plugin.

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Problem with a rule for MQ-7 Gas sensor

#10 Post by grovkillen » 03 Apr 2020, 12:19

tparvais wrote: 03 Apr 2020, 11:17
grovkillen wrote: 03 Apr 2020, 05:42 The brackets turn the name into a value.
Worthwhile to add it to the doc :)
Isn't it already part of the rules examples?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

GravityRZ
Normal user
Posts: 206
Joined: 23 Dec 2019, 21:24

Re: Problem with a rule for MQ-7 Gas sensor

#11 Post by GravityRZ » 03 Apr 2020, 13:29

tparvais wrote: 02 Apr 2020, 22:36 I found it myself:
there is no need to use [] in on .... do statement...
or you could have read my advice in which i told you to remove the []

tparvais
Normal user
Posts: 99
Joined: 28 Oct 2015, 23:13

Re: Problem with a rule for MQ-7 Gas sensor

#12 Post by tparvais » 03 Apr 2020, 13:59

GravityRZ wrote: 03 Apr 2020, 13:29
tparvais wrote: 02 Apr 2020, 22:36 I found it myself:
there is no need to use [] in on .... do statement...
or you could have read my advice in which i told you to remove the []
you're right, I read your message 5 times, but I didn't noticed the [] removal

Need to change my glasses

so thank you !

GravityRZ
Normal user
Posts: 206
Joined: 23 Dec 2019, 21:24

Re: Problem with a rule for MQ-7 Gas sensor

#13 Post by GravityRZ » 03 Apr 2020, 14:07

no problem.
next time i will mention what i changed :-)

Post Reply

Who is online

Users browsing this forum: No registered users and 23 guests