Reviving the 4G-AC55U
I've long since given upon any professional use of the 4G-AC55U: when disconnecting, the unit would not reconnected. Totally unsatisfactory for control of field instrumentation. When we bought the cabin in Tynset, I installed the router there to have internet access for our Netatmo weather station.
Since I am logging the data from the weather station, I found it mildly annoying that the connection was dropped: I would loose all data until we visited the cabin next time. Then I started looking for a solution on the net. From gundersen.net I found that others was experiencing the same problem as me. On guy had solved this by having a WIFI power switch that would toggle the power supply to the router when the connection was dropped. He controlled the power switch from a Raspberry pi that would check for internet connection.
I did not find this solution elegant, so I kept looking for a way to reset the connection without having to power cycle the router. I found a command for connection reset: service restart_wan and was determined to pass this command to the router through ssh.
I found my old Raspberry Pi in the basement and updated it with the latest Raspbian. Unfortunately, I discovered that the stock firmware for the 4G-AC55U does not support ssh and I could not find custom firmware for this router, so using telnet made it a bit more tricky.
Basically, I made a script that crond runs every hour. It checks for internet connection and if connection is not established it will reset the connection:
#!/bin/sh
if ! ping -w 10 -c 10 www.google.com > /dev/null
then
eval "sleep 2; echo <user>; sleep 2; echo <password>; sleep 2; echo "service restart_wan"; sleep 2" | telnet 192.168.1.1;
fi
I found no way to get the IP address of the router from my IPS, so I resolved to make a reverse tunnel from the Raspberry to home. Autossh is an old friend I have struggled with before. Setting up a service with systemctl turned out to be easier than expected.
[Unit]
Description=Keep a tunnel to 'home' open
After=network-online.target
[Service]
Type=forking
User=<username>
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -f -N -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=false <username>@home -R 2049:localhost:22
ExecStop=/usr/bin/pkill -9 -u <username>
Restart=always
[Install]
WantedBy=multi-user.target
Next project is to buy a couple of power switches to control the heaters from home. When electricity pricing will include a power factor, slow heating of the cabin before we arrive will be beneficial. A web cam is also on the todo-list.
Since I am logging the data from the weather station, I found it mildly annoying that the connection was dropped: I would loose all data until we visited the cabin next time. Then I started looking for a solution on the net. From gundersen.net I found that others was experiencing the same problem as me. On guy had solved this by having a WIFI power switch that would toggle the power supply to the router when the connection was dropped. He controlled the power switch from a Raspberry pi that would check for internet connection.
I did not find this solution elegant, so I kept looking for a way to reset the connection without having to power cycle the router. I found a command for connection reset: service restart_wan and was determined to pass this command to the router through ssh.
I found my old Raspberry Pi in the basement and updated it with the latest Raspbian. Unfortunately, I discovered that the stock firmware for the 4G-AC55U does not support ssh and I could not find custom firmware for this router, so using telnet made it a bit more tricky.
Basically, I made a script that crond runs every hour. It checks for internet connection and if connection is not established it will reset the connection:
#!/bin/sh
if ! ping -w 10 -c 10 www.google.com > /dev/null
then
eval "sleep 2; echo <user>; sleep 2; echo <password>; sleep 2; echo "service restart_wan"; sleep 2" | telnet 192.168.1.1;
fi
I found no way to get the IP address of the router from my IPS, so I resolved to make a reverse tunnel from the Raspberry to home. Autossh is an old friend I have struggled with before. Setting up a service with systemctl turned out to be easier than expected.
[Unit]
Description=Keep a tunnel to 'home' open
After=network-online.target
[Service]
Type=forking
User=<username>
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -f -N -o ExitOnForwardFailure=yes -o ServerAliveInterval=30 -o ServerAliveCountMax=3 -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=false <username>@home -R 2049:localhost:22
ExecStop=/usr/bin/pkill -9 -u <username>
Restart=always
[Install]
WantedBy=multi-user.target
Next project is to buy a couple of power switches to control the heaters from home. When electricity pricing will include a power factor, slow heating of the cabin before we arrive will be beneficial. A web cam is also on the todo-list.
It turned out that "service restart_wan" was not failsafe as there appears to be several reasons why the modem looses connection. I inserted "reboot" in the script instead for now.
ReplyDelete