Good morning Guys,
First of all congratulations on this software, It looks like exactly what I need!
I have been looking for a web based server running on a pi to control domotics, and this seems to tick all the boxes. I was wondering if the following is possible:
I would like to use the webserver to connect to an arduino running in the same network over TCP/IP and control/read all I/O with this. I have implemented a Modbus scada package before on an arduino, basically I am looking for something similar. is there an easy protocol interface for this?
I am sure this has been asked before, then please re-direct my request.
If i can manage this I will build my new home around this software and donate for the use.
thanks in advance.
General I/O control of arduino
Moderator: leecollings
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: General I/O control of arduino
Maybe this is a good starting point ?JanJelle wrote: ↑Sunday 06 January 2019 8:22 I would like to use the webserver to connect to an arduino running in the same network over TCP/IP and control/read all I/O with this. I have implemented a Modbus scada package before on an arduino, basically I am looking for something similar. is there an easy protocol interface for this?
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 11
- Joined: Sunday 06 January 2019 8:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: General I/O control of arduino
Hi Waaren,
Thanks for the reply. MQTT is new for me but i am giving this a go and I have established connection between my arduino and the MQTT server. I am now trying to replicate the MQTT example that Domoticz has on the website where it uses a virtual temperature sensor and a mosquitto publish command to trigger the sensor but it seems that I can't get the string in the correct fashion so that domoticz understand the published message.
this part is working fine over the raspi mosquitto command:
So i am trying to publish a similar message like this with the arduino:
I can see the message back in my serial monitor when i subscribe again to the same topic, so it seems that the message gets to the MQTT server and when subscribing I get the message back. however, it does not trigger the virtual temperature sensor in the domoticz server. I know that I am not using the " around the "idx" for example, but I can't send that as a string since that will mess up the original string.
Any suggestions?
Thanks for the reply. MQTT is new for me but i am giving this a go and I have established connection between my arduino and the MQTT server. I am now trying to replicate the MQTT example that Domoticz has on the website where it uses a virtual temperature sensor and a mosquitto publish command to trigger the sensor but it seems that I can't get the string in the correct fashion so that domoticz understand the published message.
this part is working fine over the raspi mosquitto command:
Code: Select all
To test if Domoticz receives data, create a Dummy Virtual temperature sensor.
Under Setup/Hardware add a device of type: "Dummy (Does nothing, use for virtual switches only)" with the name of your choice ("Dummy" for example).
In the corresponding entry of your just created "Dummy" hardware, click the "Create Virtual Sensors" button that appear following his type. Then enter the name of your choice (Let's say "Fictive Temp").
Under Setup/Devices, get the "idx" number of your "Fictive Temp" device (Let's say it's 1).
Then publish a temperature measurement to the virtual sensor idx noted above (example idx 1) like:
mosquitto_pub -h localhost -m '{ "idx" : 1, "nvalue" : 0, "svalue" : "25.0" }' -t 'domoticz/in'
If the mosquitto_pub command is not found install the mosquitto client:
sudo apt-get install mosquitto-clients
Code: Select all
client.publish("domoticz/in", "{idx : 3, nvalue : 0, svalue : 24.3}");
client.subscribe("domoticz/in");
client.loop();
Any suggestions?
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: General I/O control of arduino
I do not own an arduino but assume you can use a combination of single and double quotes.
so try something like
Code: Select all
client.publish("domoticz/in", '{"idx" : 3, "nvalue" : 0, "svalue" : "24.3"}');
If you don't see the the expected value in domoticz the please check the log. It should give you an idea what happens.
Log when receiving bad MQTT stuff
Code: Select all
2019-01-07 22:19:40.213 MQTT: Topic: domoticz/in, Message: {idx : 1285, nvalue : 0, svalue : 24.3}
2019-01-07 22:19:40.213 Error: MQTT: Invalid data received!
Code: Select all
2019-01-07 22:23:50.120 MQTT: Topic: domoticz/in, Message: {"idx" : 1285, "nvalue" : 0, "svalue" : "24.3" }
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 11
- Joined: Sunday 06 January 2019 8:15
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Contact:
Re: General I/O control of arduino
Ok I was not aware of the log, that was helpful! I could at least confirm my messages were also received in domoticz instead of just echoed back via a subscribe in the arduino.
I got it all working now, thanks for the helpful hints
The problem was the build up of the string. the extra quotes wasn't the answer, but it got me searching in the right direction. appearantly I needed "\" to get the double quotes in the string.
Build up of this message now in the arduino IDE is:
This bit of code in the loop connects to the server, re-attempts if failing, publishes the message and subscribes to it again to echo it back for reference in a serial monitor. Domoticz now accepted the message and put it in a virtual temperature device with 23.4 degrees as temperature.
I am now confinced I will manage all the other messages as well and will start writing the arduino code and developing the hardware for dimmers, relay outputs, alarm inputs, switch inputs etc. this hardware will be a domoticz controller with the arduino MEGA2560 as micro controller. all I/O will be isolated from the outside world with opto-couplers/relays/MOSFETS and the arduino will be guarded with an external watchdog.
If anyone is interested in helping or need help with this part as well (I noticed that the WIKI mentioned help needed!) let me know!
Thanks again!
I got it all working now, thanks for the helpful hints

Build up of this message now in the arduino IDE is:
Code: Select all
void loop()
{
if (!client.connected()) {
reconnect();
}
client.publish("domoticz/in", "{\"idx\" : 3, \"nvalue\" : 0, \"svalue\" : \"23.4\"}");
client.subscribe("domoticz/in");
client.loop();
delay(5000);
}
I am now confinced I will manage all the other messages as well and will start writing the arduino code and developing the hardware for dimmers, relay outputs, alarm inputs, switch inputs etc. this hardware will be a domoticz controller with the arduino MEGA2560 as micro controller. all I/O will be isolated from the outside world with opto-couplers/relays/MOSFETS and the arduino will be guarded with an external watchdog.
If anyone is interested in helping or need help with this part as well (I noticed that the WIKI mentioned help needed!) let me know!
Thanks again!
Who is online
Users browsing this forum: No registered users and 1 guest