1technophile / OpenMQTTGateway

MQTT gateway for ESP8266 or ESP32 with bidirectional 433mhz/315mhz/868mhz, Infrared communications, BLE, Bluetooth, beacons detection, mi flora, mi jia, LYWSD02, LYWSD03MMC, Mi Scale, TPMS, BBQ thermometer compatibility & LoRa.
https://docs.openmqttgateway.com
GNU General Public License v3.0
3.51k stars 776 forks source link

Restarting of Ras Pi causes the last IR command to be resent #102

Closed BertrumUK closed 6 years ago

BertrumUK commented 6 years ago

If I reboot my Ras Pi (MQTT Broker) my IR transmitter fires the last command even though there is no MQTT command being sent from the broker. I am running the IR transmitter from a NodeMCU.

I am using the IR to control a digibox and use this to power it up in the morning - a reboot causes the digibox to switch off which isn't very popular with the family.

1technophile commented 6 years ago

Do you have this behaviour even if openmqttgateway is not connected ?

It could be due to a retain flag stored by the broker

DenDeze commented 6 years ago

Are you retaining your messages?

BertrumUK commented 6 years ago

If I monitor the broker (mosquito) when I reboot the NodeMCU there is nothing sent from the broker telling the NodeMCU to fire off the last IR command.

I have been running this for about 3 months and it has always done it. I updated all the code about a month ago without modifying the base code and only updating the settings for classic wiring and wifi etc.

Checking the code on User_config.h and the retain flag is set

define will_Retain true

This is the same as your code on Github. I will change this to "false" and see if this works ok.

Update

New code uploaded with the retain flag set to false and there is no change. Even uploading the same config with the new flag set causes the IR to fire and turn off my digi box as you can see from this ping

Reply from 192.168.0.20: bytes=32 time=16ms TTL=64 Reply from 192.168.0.20: bytes=32 time=35ms TTL=64 Reply from 192.168.0.20: bytes=32 time=105ms TTL=64 Reply from 192.168.0.20: bytes=32 time=2600ms TTL=64 Reply from 192.168.0.20: bytes=32 time=3ms TTL=64 Reply from 192.168.0.20: bytes=32 time=1ms TTL=64 Request timed out. Request timed out. Request timed out. Request timed out.

Here is the code I am uploading

/-------------DEFINE YOUR NETWORK PARAMETERS BELOW----------------/ //MQTT Parameters definition

define mqtt_server "192.168.0.60"

define mqtt_user "xxxxxxx" // not compulsory only if your broker needs authentication

define mqtt_password "xxxxxx" // not compulsory only if your broker needs authentication

define mqtt_port 1883

define Gateway_Name "OpenMQTTGateway" //OpenMQTTGateway for NodeMCU

define will_Topic "home/OpenMQTTGateway/LWT" //home/OpenMQTTGateway/LWT for NodeMCU

define will_QoS 0

define will_Retain false

define will_Message "Offline"

define Gateway_AnnouncementMsg "Online"

1technophile commented 6 years ago

This will retain is only for last will testament of the gateway not for commands

1technophile commented 6 years ago

here is some info a bout retain flag http://www.hivemq.com/blog/mqtt-essentials-part-8-retained-messages

and this chapter: Delete a retained message

BertrumUK commented 6 years ago

Thank you for that. Maybe I need a way to send the power command then a false command that does nothing. A restart of the broker or NodeMCU would then only send the false command.

Can I keep this issue open a while longer in case someone comes up with a better solution?

gammelobst commented 6 years ago

have you already tried sending an empty message with the retained flag set to your conflicting topic? I never had this with OpenMQTTGateway and FHEM, but i do not set the retained flag while sending sth. from FHEM to the broker. I had only retained messages with the old name after renaming the gateway, but sending an empty message with retained flag let them go away. What home automation controller software do you use?

BertrumUK commented 6 years ago

I use Home Assistant on a Raspeberry Pi. The Pi is running mosquito as the broker. The retain flag is set to “false” on the code running on the NodeMCU and the command on Home Assistant.

I am running a 433mhz transmitter and a DHT22 temp/humidity sensor from the same NodeMCU.

If I reboot the Pi or the NodeMCU the last IR command is resent but the 433mhz rf signal does not this is what I don’t understand- why does the last IR command get sent when retain is set to false ?

1technophile commented 6 years ago

what I don’t understand- why does the last IR command get sent when retain is set to false ?

the retain flag parameter in the user_config.h is not for commands. It is for last will testament (online/offline detection of the gateway)

Try sending an empty message to the problematic topic or maybe modify your topic as an ultimate solution

BertrumUK commented 6 years ago

Its not very elegant but I have incorporated a fake IR command to be sent when the power to my digibox turns on. If the broker or the NodeMCU are restarted the fake command gets resent but there is no action taken by the digibox. As I said it's not elegant but it gets around the issue that I am having with the MQTT Switch component of Home Assistant.

Closing this issue. Thanks for all that helped me.