What's new

Mosquitto on AsusWRT firmware / Asus RT-AC68U Router

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Sub Zero

Occasional Visitor
Trying to work out how to install Mosquitto on a AsusWRT firmware / Asus RT-AC68U combo.
I believe the Linux is based on Tomato and heavily modified, but all the instructions I can find don't correspond to the folders I am seeing on the router when I telnet into it.

What I am ultimately trying to do is setup some kind of presence detection and pass instructions to a Mosquitto server, for further action. I am not the most educated Linux user, so I am not sure if there is an easy way to do this.

These are the instructions I am trying to follow https://github.com/dersimn/owrtwifi2mqtt
It seems to be based on OpenWRT which from what I read doesn't really do wireless on the Asus RT-AC68U.

Would appreciate any assistance you can give.
 
Thanks for the link. For those playing along at home and trying to do the same thing I am at a later date, the link basically tells you to use Entware...

I have AsusWRT firmware on my RT-AC68U router, which under "Tools" tells me the CPU is an arm v7
So I navigated through several links to get to the arm v7 download page. https://github.com/Entware/Entware/wiki/Alternative-install-vs-standard

I didn't know the kernel version so I used PuTTY to telnet into the router and run the following command. (http://www.linfo.org/find_kernel_version.html)
uname -r

Which told me the kernel version was 2.6.36.4, then I could work out which version to use... armv7 (kernel >= 2.6.36)
Next step is determine if I need Standard (Generic) or Alternative. Looking at the text above the download links, I should be fine with Standard (Generic).

Next step is to work out how to load an xxxx.sh file.
Back on this page I found these instructions. https://github.com/Entware/Entware/wiki/Install-on-Asus-stock-firmware

First check your kernel version with uname -r. If your kernel is 3.2 or higher and your architecture is arm (RT-AC58U) use armv7sf-k3.2 repo, if your kernel is 2.6.36 (Asus Broadcom routers) use armv7sf-k2.6 repo. If you have mipsel router vith 2.6.22 kernel you can use only Entware-ng repo. After reboot, open telnet/ssh console and type following command.
  • Standard install on ARM 2.6.36 devices (RT-AC68U, RT-AC56U, RT-AC87U, RT-AC3200, RT-AC88U, RT-AC3100, RT-AC5300, e.t.c):
wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh

OK if I had found that page first it might have saved a step or two... However I don't know if the AsusWRT firmware is the same as the regular Asus firmware. I am going to make an assumption that they are both loosely based on the Tomato flavour of Linux and give this a go...
wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh

I ran the command from the default folder me@myrouter: /tmp/home/root# wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh
and got a whole heap of messages saying "No such file or directory"
so lets try cd / to go back to the root folder and try again...
me@myrouter: /# wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh
Nope a whole lot more of the same messages, seems like I have hit a dead end.
 
Thanks for the link. For those playing along at home and trying to do the same thing I am at a later date, the link basically tells you to use Entware...

I have AsusWRT firmware on my RT-AC68U router, which under "Tools" tells me the CPU is an arm v7
So I navigated through several links to get to the arm v7 download page. https://github.com/Entware/Entware/wiki/Alternative-install-vs-standard

I didn't know the kernel version so I used PuTTY to telnet into the router and run the following command. (http://www.linfo.org/find_kernel_version.html)
uname -r

Which told me the kernel version was 2.6.36.4, then I could work out which version to use... armv7 (kernel >= 2.6.36)
Next step is determine if I need Standard (Generic) or Alternative. Looking at the text above the download links, I should be fine with Standard (Generic).

Next step is to work out how to load an xxxx.sh file.
Back on this page I found these instructions. https://github.com/Entware/Entware/wiki/Install-on-Asus-stock-firmware

First check your kernel version with uname -r. If your kernel is 3.2 or higher and your architecture is arm (RT-AC58U) use armv7sf-k3.2 repo, if your kernel is 2.6.36 (Asus Broadcom routers) use armv7sf-k2.6 repo. If you have mipsel router vith 2.6.22 kernel you can use only Entware-ng repo. After reboot, open telnet/ssh console and type following command.
  • Standard install on ARM 2.6.36 devices (RT-AC68U, RT-AC56U, RT-AC87U, RT-AC3200, RT-AC88U, RT-AC3100, RT-AC5300, e.t.c):
wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh

OK if I had found that page first it might have saved a step or two... However I don't know if the AsusWRT firmware is the same as the regular Asus firmware. I am going to make an assumption that they are both loosely based on the Tomato flavour of Linux and give this a go...
wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh

I ran the command from the default folder me@myrouter: /tmp/home/root# wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh
and got a whole heap of messages saying "No such file or directory"
so lets try cd / to go back to the root folder and try again...
me@myrouter: /# wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh
Nope a whole lot more of the same messages, seems like I have hit a dead end.


You're making it much more difficult than it needs to be?

I would recommend that you format your jffs partition to ensure you're starting in a clean state. Perform a 'format jffs partition on next reboot' and proceed to reboot the router 3 times in the next 15 minutes waiting 5 to 10 minutes between reboots.

Install amtm from thelonelycoder and format your USB drive to Ext4 with journalling enabled.

If you want to install Diversion (a whole network Ad blocker from thelonelycoder), it will also install Entware for you. You can install Diversion from the amtm menu script you already have installed. ;)

If you do not want to install Diversion, then install the standalone Entware to try your Mosquito install. Just know that if you later want to use the additional scripts amtm supports, you will probably need to re-install everything again at that point.

Hint; install Diversion and let it install Entware and pixelserv-tls. You can disable Diversion immediately afterward. And install Mosquito then. ;)
 
At this point I would say everything is harder than it should be. I know a little Linux probably enough to get me into trouble, but nothing more.
While what you propose may do what I am looking for, I can tell at a glance the instructions are too generic and missing too many parts to follow...

For example, back on the other page I am trying to still follow their somewhat dubious instructions...

Start scripts
Open telnet/ssh console and copy & past following scripts:

cat << EOF > /tmp/script_usbmount.tmp
if [ \$1 = "/tmp/mnt/MYPART" ]
then
ln -sf \$1 /tmp/opt
/opt/etc/init.d/rc.unslung start
fi
EOF
nvram set script_usbmount="`cat /tmp/script_usbmount.tmp`"

cat << EOF > /tmp/script_usbumount.tmp
if [ \$1 = "/tmp/mnt/MYPART" ]
then
/opt/etc/init.d/rc.unslung stop
fi
EOF
nvram set script_usbumount="`cat /tmp/script_usbumount.tmp`"

nvram commit
reboot

I have opened a telnet / ssh console and pasted the text in hit enter and it did nothing, so this would suggest that I need to put this text into a file something like a Windows batch file or a Linux script (.sh?) to make it run, only problem is I can't create said file because nano doesn't seem to be recognised by the Asus firmware Linux, in fact most Linux commands don't seem to work, so while this person thinks this is a slam dunk instruction to follow, even something as simple as this is proving to be a chore even before I try to install Entware.

Then there is the little matter of running a script which I don't know how to do. I did find this..
Set execute permission on your script:
chmod +x script-name-here.sh
To run your script, enter:
./script-name-here.sh

Which may work if I can open some kind of editor to paste the text to get it to work, but currently I am stuck at step 1.
Would appreciate you filling in the most basic and obvious blanks I am missing if you please could.
 
Success (sort of)... Downloaded Asuswrt-Merlin 384.10 which has just been released and nano now works :D

Used nano to create the two scripts (took a guess at where to split between the two scripts, and modified the MYPART to the RouterUSB) and called them USBmount.sh and USBumount.sh
Run the chmod command chmod +x USBmount.sh and chmod +x USBumount.sh to make them executable
Typed ls -la to check the attributes had changed...
and then run USBmount.sh by typing ./USBmount.sh
finally I run... wget -O - http://bin.entware.net/armv7sf-k2.6/installer/generic.sh | sh and this time I had success I now have Entware installed. Not sure if it is running...

Found this on the Asuswrt section.
Install on asuswrt merlin firmware
Alexander Ryzhov edited this page on Mar 15, 2018 · 2 revisions

Entware installer is included into firmware since 384.4 Beta 3.

Run entware-setup.sh to start using Entware.

Million dollar question is where on the file system is entware-setup.sh????
Looked in folders, looked on the USB no sign to be found and still no idea how to install Mosquitto once I do find it.

I am hoping that this entware-setup.sh starts some kind of GUI that I can install Mosquitto from otherwise it would seem like I have wasted hours trying to install Entware.
 
Last edited:
L&LD's comment made the assumption that you were using Merlin's fimrware which you weren't at that time.

Now that you are I believe you can just SSH into the router and type "entware-setup.sh". But as you have already installed a version of Entware you need to remove that first and start again. Remember to format your JFFS partition as well as removing Entware from your USB device.

When you went from stock Asus firmware to Merlin did you perform a factory reset afterwards? If not you need to do that now before you go any further. Don't then reload an old "save settings" backup from a previous firmware.
 
Last edited:
L&LD's comment made the assumption that you were using Merlin's fimrware which you weren't at that time.

Now that you are I believe you can just SSH into the router and type "entware-setup.sh". But as you have already installed a version of Entware you need to remove that first and start again. Remember to format your JFFS partition as well as removing Entware from your USB device.

When you went from stock Asus firmware to Merlin did you perform a factory reset afterwards? If not you need to do that now before you go any further. Don't then reload an old "save settings" backup from a previous firmware.

I have actually gone from the factory firmware to the AsusWRT 384.9 back to the factory firmware back to AsusWRT384.10 (which gave me nano) where I am currently on 384.10
I just used the firmware tool in the router to do all the upgrades and every time it carried the settings back over onto the new firmware, I haven't needed to reload the settings file to get my settings back.

I just tried to install this on the router:
How to install on Asuswrt-Merlin
Enter this into your favorite SSH terminal:
/usr/sbin/curl -Os https://raw.githubusercontent.com/decoderman/amtm/master/amtm && sh amtm

Nothing happened...
And there is nothing in this folder to start.
How to start amtm after installation
Enter this into your SSH terminal:
/jffs/scripts/amtm

So this option would seem like a bust. So far I seem to have managed to install Entware but don't even know if I have managed to start the service. I have tried putting services-start.sh in the jffs/services folder but when I type top or ps I see no signs of it being there as a service.

I have spent all day trying to install this Entware and I am no closer to getting Mosquitto installed on the router. Is this Entware absolutely necessary to install Mosquitto because I don't know how many more hours I can waste trying to get to step one of the process.
 
Entware isn't a service so you won't see it running. Entware is a package manager that allows you to install other software.

If you look at the wiki for installing Entware the "easy way" on Merlin that is what you should have seen. It's literally one command. There's no need to manually create or edit files. If you followed other instructions it's likely that Entware has not installed properly. That is why I suggested you reformat your JFFS partition (Administration -> System) and install it properly.

If you want to enable the running of user scripts they must be enabled at Administration -> System on the webui.

After installation of Entware you can type "opkg" on the command line to verify that it's working.
 
/usr/sbin/entware-setup.sh
That just reinstalled the software exactly like the first time. (at least I know where to find the set up file now)

This is the bit that has me pulling my hair out...
Info: Add /opt/bin & /opt/sbin to your PATH variable
Info: Add '/opt/etc/init.d/rc.unslung start' to startup script for Entware services to start

the moment you try type cd opt it redirects you to the USB stick
me@myrouter:/tmp/mnt/usbstickname/entware#
so I ls- la to see what is there, no opt folder so I look for the next closest folder and cd /etc cd /init.d
to finally get to me@myrouter:/tmp/mnt/usbstickname/entware/etc/init.d# where I ls -la again and see the rc.unslung file.

Now I have searched and searched to see which files start the scripts and the only thing that seems to work on this firmware (plently of other reference folder that just aren't there)
is the instruction to put services-start in the /jffs/scripts folder.
So I created the file adding services-start.sh in the folder with the following content

#!/bin/sh
/tmp/mnt/usbstickname/etc/init.d/rc.unslung start

saved and restarted several times but had no joy in starting the service.... HOWEVER now that the software has reinstalled I now have three files in that folder I never had before post-mount, services-start, and services-stop all in yellow.

I type nano service-start to see what is in there and I get:

#!/bin/sh
RC='/opt/etc/init.d/rc.unslung'

i=30
until [ -x "$RC" ] ; do
i=$(($i-1))
if [ "$i" -lt 1 ] ; then
logger "Could not start Entware"
exit
fi
sleep 1
done
$RC start

Since rc.unslung is not in the /opt/etc/init.d/ folder I am going to add the path to where I found it /tmp/mnt/usbstickname/etc/init.d/rc.unslung and try reboot the router again to see if it picks it up this time. I might even try to reboot as is since this file has never been in this folder before now.
 
/opt is a symbolic link to where you installed Entware on your USB disk. So in your case /opt is the same as /tmp/mnt/usbstickname/entware. So you should be using /opt not /tmp/mnt/usbstickname/entware.
 
Entware isn't a service so you won't see it running. Entware is a package manager that allows you to install other software.

If you look at the wiki for installing Entware the "easy way" on Merlin that is what you should have seen. It's literally one command. There's no need to manually create or edit files. If you followed other instructions it's likely that Entware has not installed properly. That is why I suggested you reformat your JFFS partition (Administration -> System) and install it properly.

If you want to enable the running of user scripts they must be enabled at Administration -> System on the webui.

After installation of Entware you can type "opkg" on the command line to verify that it's working.

already enabled the scripts in the GUI. Just tried opkg (the missing link I have been searching for) and I got presented with a whole heap of options. If I am not mistaken this is a menu for Entware. I really hope so.

Unfortunately opkg list give me a verbose list from p all the way to z, I need to see the packages that are from A - P.
 
The answer was staring me in the face the whole time...

https://github.com/dersimn/owrtwifi2mqtt

Install the MQTT client
Install the packages
  • mosquitto-client
  • coreutils-nohup
with either luci or opkg.

All I needed was the key word OPKG to then find out there was an install option for me to simple type opkg install mosquitto-client and it work.
I'm not sure if opkg would still work without Entware, I really hope it doesn't because I would hate to find out I spent the whole day chasing my tail with the answer virtually in front of me.
 
I'm not sure if opkg would still work without Entware, I really hope it doesn't because I would hate to find out I spent the whole day chasing my tail with the answer virtually in front of me.
No it wouldn't. opkg is Entware.
 
opkg update
opkg list mosquitto*

I tried that but with ' ' around mosquitto works just like you typed.

Finally got this to work..
me@myrouter:/jffs/scripts# opkg install mosquitto-client
Installing mosquitto-client-nossl (1.5.7-1) to root...
Downloading http://bin.entware.net/armv7sf-k2.6/mosquitto-client-nossl_1.5.7-1_armv7-2.6.ipk
Installing libuuid (2.33-2) to root...
Downloading http://bin.entware.net/armv7sf-k2.6/libuuid_2.33-2_armv7-2.6.ipk
Installing libcares (1.15.0-4) to root...
Downloading http://bin.entware.net/armv7sf-k2.6/libcares_1.15.0-4_armv7-2.6.ipk
Installing libmosquitto-nossl (1.5.7-1) to root...
Downloading http://bin.entware.net/armv7sf-k2.6/libmosquitto-nossl_1.5.7-1_armv7-2.6.ipk
Configuring libuuid.
Configuring libcares.
Configuring libmosquitto-nossl.
Configuring mosquitto-client-nossl.
 
Step two was just like step one...

me@myrouter:/jffs/scripts# opkg install coreutils-nohup
Installing coreutils-nohup (8.30-1) to root...
Downloading http://bin.entware.net/armv7sf-k2.6/coreutils-nohup_8.30-1_armv7-2.6.ipk
Installing coreutils (8.30-1) to root...
Downloading http://bin.entware.net/armv7sf-k2.6/coreutils_8.30-1_armv7-2.6.ipk
Configuring coreutils.
Configuring coreutils-nohup.
me@myrouter:/jffs/scripts#

On a roll now, hopefully the rest of the instructions go easy.

Copy over the script
Use SCP to copy the presence_report script to /usr/bin/presence_report on the target device. Call chmod u+x /usr/bin/presence_report to allow script execution.

Add the script to rc.local
Place the following lines

  • nohup /usr/bin/presence_report event 192.168.1.2 >/dev/null 2>&1 &
  • nohup /usr/bin/presence_report lastseen 192.168.1.2 >/dev/null 2>&1 &
inside the /etc/rc.local file before the exit 0. You can to this via command-line or via LuCI in System -> Startup -> Local Startup. The script will be executed after reboot.

Usage
After installation the following topics will be published for each WiFi device, using the lowercase MAC address:

owrtwifi/status/mac-00-00-00-00-00-00/lastseen/iso8601

Payload contains the timestamp when the device was seen in an ISO 8601 (and OpenHAB) compatible format, like this: 2017-08-25T19:29:57+0200

owrtwifi/status/mac-00-00-00-00-00-00/lastseen/epoch

Unix epoch in seconds

owrtwifi/status/mac-00-00-00-00-00-00/event

Message will be new or del and is sent right after the device connected/disconnected to/from WiFi.
 
Those instructions are for OpenWRT not Asuswrt so you'll have to modify them accordingly.

/usr/bin is not a writable location. User scripts normally go in /jffs/scripts.

There's no direct equivalent to rc.local so you'll probably have to create a startup script and put it in /opt/etc/init.d.

EDIT: Glancing at the presence_report script I can see that it uses OpenWRT specific commands to query the wireless devices. These commands don't exist in Asuswrt so this script will have to be rewritten using different commands.
 

Similar threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top