Page 1 of 1

MQTT domoticz/out topic on arduino

Posted: Wednesday 09 January 2019 22:17
by JanJelle
Hi,

I am facing an issue with receiving a message on the arduino from the Domoticz server. The arduino is reading the topics that it publishes itself fine, and also reads topics published directly from the raspberry pi mosquitto server.

however it doesn't read any switch statements. I have now made a dummy device to create virtual switches/sensors. the server reads the MQTT message from the arduino and sets the virtual temperature sensor for example, but i can't read any switch commands sent from the domoticz server.

How is this normally done? do I have to define a topic for the message per virtual switch? i thought every topic was domoticz/out.

Can anyone point me in the right direction?

thanks in advance.

Re: MQTT domoticz/out topic on arduino

Posted: Wednesday 09 January 2019 23:56
by waaren
JanJelle wrote: Wednesday 09 January 2019 22:17 I am facing an issue with receiving a message on the arduino from the Domoticz server.
Can anyone point me in the right direction?
Can you describe what you did so far.
Did you add a MQTT Client Gateway with LAN interface as hardware in domoticz ? Settings ?
Where is your broker located ?

Re: MQTT domoticz/out topic on arduino

Posted: Thursday 10 January 2019 7:07
by JanJelle
Hi,

My broker is on a raspberry pi in the network. the arduino is also in the network.

I have added the mqtt gateway over LAN and I have communication between the 2. Arduino publishes a temperature and domoticz receives this in a the log correctly and puts it in a virtual temperature gauge. so far so good.

the arduino also subscribes to the domoticz/in topic and that works. it receives the message that it publishes.

the problem is receiving data from a switch or anything on the topic "domoticz out". I have a feeling I am configuring the domoticz virtual switch in a wrong manner because I can see in the log that I have pressed the switch, but I don't see the full mqtt package in the log like the incoming traffic but I don't know if that is normally the case.

Does adding a virtual switch automatically make it publish on domoticz/out over mqtt?

If i publish a message on the command line on the pi with the mosquitto_pub function the arduino also reads it fine (when subscribing to any topic I put in the command ofcourse.

Re: MQTT domoticz/out topic on arduino

Posted: Thursday 10 January 2019 8:48
by waaren
JanJelle wrote: Thursday 10 January 2019 7:07 Does adding a virtual switch automatically make it publish on domoticz/out over mqtt?
If you set your mqtt gateway over LAN settings in domoticz to flat (out) it will publish switch events to domoticz/out
Spoiler: show
1547105987.966405771 - domoticz/out - {
"Battery" : 255,
"RSSI" : 12,
"description" : "",
"dtype" : "Light/Switch",
"id" : "0001455B",
"idx" : 1291,
"name" : "mqtt_testStwitch",
"nvalue" : 1,
"stype" : "Switch",
"svalue1" : "0",
"switchType" : "On/Off",
"unit" : 1
}

Re: MQTT domoticz/out topic on arduino

Posted: Thursday 10 January 2019 8:51
by emme
MQTT in domoticz is a sort of console for logs... my understanding is that you cannot issue a command to query the state of a device via MQTT
you have to grab the ID during the event and store it.

OR, query the device via HTTP API/JSON request

hope this is what you are willing to get :P

Re: MQTT domoticz/out topic on arduino

Posted: Thursday 10 January 2019 9:32
by JanJelle
If you set your mqtt gateway over LAN settings in domoticz to flat (out) it will publish switch events to domoticz/out
This goes for any switch? virtual switches as well? is there any way to see the message as the MQTT message in the log so I can be sure that the topic is correct? Is there also a way to assign a user-specified topic to an action as well? say switch_light will be topic "switch_light". also, is it possible to set the state of the switch in Domoticz via an incoming MQTT message?
MQTT in domoticz is a sort of console for logs... my understanding is that you cannot issue a command to query the state of a device via MQTT
you have to grab the ID during the event and store it.

OR, query the device via HTTP API/JSON request

hope this is what you are willing to get :P
Thanks for the reply. I don't need to query the state of a device in that manner. I just want to press the switch in the console and send an MQTT message out on the appropriate topic.

Re: MQTT domoticz/out topic on arduino

Posted: Thursday 10 January 2019 9:42
by waaren
JanJelle wrote: Thursday 10 January 2019 9:32 This goes for any switch? virtual switches as well?
Not for all sensors (not for a text sensor) but virtual switches: Yes
I just want to press the switch in the console and send an MQTT message out on the appropriate topic.
I use

Code: Select all

mosquitto_sub -F "%U - %t - %p" -v -h <brokerIP> -p 1883 -t '#' 
on my PI to listen to all MQTT topics.

Re: MQTT domoticz/out topic on arduino

Posted: Thursday 10 January 2019 10:13
by JanJelle
CODE: SELECT ALL

mosquitto_sub -F "%U - %t - %p" -v -h <brokerIP> -p 1883 -t '#'
Alright I will give this a go to see if the domoticz console actually sends out the MQTT message because I am suspecting that part.

furthermore there are no settings required for outgoing messages? timeout on the MQTT gateway or anything specific?

I'll let you know how I get on.

Re: MQTT domoticz/out topic on arduino

Posted: Thursday 10 January 2019 22:33
by JanJelle
Hi,

Ok I got it running. I made the mistake of asigning the IP address of the arduino in the gateway, but I also had a second gateway with the localhost IP which is the raspberry that runs the server. obviously I shouldn't have put the MQTT gateway for the arduino in there since that is not the broker, but I didn't realize that thourougly what I was doing there.

After this I received the switch commands in the raspberry pi server with the code you mentioned, apart that I had to fill in -T instead of -F and <IPbroker> was localhost.

Furthermore I had to change the header file of the MQTT library of the arduino to accept packages of 512bytes. default was 128 bytes but this was too limited for the messages of the domoticz.

Thanks for the help!

Re: MQTT domoticz/out topic on arduino

Posted: Sunday 14 April 2019 21:34
by RobertB2000
To JanJelle.
Sorry for my English. I have a similar problem like you.
I can send an MQTT message to domoticz from arduino. I can not get the domotics message. Could you send me your sketch arduino, who is reading the switching instruction?

Re: MQTT domoticz/out topic on arduino

Posted: Wednesday 17 July 2019 11:07
by SebaNowy
PubClient has a default message size which is 128 bytes. As you probably know json message from domoticz on domiticz/out is much bigger. What you need to do is edit PubSubClient.h and change default size of message.
Just change
#define MQTT_MAX_PACKET_SIZE 128
to
#define MQTT_MAX_PACKET_SIZE 1024

Re: MQTT domoticz/out topic on arduino

Posted: Wednesday 20 November 2019 22:08
by Westcott
SebaNowy,

Thanks for finding that, and posting the solution!
It needs to be added to the MQTT Wiki.