UDP and MQTT but with different Intervals?
Moderators: grovkillen, Stuntteam, TD-er
UDP and MQTT but with different Intervals?
I have a ESP8266NodeMCU happily reading a voltage from an ADS1115 ADC
I send %value% to a UDP Controller and then out on the local LAN. I display the result in a Node Red dashboard
I'd like to send this value as frequently as possible so Ive set the Device message interval to 1 second.
So far so good
I'd also like to send the same %value% to a public MQTT broker but I only every 10 minutes
I can send %value% to both ESPEASY controllers but I cant figure out a way to get the controllers to send out/publish at different intervals.
Is there a way to do this ?
Is there a way for the "Publish" command to specify a specific controller so I could do it in a Rule ?
BTW - I can (sort of) send data from the 2 controllers at different intervals but only by creating 2 identical devices (one for each controller)
The first device sends to the UDP controller every 1 sec delay and the other one publishes to MQTT every 3600 seconds
Not very elegant !
Hope this makes sense - any guidance appreciated
I send %value% to a UDP Controller and then out on the local LAN. I display the result in a Node Red dashboard
I'd like to send this value as frequently as possible so Ive set the Device message interval to 1 second.
So far so good
I'd also like to send the same %value% to a public MQTT broker but I only every 10 minutes
I can send %value% to both ESPEASY controllers but I cant figure out a way to get the controllers to send out/publish at different intervals.
Is there a way to do this ?
Is there a way for the "Publish" command to specify a specific controller so I could do it in a Rule ?
BTW - I can (sort of) send data from the 2 controllers at different intervals but only by creating 2 identical devices (one for each controller)
The first device sends to the UDP controller every 1 sec delay and the other one publishes to MQTT every 3600 seconds
Not very elegant !
Hope this makes sense - any guidance appreciated
Re: UDP and MQTT but with different Intervals?
The simplest way to achieve this would be to start a looptimer on the MQTT#Connected event set to 600 seconds (10 min.) that uses the publish command:
Edit: Added the timer event handler.
Code: Select all
on mqtt#connected do
LoopTimerSet,1,600
asyncevent,sendvaluestomqtt
endon
on sendvaluesmqtt do
Publish,topic/to/send/value,[task#value]
endon
// Code provided by jgrad:
On Rules#Timer=1 do
asyncevent,sendvaluestomqtt
endon
Last edited by Ath on 24 Feb 2021, 20:27, edited 1 time in total.
/Ton (PayPal.me)
Re: UDP and MQTT but with different Intervals?
what about solution to (under Devices) define 2 device tasks, both connected to same ADS HW, but each with different interval and sending data to different controller?
above proposal with rules send values only once - I think there is missing code to send data everytime looptimer1 generate event
above proposal with rules send values only once - I think there is missing code to send data everytime looptimer1 generate event
Code: Select all
On Rules#Timer=1 do
asyncevent,sendvaluestomqtt
endon
Re: UDP and MQTT but with different Intervals?
Ah, yes, I got interrupted while typing that up from the tablet. Good call.
Edit: I updated the script with the timer event handler.
Edit: I updated the script with the timer event handler.
/Ton (PayPal.me)
Re: UDP and MQTT but with different Intervals?
Ath & jgrad
I tried using Publish on a timer in Rules but the problem I had was that the Publish command only appears to work if the MQTT controller is enabled.
If the MQTT controller is enabled it sends values at a frequency determined by "Interval" in Devices.
ie Interval setting in Devices effectively overrides Publish/Timer in Rules
Catch 22 ?
Thanks for helping
I tried using Publish on a timer in Rules but the problem I had was that the Publish command only appears to work if the MQTT controller is enabled.
If the MQTT controller is enabled it sends values at a frequency determined by "Interval" in Devices.
ie Interval setting in Devices effectively overrides Publish/Timer in Rules
Catch 22 ?
Thanks for helping
Re: UDP and MQTT but with different Intervals?
You should disable the MQTT Controller from the Task configuration (Devices tab), but leave the Controller itself enabled (Controllers tab), then it should not send out via MQTT.
/Ton (PayPal.me)
Re: UDP and MQTT but with different Intervals?
OK I couldn't resist a quick test before updating the Rules
Your suggested configuration does stop MQTT being sent out but it seems that the Publish command is disabled also
To test Publish I typed "Publish #,#" into the Command box in Tools Tab
With the MQTT Controller Enabled and Devices, Send to controller #1 (The MQTT controller) disabled I do not get MQTT message out
With the MQTT Controller Enabled and Devices, Send to controller #1 (The MQTT controller) enabled I do get a MQTT message out
Time for bed and hope I can get my head around this tomorrow.
Thanks once again for taking the time to help
Re: UDP and MQTT but with different Intervals?
The Publish command sends out to the first enabled MQTT Controller, independent of any 'Send to Controller' checkbox on the Devices pages.
/Ton (PayPal.me)
Re: UDP and MQTT but with different Intervals?
Are you sure ?
Unfortunately mine doesn't.
I've tried again with a very simple setup with only 1 device but Publish only sends out a message when the MQTT controller is selected in Devices/Tasks/Send to Controller
Even with your kind assistance I dont seem to be able make this work so I think I will have to abandon and opt for 2 Tasks per Device
(1 sending MQTT and 1 sending UDP at different intervals)
Thanks again
Re: UDP and MQTT but with different Intervals?
Can you show screenshots of the Controller page for your MQTT controller, and the Device page for your task?
The Publish command is not specific to a task, but you send a value to a MQTT topic, recognized by the receiver.
Please also show the rules/command you used to test this so far.
The Publish command is not specific to a task, but you send a value to a MQTT topic, recognized by the receiver.
Please also show the rules/command you used to test this so far.
/Ton (PayPal.me)
Re: UDP and MQTT but with different Intervals?
I really appreciate you sticking with me on this.
Hope the screenshots are adequate.
For obvious security reasons I've scrubbed out (?????) the first part of my Publish and Subscribe Topic on the screenshots
On my MQTT client I subscribe to ?????/#
The behaviour is exactly as I said earlier.
When I type (in the ESPEASY Tools command box)
Publish #,#
I do not get a message on the Hive public MQTT broker unless Controller 1 is ticked in the Device (Task 1) Data Acquisition tab
I have cleared any rules I set in order to simplify the test
Hope the screenshots are adequate.
For obvious security reasons I've scrubbed out (?????) the first part of my Publish and Subscribe Topic on the screenshots
On my MQTT client I subscribe to ?????/#
The behaviour is exactly as I said earlier.
When I type (in the ESPEASY Tools command box)
Publish #,#
I do not get a message on the Hive public MQTT broker unless Controller 1 is ticked in the Device (Task 1) Data Acquisition tab
I have cleared any rules I set in order to simplify the test
- Attachments
-
- Controllers.png (45.07 KiB) Viewed 8075 times
-
- Controller 1 top.png (53.67 KiB) Viewed 8075 times
-
- Device 1 top.png (33.44 KiB) Viewed 8075 times
-
- Command.png (24.63 KiB) Viewed 8075 times
-
- Device 1.png (34.4 KiB) Viewed 8075 times
-
- Devices.png (94.01 KiB) Viewed 8075 times
-
- Controller 1 bottom.png (80.09 KiB) Viewed 8075 times
Re: UDP and MQTT but with different Intervals?
I'm not sure if you should use the loop timer, or maybe act on the event sent when a new value is being read.
N.B. Both use cases may be valid, but you may need to know their differences.
A task set to run at interval N may not always run exactly at interval N, but it may take slightly longer to get rescheduled.
This depends on the plugin used for that task (e.g. BME280 is known to drift, still have to look into that)
The loop timer however does loop with a very constant interval. It may start slightly late on a loop, but the rescheduled one is based on the last scheduled time so (almost) no drift.
If you collect the data based on the loop timer, then this timer will collect the latest sample and process it at a constant interval.
But this may not be the N'th sample.
So it depends on the use case which approach is best.
N.B. you can also call a taskrun command from the loop timer to execute a task and thus send data to the connected controller on a given interval.
There is also a number of alternative ways to achieve a decimation of the number of messages.
You could add a dummy task in which you copy your values and the call "taskrun" on that dummy task.
Any connected values of that dummy task will then be sent to the connected controller.
By keeping track of a timer in the rules (see variables in rules) you can decimate when to copy what values to the dummy task and call taskrun on it.
N.B. this way you can share a single dummy task for a number of values to collect and send as the values are kept in the prepared messages queued in the controller queue.
Another way (less elegant and a bit tricky to use on multiple tasks) is to set the minimal send interval of a controller.
If you only need to send values from a single task, this may be the simplest way to handle this.
Just set the minimal send interval to 10000 msec and "delete oldest" for when the queue is full.
Maybe also set the queue length to 1 and no retries.
N.B. Both use cases may be valid, but you may need to know their differences.
A task set to run at interval N may not always run exactly at interval N, but it may take slightly longer to get rescheduled.
This depends on the plugin used for that task (e.g. BME280 is known to drift, still have to look into that)
The loop timer however does loop with a very constant interval. It may start slightly late on a loop, but the rescheduled one is based on the last scheduled time so (almost) no drift.
If you collect the data based on the loop timer, then this timer will collect the latest sample and process it at a constant interval.
But this may not be the N'th sample.
So it depends on the use case which approach is best.
N.B. you can also call a taskrun command from the loop timer to execute a task and thus send data to the connected controller on a given interval.
There is also a number of alternative ways to achieve a decimation of the number of messages.
You could add a dummy task in which you copy your values and the call "taskrun" on that dummy task.
Any connected values of that dummy task will then be sent to the connected controller.
By keeping track of a timer in the rules (see variables in rules) you can decimate when to copy what values to the dummy task and call taskrun on it.
N.B. this way you can share a single dummy task for a number of values to collect and send as the values are kept in the prepared messages queued in the controller queue.
Another way (less elegant and a bit tricky to use on multiple tasks) is to set the minimal send interval of a controller.
If you only need to send values from a single task, this may be the simplest way to handle this.
Just set the minimal send interval to 10000 msec and "delete oldest" for when the queue is full.
Maybe also set the queue length to 1 and no retries.
Re: UDP and MQTT but with different Intervals?
I'm not sure what the Publish #,# is supposed to do, but AFAIK, the # is the wildcard used by MQTT for subscribing to topics. Don't know what it does when sending.
My example used a more explicit publish,topic/name/value,[task#value] so in your case that could be:
My example used a more explicit publish,topic/name/value,[task#value] so in your case that could be:
Code: Select all
publish,electrical.batteries.house.voltage,[electrical.batteries.house#voltage]
/Ton (PayPal.me)
Re: UDP and MQTT but with different Intervals?
According to the MQTT specifications, you can only use topic wildcards in a subscribe.
Not in a publish.
Not in a publish.
Re: UDP and MQTT but with different Intervals?
Thanks guys - I'll be more specific re: Publish <topic>,<value>
Dont know where I picked up Publish #,#
Edit: SUCCESS
Im publishing now
Now to play with Timer Rules
You guys have been wonderful - Thanks a mill
Dont know where I picked up Publish #,#
Edit: SUCCESS
Im publishing now
Now to play with Timer Rules
You guys have been wonderful - Thanks a mill
Re: UDP and MQTT but with different Intervals?
Maybe also nice to read a bit more on the loop timers here: https://espeasy.readthedocs.io/en/lates ... oop-timers
Re: UDP and MQTT but with different Intervals?
Reading Now thanksTD-er wrote: ↑25 Feb 2021, 20:23 Maybe also nice to read a bit more on the loop timers here: https://espeasy.readthedocs.io/en/lates ... oop-timers
Who is online
Users browsing this forum: No registered users and 13 guests