Hi there,
I want to log the temperatures of my central heating, so I installed two One-Wire-Sensors, one at the beginning of the loop, one at the end.
I'm using ESP-Easy Mega (git-build mega-20231013 / ESP_Easy_mega_20231013_collection_B_ESP8266_4M1M).
Values are sent to a MQTT broker running on an old Raspberry Pi
mosquitto/now 1.4.10-3+deb9u2
mosquitto-clients/now 1.4.10-3+deb9u2
Collecting the temperature values via ESP-Easy works fine, and logging them via mqtt on the RasPi works also.
What I am missing is a timestamp for the values.
Sounds like the easiest thing in the world, but I am running into dead ends whatever I try ...
Unfortunately, the mosquitto-client on the RasPi does not support output formatting (-F option is missing ...). So I tried to use awk on the RasPi, but it only runs mawk which does not support sprintf to format datetime ...
Also, the RasPi and the image it runs are quite old and struggle to update to newer package versions.
So here's the question: Is there an easy way to send formatted output to the mqtt broker in the first place?
In the Values section of the Devices-config, there is a Formula field, but it only seems to support arithmetic conversions, not the concatenation of system variables like %systime%.
I spent some time reading about rules, but I am not sure if this can be the solution to my problem.
Can anyone point me into the right direction?
Best Regards
Horst Brack
add timestamp to mqtt messages
Moderators: grovkillen, Stuntteam, TD-er
Re: add timestamp to mqtt messages
You may have missed the fun part of ESPEasy, Rules
That feature has to be enabled in Tools/Advanced settings (top checkbox). And documentation for that, it can be a bit overwhelming..., can be found here: https://espeasy.readthedocs.io/en/lates ... Rules.html
You can respond on an event for the temperature sensor (I named it DS1 here), like this:
That feature has to be enabled in Tools/Advanced settings (top checkbox). And documentation for that, it can be a bit overwhelming..., can be found here: https://espeasy.readthedocs.io/en/lates ... Rules.html
You can respond on an event for the temperature sensor (I named it DS1 here), like this:
Code: Select all
on DS1#temperature do
// Only send the time-stamp, the temperature data is handled by the Controller connected to the task
Publish,your/DS1/mqtt/timestamp/topic,"%lcltime%"
endon
/Ton (PayPal.me)
-
- New user
- Posts: 4
- Joined: 29 Nov 2023, 21:59
Re: add timestamp to mqtt messages
Thanks for your quick reply and your hint, Ath!
I'll dive into rules and try your solution
I'll dive into rules and try your solution
-
- New user
- Posts: 4
- Joined: 29 Nov 2023, 21:59
Re: add timestamp to mqtt messages
Tested it and it works, but ...
Now I get an additional message with the timestamp in my output, in other words alternating lines with timestamps and values.
That will do the job with a little postprocessing, but ideally I would like to have a single mqtt message for each measurement with a timestamp succeeded by the value.
Any ideas if and how that can be achieved?
Now I get an additional message with the timestamp in my output, in other words alternating lines with timestamps and values.
That will do the job with a little postprocessing, but ideally I would like to have a single mqtt message for each measurement with a timestamp succeeded by the value.
Any ideas if and how that can be achieved?
Re: add timestamp to mqtt messages
Hmm, AFAIK, MQTT is a single-content messaging system. If the server doesn't register the date/time of a received message, or you can't retrieve it, you're out of luck, I guess. Or we're talking about different things here...
/Ton (PayPal.me)
Re: add timestamp to mqtt messages
A MQTT message is just a string, so you can also create a combined message like this:
Code: Select all
on DS1#temperature do
// Only send the time-stamp, the temperature data is handled by the Controller connected to the task
Publish,your/DS1/mqtt/timestamp/topic,"%eventvalue%;%lcltime%"
endon
-
- New user
- Posts: 4
- Joined: 29 Nov 2023, 21:59
Re: add timestamp to mqtt messages
@Ath:
understood, I was looking for a way to concatenate timestamp and teperature value before it is written to the MQTT message primarily.
@TD-er:
Your example gets me exactly the output that I want, thanks!
What was still bothering me a bit was the fact that I then got 2 messages because I published the message under the same name as the sensor message.
But meanwhile I found out that you can define a new message in the rule, so now I have exactly what I want.
@Ath:
Your were right, rules are the fun part
Thanks so much for your help!
understood, I was looking for a way to concatenate timestamp and teperature value before it is written to the MQTT message primarily.
@TD-er:
Your example gets me exactly the output that I want, thanks!
What was still bothering me a bit was the fact that I then got 2 messages because I published the message under the same name as the sensor message.
But meanwhile I found out that you can define a new message in the rule, so now I have exactly what I want.
@Ath:
Your were right, rules are the fun part
Thanks so much for your help!
Who is online
Users browsing this forum: Ahrefs [Bot] and 31 guests