Posted: Fri Jan 24, 2025 0:41 Post subject: Home automation
Hi,
I'm trying to send a message to an ESP32 that a particular device is reconnected to my network.
Desirable to keep my DDWRT and ESP32 on different Vlans.
Possibly this may work: https://markofthelam.com/blog/mqtt/
But may be there is a better way?
Thank you
You can install MQTT (Mosquitto) on DD-WRT via Entware. I am using it with Home Assistant and it works well. _________________ - Linksys EA8500: I-Gateway, WAP/VAP 5ghz only. Features: VLANs, Samba, WG, Entware - r60xxx
- Linksys EA8500: 802.11s Secondary w/VLAN Trunk over 5ghz - r60xxx
- Linksys MX4300: 802.11s Primary w/VLAN Trunk over 5ghz. 2.4ghz WAP/VAP only - r60xxx
- Linksys MX4300: (WAP/VAP (7)) Multiple VLANs over single trunk port. Entware/Samba r60xxx
- Linksys MR7350: WDS Station for extended Ethernet r60xxx
- Linksys MR7500, MX8500: None in production. Just testing. r60xxx
- OSes: Fedora 40, 10 RPis (2,3,4,5), 23 ESP8266s: Straight from Amiga to Linux in '95, never having owned a Windows PC.
- Forum member #248
Let me look in to this. Thank you. I can not find discussions how to send messages from DDWRT to HA. May be some scripts examples I can learn from?
There are no scripts necessary. Once you get MQTT running on dd-wrt (I use the non-ssl version), just add the integration in HA and put in the IPADDR of the router. Then you can read and publish from within the integration.
https://www.home-assistant.io/integrations/mqtt _________________ - Linksys EA8500: I-Gateway, WAP/VAP 5ghz only. Features: VLANs, Samba, WG, Entware - r60xxx
- Linksys EA8500: 802.11s Secondary w/VLAN Trunk over 5ghz - r60xxx
- Linksys MX4300: 802.11s Primary w/VLAN Trunk over 5ghz. 2.4ghz WAP/VAP only - r60xxx
- Linksys MX4300: (WAP/VAP (7)) Multiple VLANs over single trunk port. Entware/Samba r60xxx
- Linksys MR7350: WDS Station for extended Ethernet r60xxx
- Linksys MR7500, MX8500: None in production. Just testing. r60xxx
- OSes: Fedora 40, 10 RPis (2,3,4,5), 23 ESP8266s: Straight from Amiga to Linux in '95, never having owned a Windows PC.
- Forum member #248
oh, one more question, My DDWRT on private (br0)Vlan and HA on public (br1). Connection can be init only from br0. Is this OK with MQTT?
And Entware has two Mosquitto packages SSl and no SSL. Wondering if SSL will cause significantly more load on my router's CPU, introduce memory leaks, if you may know?
Thanks!
oh, one more question, My DDWRT on private (br0)Vlan and HA on public (br1). Connection can be init only from br0. Is this OK with MQTT?
And Entware has two Mosquitto packages SSl and no SSL. Wondering if SSL will cause significantly more load on my router's CPU, introduce memory leaks, if you may know?
Thanks!
I am pretty sure you can specify the interface and/or IPADDR to use in the mosquitto.conf file (I think!). I only use mosquitto for home built devices (ESP and Rpi) so it's on the main network, because I trust those because I trust myself. Everything else is on vlan10 which doesn't have any mqtt devices on it.
If it cannot be configured for the IP/Interface, then you will need an iptables rule. _________________ - Linksys EA8500: I-Gateway, WAP/VAP 5ghz only. Features: VLANs, Samba, WG, Entware - r60xxx
- Linksys EA8500: 802.11s Secondary w/VLAN Trunk over 5ghz - r60xxx
- Linksys MX4300: 802.11s Primary w/VLAN Trunk over 5ghz. 2.4ghz WAP/VAP only - r60xxx
- Linksys MX4300: (WAP/VAP (7)) Multiple VLANs over single trunk port. Entware/Samba r60xxx
- Linksys MR7350: WDS Station for extended Ethernet r60xxx
- Linksys MR7500, MX8500: None in production. Just testing. r60xxx
- OSes: Fedora 40, 10 RPis (2,3,4,5), 23 ESP8266s: Straight from Amiga to Linux in '95, never having owned a Windows PC.
- Forum member #248
oh, one more question, My DDWRT on private (br0)Vlan and HA on public (br1). Connection can be init only from br0. Is this OK with MQTT?
And Entware has two Mosquitto packages SSl and no SSL. Wondering if SSL will cause significantly more load on my router's CPU, introduce memory leaks, if you may know?
Thanks!
I am pretty sure you can specify the interface and/or IPADDR to use in the mosquitto.conf file (I think!). I only use mosquitto for home built devices (ESP and Rpi) so it's on the main network, because I trust those because I trust myself. Everything else is on vlan10 which doesn't have any mqtt devices on it.
If it cannot be configured for the IP/Interface, then you will need an iptables rule.
Thank you for advise. Me too, was programming esp32 for different project and looking to integrate all in to HA. Only thing is: many yml files require user names, passwords for integration, Justifiable, but also exposing them all if HA exposed to WAN.
Thank you for advise. Me too, was programming esp32 for different project and looking to integrate all in to HA. Only thing is: many yml files require user names, passwords for integration, Justifiable, but also exposing them all if HA exposed to WAN.
Nothing should be exposed to the WAN port by default and it uses port 1883. _________________ - Linksys EA8500: I-Gateway, WAP/VAP 5ghz only. Features: VLANs, Samba, WG, Entware - r60xxx
- Linksys EA8500: 802.11s Secondary w/VLAN Trunk over 5ghz - r60xxx
- Linksys MX4300: 802.11s Primary w/VLAN Trunk over 5ghz. 2.4ghz WAP/VAP only - r60xxx
- Linksys MX4300: (WAP/VAP (7)) Multiple VLANs over single trunk port. Entware/Samba r60xxx
- Linksys MR7350: WDS Station for extended Ethernet r60xxx
- Linksys MR7500, MX8500: None in production. Just testing. r60xxx
- OSes: Fedora 40, 10 RPis (2,3,4,5), 23 ESP8266s: Straight from Amiga to Linux in '95, never having owned a Windows PC.
- Forum member #248
@lexridge. In one of the old posts you mentioned: First I created a Samba user, then used that user to run mosquitto. This way I don't have to recreate the user on every boot. Then in Startup I just added this: /opt/sbin/mosquitto -c /opt/etc/mosquitto/mosquitto.conf&
Is this still valid for new builds? Or may be I can add user to DDWRT?
I think the Entware Mosquito package in broker and client but I should use only client part only if my preference is one way communication to a broker on a different Vlan?
Thank you
@lexridge. In one of the old posts you mentioned: First I created a Samba user, then used that user to run mosquitto. This way I don't have to recreate the user on every boot. Then in Startup I just added this: /opt/sbin/mosquitto -c /opt/etc/mosquitto/mosquitto.conf&
Is this still valid for new builds? Or may be I can add user to DDWRT?
Yep, I am still using this exact configuration, as a samba user. But it's really just as easy to create a new user on boot in startup commands. I have just not changed it since it works as is.
Quote:
I think the Entware Mosquito package in broker and client but I should use only client part only if my preference is one way communication to a broker on a different Vlan?
Thank you
I use both client and server (broker) as I use the client in dd-wrt to announce such things as router shutdowns, startups, uptime etc. Re: your vlans, well that's something you will just have to try and see how far your mqtt traffic gets, then adjust iptables accordingly. _________________ - Linksys EA8500: I-Gateway, WAP/VAP 5ghz only. Features: VLANs, Samba, WG, Entware - r60xxx
- Linksys EA8500: 802.11s Secondary w/VLAN Trunk over 5ghz - r60xxx
- Linksys MX4300: 802.11s Primary w/VLAN Trunk over 5ghz. 2.4ghz WAP/VAP only - r60xxx
- Linksys MX4300: (WAP/VAP (7)) Multiple VLANs over single trunk port. Entware/Samba r60xxx
- Linksys MR7350: WDS Station for extended Ethernet r60xxx
- Linksys MR7500, MX8500: None in production. Just testing. r60xxx
- OSes: Fedora 40, 10 RPis (2,3,4,5), 23 ESP8266s: Straight from Amiga to Linux in '95, never having owned a Windows PC.
- Forum member #248
Is this the reason for "&"? If a command is terminated by the control operator ( '&' ), the shell shall execute the command asynchronously in a subshell.
Correct. I am not 100% sure the '&' is even needed, but put it there just to be on the safe side. This is from my Administration/Commands/Startup Commands:
Code:
#For Entware
/opt/etc/init.d/rc.unslung start
sleep 5
/opt/sbin/mosquitto -c /opt/etc/mosquitto/mosquitto.conf&
sleep 2
#Announce the router has been rebooted
/opt/bin/mosquitto_pub -h YOURROUTERIPADDR -t ddwrt/system -m "`date` DD-WRT Rebooted"
So once mosquitto starts, it then publishes to the server that dd-wrt has been restarted complete with date/time. It does something similar at shutdown too.
mosquitto_pub is the app that sends to the server. -t flag is the topic and -m flag is the message to send. _________________ - Linksys EA8500: I-Gateway, WAP/VAP 5ghz only. Features: VLANs, Samba, WG, Entware - r60xxx
- Linksys EA8500: 802.11s Secondary w/VLAN Trunk over 5ghz - r60xxx
- Linksys MX4300: 802.11s Primary w/VLAN Trunk over 5ghz. 2.4ghz WAP/VAP only - r60xxx
- Linksys MX4300: (WAP/VAP (7)) Multiple VLANs over single trunk port. Entware/Samba r60xxx
- Linksys MR7350: WDS Station for extended Ethernet r60xxx
- Linksys MR7500, MX8500: None in production. Just testing. r60xxx
- OSes: Fedora 40, 10 RPis (2,3,4,5), 23 ESP8266s: Straight from Amiga to Linux in '95, never having owned a Windows PC.
- Forum member #248
Correct. I am not 100% sure the '&' is even needed, but put it there just to be on the safe side. This is from my Administration/Commands/Startup Commands:
Code:
#For Entware
/opt/etc/init.d/rc.unslung start
sleep 5
/opt/sbin/mosquitto -c /opt/etc/mosquitto/mosquitto.conf&
sleep 2
#Announce the router has been rebooted
/opt/bin/mosquitto_pub -h YOURROUTERIPADDR -t ddwrt/system -m "`date` DD-WRT Rebooted"
So once mosquitto starts, it then publishes to the server that dd-wrt has been restarted complete with date/time. It does something similar at shutdown too.
mosquitto_pub is the app that sends to the server. -t flag is the topic and -m flag is the message to send.
Thank you! This has information that I can use to move forward without guessing.
well, i should admit my Linux knowledge is shallow.
My attempt to run either of two comands returns -sh: mosquitto_pub or _sub: not found.
(https://mpolinowski.github.io/docs/Development/Javascript/2021-06-02--mqtt-cheat-sheet/2021-06-02/#configuration). May be this is missing? libmosquitto-nossl 2.0.18-3
Im using two SSH sessions to DDWRT for this test
These must be in your $PATH.
/opt/sbin:/opt/bin:/opt/usr/sbin:/opt/usr/bin
Just type
Code:
#echo $PATH
to check.
Are you running unslung in your Startup as I posted above?
You can try running mosquitto_sub and _pub using the full path. ie /opt/bin/mosquitto_pub
I'm pretty sure you need a mosquitto.conf file. At least a simple one:
allow_anonymous true
#password_file /etc/mosquitto/pwfile
listener 1883
user YOUR_SAMBA_USERNAME_HERE
You have a slightly newer version installed than I do, but that should not matter. I have:
mosquitto-client-nossl - 2.0.15-1
mosquitto-nossl - 2.0.15-1
Again, your posted commands should work. If they are not found, then your PATH is not correct. I have told you how to fix that with unslung. You MUST run this in Startup to set your PATHs, but if you give the full path, it should still work unless a library is missing, but that would be an entirely different error. _________________ - Linksys EA8500: I-Gateway, WAP/VAP 5ghz only. Features: VLANs, Samba, WG, Entware - r60xxx
- Linksys EA8500: 802.11s Secondary w/VLAN Trunk over 5ghz - r60xxx
- Linksys MX4300: 802.11s Primary w/VLAN Trunk over 5ghz. 2.4ghz WAP/VAP only - r60xxx
- Linksys MX4300: (WAP/VAP (7)) Multiple VLANs over single trunk port. Entware/Samba r60xxx
- Linksys MR7350: WDS Station for extended Ethernet r60xxx
- Linksys MR7500, MX8500: None in production. Just testing. r60xxx
- OSes: Fedora 40, 10 RPis (2,3,4,5), 23 ESP8266s: Straight from Amiga to Linux in '95, never having owned a Windows PC.
- Forum member #248