Categories
Connected Farm

Resolving issues with running a Raspberry Pi Zero and Huawei HiLink 3G Dongle 24/7

After weeks of testing the MySensors Remote Gateway Raspberry Pi Zero with Huawei 3G dongle I was having frequent connectivity issues, after 2 to 3 days the connection would just drop and not reconnect without a hard reset. The issue would seem to be that the dongle is just not designed to run 24/7 and will eventually disconnect itself.

I tried using Cron in the Pi OS to schedule reboots daily but this did not work as this particular 3G dongle has its own MCU and requires a reboot itself. On the Raspberry Pi Zero the USB power is hardwired to the PSU connector which means soft reboot of the Pi will not reset the dongle. Some of the other Raspberry Pi models however can control power to the USB port using software.

I had a few other models of old Huawei and TP-Link 3G dongles but each had their own issues, some would not connect at all, others were even more unstable causing unexpected reboots of the Pi Zero. As this project is running from solar power I wanted to stick with the Raspberry Pi Zero in order to be as power efficient as possible.

My solution, is a bit of a hack but has been stable since it was implemented over a week ago, I’ve setup a daily reboot with Cron, but before rebooting I use Cron and WiringPi to switch off power to the USB dongle using a simple relay module. I’ve used a double relay module here as I had it already but only one relay is required.

First off I had to install WiringPi.

sudo apt-get install wiringpiCode language: JavaScript (javascript)

Then schedule the relay to switch off and the Raspberry Pi to reboot using Cron.

sudo crontab -e

The following was added to the end of the file.

0 5 * * * /usr/bin/gpio mode 21 out
30 5 * * * /sbin/shutdown -r now
Code language: JavaScript (javascript)

This will switch off the relay at 05:00 and reboot the Raspberry Pi at 05:30, I’ve left 30min between the 2 actions but I’m sure it could be shortened if necessary. The relay is connected to WiringPi pin 21 which is actually physical pin 29.

I’ve also added the following automation to my Home Assistant to ensure it maintains connectivity after the gateway restart, again times can probably be shortened to within a few min.

- alias: Restart HA
  trigger: 
    platform: time
    at: "06:00:00"  
  action:
    - service: homeassistant.restartCode language: CSS (css)

The Gateway also required a more suitable IP rated case so I went with an outdoor 2 gang junction box.

Facebook Comments