Tuesday, July 3, 2018

Mobile NAT

Cellular modems are really nifty in the sense that they give you internet access pretty much anywhere. Unfortunately, unless you pay for the expense of a business plan, this comes at the cost of not having a public IP address. Essentially the cellular networks operate just like a giant version of your home network; each modem gets assigned a private address that is NAT'd to a public address.

Usually this is OK as long as you're just making outbound connections (such as surfing the web). It does however make it very difficult to establish an inbound connection to a cellular modem from the public network, which we want to be able to do with the CabinPi in the event that we need to ssh into to check on things.

The solution we found was to use AutoSSH. In short, the CabinPi runs the AutoSSH daemon to ensure that there is always a persistent ssh tunnel open to a well known host on the Internet. You can then log into this well known host and then use that tunnel to connect back to the Pi.

Generally, I followed this guide to configure AutoSSH: SSH TUNNELLING FOR FUN AND PROFIT: AUTOSSH.

The final configuration that I used for autossh.service is:
[Unit]
Description=AutoSSH tunnel service
After=network.target

[Service]
User=autossh
Environment="AUTOSSH_GATETIME=0"
ExecStart=/usr/bin/autossh -M 0 -q -N -o "ServerAliveInterval 60" -o "ServerAliveCountMax 3" -o "ExitOnForwardFailure=yes" -NR 2222:localhost:22 [email protected]

[Install]
WantedBy=multi-user.target

In general it has worked pretty well and considering that I can ssh to a device up in the mountains it's pretty impressive.

Monday, September 11, 2017

Help! I Can't Reach the Power Switch

Pi is going to live in a remote location keeping it up and responding is better than a long drive just to press a reboot button. The watchdog service is going to help us out by rebooting the system when one of it's tests gets triggered.

Outline of Actions

  1. Turn on watchdog hardware
  2. Install Service
  3. Configure watchdog tests
  4. Run service
  5. Setup service to run on boot

Action Details

1. Turning on the hardware

Modify system config
sudo nano /boot/config.txt
Add this:
# turn on the hardward watchdog 
dtparam=watchdog=on
After reboot you should see watchdog listed (I don't know why there are two)
$ ls -al /dev/watchdog*
crw------- 1 root root  10, 130 Sep 11 15:38 /dev/watchdog
crw------- 1 root root 252,   0 Sep 11 15:38 /dev/watchdog0

2. Install the software

sudo apt-get install watchdog

3. Enable the tests

sudo nano /etc/watchdog.conf
uncomment a few lines
max-load-1      = 24
min-memory      = 1
watchdog-device = /dev/watchdog

4. Run the Service

sudo systemctl start watchdog
sudo systemctl status watchdog

5. Run on Boot

sudo nano /lib/systemd/system/watchdog.service
 
Change WantedBy to this:
[Install]
WantedBy=multi-user.target
 
And Enable
sudo systemctl enable watchdog

Resources

Enabling Watchdog on Raspberry Pi by Abdullah Bashir
Is this the correct way to install the watchdog package? by paulv 

Friday, September 8, 2017

Cellular Modem on the Pi

Our first attempt at adding WAN connectivity to the Pi failed because we didn't have a proper antenna connection, and we were on site so there was no Radio Shack (ha!) to run to. With the Novatel in pieces after half-assed attempts to solder hair-like antenna leads to gnat-sized antenna ports failed, it was time to order a new modem.

Cabin Pi

For our first public project, FPHI is working on the creation of an off the grid cabin monitoring system. At it's core, a Raspberry Pi 3 will monitor environmental and cabin systems and make the information available to the public.

Here's the current plan.

Environmental inputs:

  • Interior Temperature
  • Exterior Temperature
  • Humidity
  • Barometric Pressure
System Input:
  • From the charge controller, read the solar cell and battery levels
  • Monitor the power consumption of the Pi itself
Output:
  • Write the collected data to a remote InfluxDB, for rendering with Grafana.
  • Take occasional pictures (using the Pi Cam) and post to "the cloud".
Connectivity:
  • Use a cellular modem to transfer data out and provide remote shell capability

So that's the nutshell summary. We'll use this space to record the difficulties in achieving these goals.