'Prod_env.ini' build help - simple mqtt payloads

I have just started to look at your code to build an IR blaster type device with 433MHz support. I am using a Wemos D1 mini style board and built a binary using the following in a prod_env.ini file.

 platform = ${com.esp8266_platform}
    board = nodemcuv2
    lib_deps =
    build_flags = 
    board_build.flash_mode = dout

To make it easier for me to integrate into openHAB, I wanted to use the simple publishing/receiving presuming I would just get a numerical “value” to publish to the mqtt broker and cause an IR pulse to be transmitted.

When I press my IR remote, I get two strings of data seen on the ‘/IRtoMQTT’ topic seen in the ‘mqtt.fx’ software. One is a string of numbers e.g. 12345678 and the other seems to be the JSON output {“value”:12345678, etc…etc…}.

To publish using openHAB as the control, I have setup some virtual switches that use a rule to publish the JSON path '{"value":12345678}'. This works but I thought I should just be able to publish 12345678 instead.
I noticed that the /SYStoMQTT topic is also in JSON format. Can I force all topics to report just their individual payloads rather than JSON outputs? I was hoping to set all configurations using the prod_env.ini file so I didn’t need to modify the ‘Github’ files every time there is an update to the code.

Also, instead of changing

#define TimeBetweenReadingSYS 120000 // time between system readings (like memory)

to 300000 for a 5 minute update, can I set:

'-DTimeBetweenReadingSYS=300000' in prod_env.ini instead?

For the moment you have to change it in user_config.h

But as you are the first to ask I will make it available through *.ini files.

The plan is to progressively migrate to json instead of the simple payloads but I can listen arguments if we need to conserve both.

For the moment you have to change it in user_config.h

But as you are the first to ask I will make it available through *.ini files.

Excellent, the code is in my .ini file but obviously it didn’t work at the moment.

WRT JSON, I have worked out how to break down the state and command mqtt topics so simple payload is not required.

I’ll look to post my openHAB .things .items and .rules as an example that others may find useful.

One thing that you may need to look at is the mqtt state /version. It sends version_tag. I presume it should say 0.9.3?

I use the text file approach with openHAB rather than PaperUI. This is what I have got working using JSON encoded mqtt messages. You need to have the JSONPATH transformation add-on and I use the EXPIRE binding to create openHAB switches that send the JSON payload as a String when selected ON using a rule. The EXPIRE binding then returns that switch back to OFF. I have setup four switches for four remote functions on my LG TV. I’ll probably make a .items and .rules for each remote I want to replicate.


Bridge mqtt:broker:mqtt-broker {
  Thing mqtt:topic:MQTT_GATEWAY "Open MQTT Gateway" @ "MQTT-IR" {
      Type string : GW_version  			[ stateTopic="home/OpenMQTTGateway_D1/version" ]
      Type string : GW_online  				[ stateTopic="home/OpenMQTTGateway_D1/LWT" ]
	  Type string : GW_IR_Rx  				[ stateTopic="home/OpenMQTTGateway_D1/IRtoMQTT" ]
	  Type string : GW_Sys  				[ stateTopic="home/OpenMQTTGateway_D1/SYStoMQTT" ]
	  Type string : GW_MQTT_IR 				[ commandTopic="home/OpenMQTTGateway_D1/commands/MQTTtoIR" ]	  


String		GW_version			"Gateway Version"					{ channel="mqtt:topic:MQTT_GATEWAY:GW_version" }
String		GW_online			"Gateway Online"					{ channel="mqtt:topic:MQTT_GATEWAY:GW_online" }
String		GW_IR_Rx			"Gateway IR Rx 	[JSONPATH($.value):%s ] "		{ channel="mqtt:topic:MQTT_GATEWAY:GW_IR_Rx" }
String		GW_Sys_RSSI			"Gateway RSSI 	[JSONPATH($.rssi):%s ] "		{ channel="mqtt:topic:MQTT_GATEWAY:GW_Sys" }
String		GW_Sys_UT			"Gateway Uptime [JSONPATH($.uptime):%s ] "		{ channel="mqtt:topic:MQTT_GATEWAY:GW_Sys" }
String		GW_Sys_Ip			"Gateway Ip 	[JSONPATH($.ip):%s ] "			{ channel="mqtt:topic:MQTT_GATEWAY:GW_Sys" }
String		GW_MQTT_IR			"Gateway IR Rx"						{ channel="mqtt:topic:MQTT_GATEWAY:GW_MQTT_IR" } // Gives a readout of the 'value' received by 'openmqttgateway'

// Each switch is used in a rule to send mqtt payload to 'openmqttgatway' which triggers the IR pulse
Switch   LG_Power_On      	"LG Power On"   	{ expire="1s,OFF" }      
Switch   LG_Power_Off     	"LG Power Off"  	{ expire="1s,OFF" }
Switch   LG_Vol_Up      	"LG Vol Up"   		{ expire="1s,OFF" }
Switch   LG_Vol_Dn      	"LG Vol Dn"   		{ expire="1s,OFF" }


var String jsonString

rule "MQTT to IR"

// Item to check to see if selected to ON. Add a 'or' for each remote button you want to use in openHAB       
    Item LG_Vol_Up changed to ON or 
    Item LG_Vol_Dn changed to ON		

// JSON 'value' to send as 'String' to 'openmqttgateway'
	if(LG_Vol_Up.state == ON) jsonString = "{\"value\":551502015}" // LG_Vol_Up
	if(LG_Vol_Dn.state == ON) jsonString = "{\"value\":551534655}" // LG_Vol_Dn

Screen shot of how it looks in openHAB app.

1 Like