Home automation

Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions
Goto page 1, 2  Next
Author Message
strobes
DD-WRT Novice


Joined: 17 Aug 2007
Posts: 38

PostPosted: Fri Jan 24, 2025 0:41    Post subject: Home automation Reply with quote
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
Sponsor
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2129
Location: WV, USA

PostPosted: Fri Jan 24, 2025 3:05    Post subject: Reply with quote
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
strobes
DD-WRT Novice


Joined: 17 Aug 2007
Posts: 38

PostPosted: Sat Jan 25, 2025 2:43    Post subject: Reply with quote
lexridge wrote:
You can install MQTT (Mosquitto) on DD-WRT via Entware. I am using it with Home Assistant and it works well.

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?
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2129
Location: WV, USA

PostPosted: Sat Jan 25, 2025 2:55    Post subject: Reply with quote
strobes wrote:
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
strobes
DD-WRT Novice


Joined: 17 Aug 2007
Posts: 38

PostPosted: Sat Jan 25, 2025 3:27    Post subject: Reply with quote
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!
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2129
Location: WV, USA

PostPosted: Sat Jan 25, 2025 3:58    Post subject: Reply with quote
strobes wrote:
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. Wink 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
strobes
DD-WRT Novice


Joined: 17 Aug 2007
Posts: 38

PostPosted: Sat Jan 25, 2025 20:35    Post subject: Reply with quote
lexridge wrote:
strobes wrote:
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. Wink 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.
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2129
Location: WV, USA

PostPosted: Sat Jan 25, 2025 20:51    Post subject: Reply with quote
strobes wrote:
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
strobes
DD-WRT Novice


Joined: 17 Aug 2007
Posts: 38

PostPosted: Sun Jan 26, 2025 21:06    Post subject: Reply with quote
@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
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2129
Location: WV, USA

PostPosted: Sun Jan 26, 2025 22:35    Post subject: Reply with quote
strobes wrote:
@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
strobes
DD-WRT Novice


Joined: 17 Aug 2007
Posts: 38

PostPosted: Sun Jan 26, 2025 23:55    Post subject: Reply with quote
> /opt/sbin/mosquitto -c /opt/etc/mosquitto/mosquitto.conf&

Is this the reason for "&"? If a command is terminated by the control operator ( '&' ), the shell shall execute the command asynchronously in a subshell.
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2129
Location: WV, USA

PostPosted: Mon Jan 27, 2025 0:24    Post subject: Reply with quote
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
strobes
DD-WRT Novice


Joined: 17 Aug 2007
Posts: 38

PostPosted: Mon Jan 27, 2025 1:13    Post subject: Reply with quote
lexridge wrote:
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.
strobes
DD-WRT Novice


Joined: 17 Aug 2007
Posts: 38

PostPosted: Mon Jan 27, 2025 2:50    Post subject: Reply with quote
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

mosquitto_sub -h localhost -t /hello/world
mosquitto_pub -h localhost -t /hello/world -m 'welcome!'

The mosquito is running and listens on 1883, No changes to default cfg file yet. (samba client created)

2726 1 nobody S 3996 3.1 0 0.0 mosquitto -c /opt/etc/mosquitto/mosquitto.conf

tcp 0 0 ::1:1883 :::* LISTEN 2726/mosquitto
tcp 0 0 127.0.0.1:1883 0.0.0.0:* LISTEN 2726/mosquitto
lexridge
DD-WRT Guru


Joined: 07 Jun 2006
Posts: 2129
Location: WV, USA

PostPosted: Mon Jan 27, 2025 3:11    Post subject: Reply with quote
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:
Code:
#pid_file /opt/var/run/mosquitto.pid

persistence true
persistence_location /opt/var/lib/mosquitto/

#log_dest file /opt/var/log/mosquitto.log

#include_dir /opt/etc/mosquitto/conf.d

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
Goto page 1, 2  Next Display posts from previous:    Page 1 of 2
Post new topic   Reply to topic    DD-WRT Forum Index -> General Questions All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum