Just get me the last value!

Updated for version 2.3 – mqttcogs_get shortcode is deprecated and replaced with the mqttcogs_drawhtml shortcode

There are instances where a graph might not be appropriate. I might simply want to display the current temperature outside. I don’t want any fancy formatting I simply want to embed the value in one of my posts. Which value though? The temperature is only meaningful if you know the date and time at which the reading was taken.

It is possible to display both using the [ mqttcogs_drawhtml ] shortcode. In it’s most basic form it will return the most recent datetime or payload field. Here’s the code to display the text above:

[ mqttcogs_drawhtml topics='mysensors_out/92/2/1/0/0'] Last known temperature reading is {0,1}C  taken at {0,0}[/mqttcogs_drawhtml]

So my {0,1} corresponds to row 0, column 1 (19.6) and {0,0} to row 0, column 0 (2020-03-20 12:21:11)

How about MIN/MAX for today?

Technically this should work but for some reason it currently isn’t. I’m looking into now. I tried the following but the date isn’t formatted correctly. Watch this space…

[ mqttcogs_drawhtml topics='mysensors_out/92/2/1/0/0,mysensors_out/92/2/1/0/0' group='DAY' aggregations='MIN,MAX' ] Min Temperature today was {0,1}C  taken at {0,0}
 Max Temperature today was {1,2}C  taken at {1,0}[/mqttcogs_drawhtml]

What about other days?

It’s also possible to specify a ‘from’ and ‘to’ attribute and a sort attribute. This would allow you to get the start and end temperature for a given date range. I’m not sure why you might want to do this!


Hi, really happy to stumble across your plugin MQTTCogs and am trying very hard to get it running.. but no success yet.

My Setup;
MQTT Broker installed and running and in use by other applications.
WP (Latest version) up and running in my little data center
MQTTCogs installed and accessible in the WP control panel

Test setup;
Sensor sending temperature ‘AmperageApps/0008/Temperature (c)’
Broker shows AmperageApps/0008/Temperature (c) 27.5 (works)

WordPress shortcode;
Temperature Testing [mqttcogs_get topic='AmperageApps/0008/Temperature (c)']

Temperature Testing

Is there any logging or files to view behind the scenes to help int he troubleshooting? I am not even sure if it is connecting and would like to find the most basic troubleshooting steps.

Thanks for any assistance!

This is a summary of the steps we went through to diagnose this issue:

Enable wordpress debugging – see wp_config.php

define(‘WP_DEBUG’, true);
define(‘WP_DEBUG_LOG’, true);

Then find this line a little down to see where the log is written to.
@ini_set(‘error_log’,’/home/somepathhere/php-errors.log’); // path to server-writable log file

The log above showed a connection timeout.

I would suggest that if the connection is timing out then the commercial host is blocking outgoing port 1883. My host does this as well.

I suggest asking their support which ports are open by default. Normally ones used for http/https and also mail servers will be open as well as some others. If you are lucky they will open the port for you. In my case, they wouldn’t, so I set up a port mapping on another machine.

Leave a Reply

Your email address will not be published. Required fields are marked *