MQTT domoticz/out topic on arduino

Moderator: leecollings

Post Reply
JanJelle
Posts: 11
Joined: Sunday 06 January 2019 8:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

MQTT domoticz/out topic on arduino

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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 ?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JanJelle
Posts: 11
Joined: Sunday 06 January 2019 8:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
User avatar
emme
Posts: 909
Joined: Monday 27 June 2016 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version: latest
Location: Milano, Italy
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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
The most dangerous phrase in any language is:
"We always done this way"
JanJelle
Posts: 11
Joined: Sunday 06 January 2019 8:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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.
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
JanJelle
Posts: 11
Joined: Sunday 06 January 2019 8:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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.
JanJelle
Posts: 11
Joined: Sunday 06 January 2019 8:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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!
RobertB2000
Posts: 1
Joined: Sunday 14 April 2019 21:22
Target OS: Windows
Domoticz version:
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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?
SebaNowy
Posts: 1
Joined: Wednesday 17 July 2019 11:02
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: MQTT domoticz/out topic on arduino

Post 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
User avatar
Westcott
Posts: 423
Joined: Tuesday 09 December 2014 17:04
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: UK - Glos
Contact:

Re: MQTT domoticz/out topic on arduino

Post by Westcott »

SebaNowy,

Thanks for finding that, and posting the solution!
It needs to be added to the MQTT Wiki.
Zwave - Sigma Z+ stick, Fibaro, Horstmann, Neo Coolcam, EUROtronic
RFlink - IR detectors and temperatures
Wifi - YeeLights, ESP32s, Anoop sockets
Zigbee - lots with zigbee2mqtt and ZbBridge
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests