Maybe we can figure out why it isn’t working for us, but it is for you. I think it would be better not to reconnect the whole time, but keep the connection open as you did in your last version.
I’m running eclipse-mosquitto in Docker, (latest) version 1.6.12. Which mosquitto-server are you guys running?
As for me, the recent version is not correct operation.
The 1st problem is disconnecting from mqtt broker in ~10 sec (defaut timeout).
1602927189: New client connected from 10.100.101.62 as dahua-vto-dahuavto (p1, c1, k10, u'my_mqtt_user').
1602927204: Client dahua-vto-dahuavto has exceeded timeout, disconnecting.
To fix that problem I added missed row after the new phpMQTT object creation at file DahuaEventHandler.php:
$mqtt->keepalive = $this->keepAliveInterval;
It’s OK now, but the 2nd problem remains. If you suddenly stop your broker, try block for $mqtt->publish doesn’t catch the exeption and you can see “MQTT message published” when the connection to broker already gone. It’s need to fix that moment.
Again, thanks @meteonet. I installed nano within my portainer container, added that row to DahuaVTO.php and got it working instead of timeouts. Now I can continue with my project while waiting for rest of the fixes!
Thanks for the quick fix. However, I think it would be better to release a new version with the fix from meteonet. What’s the reason you reverted to the old way of connecting. Wouldn’t it be better to keep the connection open using the keep-alive interval?
One more request for @bar
I’m using Dahua VTO 2000A and most of code runs well in docker with manual run (php).
There is however one issue:
MQTT message published Topic: DahuaVTO/VideoMotion/Event Payload: {“Action”:“Start”,“Data”:{“LocaleTime”:“2020-10-23 19:46:45”,“UTC”:1603475205},“deviceType”:“VTO2000A-2”,“serialNumber”:“xxxxxxx”}
Event Call from VTO
MQTT message published Topic: DahuaVTO/CallNoAnswered/Event Payload: {“Action”:“Start”,“Data”:{“CallID”:“3”,“IsEncryptedStream”:false,“LocaleTime”:“2020-10-23 19:46:46”,“LockNum”:2,“SupportPaas”:false,“TCPPort”:37777,“UTC”:1603475206},“deviceType”:“VTO2000A-2”,“serialNumber”:“xxxxxxx”}
PHP Notice: Undefined variable: eventList in /home/xxxxxxx/DahuaVTO2MQTT/DahuaEventHandler.php on line 454
PHP Notice: Trying to access array offset on value of type null in /home/xxxxxxx/DahuaVTO2MQTT/DahuaEventHandler.php on line 454
I think it is small issue as it looks as error in logging.
Oups - I messed up yesterday.
I’m currently running 2 environments:
1: the one which is woking is regular linux machine with older code. it is started manualy as it was only version I could make it working here.
2: raspburry pi 4 with HA installed - this one I would like to run, but cant install from repository ( parse error: Expected string key before ‘:’ at line 1, column 4 [00:10:15] ERROR: Unknown HTTP error occured)
Anyway - at least we know that VTO2000 works well.