generate pulse by mqtt

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
garvarma
Normal user
Posts: 19
Joined: 15 Jul 2016, 13:11

generate pulse by mqtt

#1 Post by garvarma » 15 Jul 2016, 13:28

Hello,

First of all thanks to everyone for help.

i have a wemos D1 mini device with EspEasy firmware.

Now i want to send a pulse about 5000 ms by mqtt, but i dunno how to do it. I know that by http is posible with this instruction:

http://[IP_device]/control?cmd=pulse,0,0,5000

That for 5 seconds GPIO 0 turn on (i send 0 because a have a relay that works with inverse logic) in logs of esp, only i saw this:

GPIO 0 Pulsed for 5000 mS

Anyone knows how to translate and send this instruction by mqtt?

thanks

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: generate pulse by mqtt

#2 Post by tozett » 15 Jul 2016, 16:26

May use rules for Timer? Look rules up on the Wiki ...?!

Martinus

Re: generate pulse by mqtt

#3 Post by Martinus » 15 Jul 2016, 17:18

You can send the entire command as payload to ../cmd topic.

So if your template is

/%sysname%/#

and your system name is

espdemo

you should send payload

pulse,0,0,5000

to topic

/espdemo/cmd

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: generate pulse by mqtt

#4 Post by tozett » 15 Jul 2016, 21:48

coool, should go into wiki ...
:)

garvarma
Normal user
Posts: 19
Joined: 15 Jul 2016, 13:11

Re: generate pulse by mqtt

#5 Post by garvarma » 17 Jul 2016, 22:26

Hello to everyone,

Thanks for help.

Sorry tozett, but wiki have many pages, so maybe you can attach the rules for timer where it says this? because i don't see it. I red wiki about EasyESP and i didn't find this page.

Martinus, thanks for help, i did it and worked perfect. If you know where is link of wiki where explain this, i think i will be happy and tozett too:).

thanks to every one.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: generate pulse by mqtt

#6 Post by tozett » 18 Jul 2016, 08:01

timer are mentioned/explained in the RULES-section here:
http://www.esp8266.nu/index.php/Tutorial_Rules#Timer

does this help?

garvarma
Normal user
Posts: 19
Joined: 15 Jul 2016, 13:11

Re: generate pulse by mqtt

#7 Post by garvarma » 19 Jul 2016, 06:01

Hi tozett,

Perfect with this link.

Really, in the wiki is too difficult to find this link, because in main page, table content doesn't appear, and in other sub-pages also i didn't find it.

I read about rules and maybe it's good for about one thing that i want to use it.

Please do you know if in wiki exist a link, about "device page" : http://www.esp8266.nu/index.php/ESPEasy, more extensive?, because i created a counter in my device, and i wanted to share this variable or value to mqtt.
Other thing, and thanks to your link, maybe is doing a rule for this.

thanks

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: generate pulse by mqtt

#8 Post by tozett » 19 Jul 2016, 07:07

did not fully understand what variable you have, and where,
but you can send values to mqtt with rules.
use cmd: "Publish" fully explained here:
http://www.esp8266.nu/index.php/Tutoria ... nd_Publish

i do this too, its working.. ;)

garvarma
Normal user
Posts: 19
Joined: 15 Jul 2016, 13:11

Re: generate pulse by mqtt

#9 Post by garvarma » 20 Jul 2016, 22:28

Hi tozett,

I was reading Rules#Timer on wiki, and about part of publish i have a doubt/problem and as you can see in wiki this part is not completed.

Well i follow the example at the end of chapter Rules#Timer where explain to create a rule for a led that after 10 sec led is switched on, etc. This works well.

A part of this, i create in menu device a counter, that says how many times led is switched on
Img_devices.JPG
Img_devices.JPG (45.9 KiB) Viewed 13816 times
Inside task 1 in device menu, you can see 2 values or variables (Count, Total)
Img_devices2.JPG
Img_devices2.JPG (47.67 KiB) Viewed 13816 times
Well, by rules, i want to publish these 2 values or variables to mqtt. As i told you, i follow wiki, but doesn't work as i want. By rules, i would like to publish by rules this:
/nodemcu/prueba/Count, (content_of variable_Count) and
/nodemcu/prueba/Total, (content_of variable_Total)

But i dunno, how to obtain the content of variable Total. So i try to do it by constant like:
Publish /%sysname%/%tskname%/%valname2%,5
rules.JPG
rules.JPG (28 KiB) Viewed 13816 times
But when i see topic in mqtt, i see this:
mqtt.JPG
mqtt.JPG (15.98 KiB) Viewed 13816 times
so not correspond with /nodemcu/prueba/Total payload:

do you know where i mistake please?

really thinks about your help

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: generate pulse by mqtt

#10 Post by tozett » 20 Jul 2016, 23:06

after a very quick look at your post, my (working) example of a mqtt-publish:

Code: Select all

// ** MQTT use additional topic for node-red **
     publish ESP/01/Haustuer/Key/[rfid#tag]
so in your case, i think you should publish (with leading slash! or without!) something like:

Code: Select all

publish /YOURTOPICTEXT/[PAYLOAD-is-DEVICEname-and#VALUEname]
what looks like (as one publish-task for each, maybe?):

Code: Select all

/nodemcu/[prueba#Count]

Code: Select all

/nodemcu/[prueba#Total]
may give this a try? (besides that: what is your (interesting) idea to generate a pulse and count it. what is your need?)

garvarma
Normal user
Posts: 19
Joined: 15 Jul 2016, 13:11

Re: generate pulse by mqtt

#11 Post by garvarma » 21 Jul 2016, 05:55

Hi tozett,

I tried this as you told me and didn't work with variable Count or Total. in mqtt i received value 0.00
rules2.JPG
rules2.JPG (31.33 KiB) Viewed 12893 times
mqtt2.JPG
mqtt2.JPG (36.23 KiB) Viewed 12893 times
The idea to generate a pulse counter of a GPIO concretely is because i want to control 1 rollershutter at home by 1 relay. The rollershutter only have 1 wire to control the UP and the DOWN.

When i give 220V to this wire, then rollershutter move to one side, if i take it from 220V, then stop, if i give again 220V, then turn to other side.
So the idea is to count how many time i switch on this GPIO, and then about even or odd number (counter) know which is the state of rollershutter if UP or Down, to then generate the oposite.

Do you understand me?

thanks

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: generate pulse by mqtt

#12 Post by tozett » 21 Jul 2016, 10:05

ok, thanks for explanation.

your rules look like you have a space in your topic before your [event#variable] statement..
you might check this..

how do you subscribe your topic? may try some other mqtt-client to test?
and may subscribe to "/topic/#" (general example, i.e. for you: "/nodemcu/#" ) and see for debugging what is all coming in as payload?

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: generate pulse by mqtt

#13 Post by tozett » 21 Jul 2016, 15:21


garvarma
Normal user
Posts: 19
Joined: 15 Jul 2016, 13:11

Re: generate pulse by mqtt

#14 Post by garvarma » 21 Jul 2016, 16:54

Hi,
how do you subscribe your topic? may try some other mqtt-client to test?
and may subscribe to "/topic/#" (general example, i.e. for you: "/nodemcu/#" ) and see for debugging what is all coming in as payload?
I use a software called mqtt-spy to subscribe to topic in PC and see payload. Always i subscribe to /nodemcu/#, just that i not send you this part in attached files
mqtt3.JPG
mqtt3.JPG (61.7 KiB) Viewed 12861 times
Yes, i need to see serial logs in nodemcu. Today i want try it.
Please check r113, possible Bug?
Hi, i was reading how to compile files and hope today or tomorrow try to compile R113 and upload it. Maybe, before i will try with R112, because now i have installed R110.

thanks again really.

tozett
Normal user
Posts: 734
Joined: 22 Dec 2015, 15:46
Location: Germany

Re: generate pulse by mqtt

#15 Post by tozett » 23 Jul 2016, 09:33

i tried to re-build you setting on my device. never played pulsecounter before.. :oops:

1) still on version r111...
i hat count and total at the same value. the error was, to left out the idx-value.
in your screenshot it is the same.

please give the idx-field a value and check,
if count and total now behave like expected.

garvarma
Normal user
Posts: 19
Joined: 15 Jul 2016, 13:11

Re: generate pulse by mqtt

#16 Post by garvarma » 23 Jul 2016, 23:54

Hi tozett,
1) still on version r111...
i hat count and total at the same value. the error was, to left out the idx-value.
in your screenshot it is the same.

please give the idx-field a value and check,
if count and total now behave like expected.
well sorry for delay, but i was doing some test with R113 and create a rule like this:

Code: Select all

On System#Boot do    
  gpio,2,0
  timerSet,1,10
  cont=0      
endon

On Rules#Timer=1 do  
  if [E1SW1#Switch]=1
     gpio,2,0
  else
     gpio,2,1
     cont=cont+1
     endif
but didn't worked, because i didn't know how to send by mqtt variable "cont".

Tonight i saw your reply, and i modify my device configuration adding IDX number as you said, and worked!
devices.jpg
devices.jpg (38.17 KiB) Viewed 12760 times
rules.JPG
rules.JPG (34.02 KiB) Viewed 12760 times
mqtt.JPG
mqtt.JPG (65.75 KiB) Viewed 12760 times
So thank you very much for all your help!

Just one doubt about code that i attached if in rule i create a variable like:

Code: Select all

On System#Boot do    
  gpio,2,0
  timerSet,1,10
  cont=0      
endon

On Rules#Timer=1 do  
  if [E1SW1#Switch]=1
     gpio,2,0
  else
     gpio,2,1
     cont=cont+1
  endif
There is any way to send this variable (cont) by mqtt? i was reading few websites and didn't say anything to send the content of variable by mqtt...

Well, i will continue reading if i find something, and really thanks very much!

Post Reply

Who is online

Users browsing this forum: No registered users and 66 guests