Pushing notifications from home network to cell phone
#1
This may be one of those uses that most people wouldn't find too useful, but I thought I'd share the setup since it helped me to solve a problem that had stumped me for awhile.

There are various reasons one might want to push notifications from your home network to your mobile device (notifying of changes in your dynamic IP address, alerts from smart home sensors/smoke alarms/security alarms, etc.), and while there are some easy ways to do this using third-party services, I dislike solutions that rely on third parties too much.

So for this example, I check whether my ISP has changed my home IP address, and if it has, I push a notification to my cell phone in the form of a text file with the new IP address. For the Pine, I'm using the latest Debian image from here, with Tor installed:

Code:
sudo apt-get install tor

Then, on my Android phone I have installed SSHelper, which I obtained via the f-droid repositories, but you can also install from the Play Store I believe. I also have installed Orbot, which I recommend getting from the official Guardian Project repository rather than the Play Store, though I believe it is also there.

To set up SSHelper to run as a hidden service, you will need to open the settings dialog in Orbot, and scroll down to the Hidden Service Hosting section, and check the box for Hidden Service Hosting. Click on Hidden Service Ports and pick whatever port you have selected in SSHelper (for this example I'm using the default, 2222). Next, you need to shut down Orbot and restart it so that it will generate your .onion address. Go into the hidden service settings again, click on the .onion hostname, and copy that address. You might want to write it down or save it as a text file since you'll need it later.

Next, on the Pine, attempt to access the Android phone using the .onion hostname:

Code:
torsocks ssh -p 2222 123456abcde.onion

Once you've confirmed this works, you need to set up the SSH server to use  a keypair instead of password, so on the Pine type these two commands:

Code:
ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ''
torsocks ssh-copy-id -i ~/.ssh/id_dsa.pub -p 2222 12345abcdef.onion

Type in the password when it prompts you, then exit once the devices finish the key exchange. Now, on the Android phone, enter the SSHelper settings and check the box Disable password logins.

Next, I wrote a perl script that checks with a public site and creates a text file containing the IP, as well as a log of prior IPs and when they changed:

Code:
#!/usr/bin/perl -w

use strict;

my $nip;
my $now = localtime();
my $ipcheck = "http://ipecho.net/plain";
my $result = qx{curl --silent $ipcheck};

if($result =~  m/(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/) {
 $nip = $1;
}
else { die "regex failed to match an IP: $!"; }

open(LAST, "<lastip") or die "Can't open lastip";
my $lastip = <LAST>;
close(LAST);

unless($lastip eq $nip) {
open(LAST, ">lastip") or die "Can't open lastip";
print LAST $nip;
close(LAST);

print qx{torsocks scp -P 2222 /home/pineuser/lastip 12345abcdef.onion:/sdcard/ipchecker/};
open(LOG, ">>history") or die "Can't open history";
print LOG "$nip\t[$now]\n";
close(LOG);

print qx{torsocks scp -P 2222 /home/pineuser/history 12345abcdef.onion:/sdcard/ipchecker/};
}
else {
open(CHECKED, ">checked") or die "Can't open checked";
print CHECKED $now;
close(CHECKED);
print qx{torsocks scp -P 2222 /home/pineuser/checked 12345abcdef.onion:/sdcard/ipchecker/};
}

Now, all that's left is to create the three files and set the script to run periodically via crontab:

Code:
touch lastip history checked
crontab -e

I set the cronjob to run hourly at five past the hour (because why not?), but obviously anything would work:

Code:
5 * * * * /home/pineuser/notifier.pl

Assuming everything went smoothly, you should have three files created in your SSH root directory: checked lets you know how recently it was checked, lastip should be the most recent IP address, and history should list each prior IP address.

As I indicated at the beginning, this particular script is just an example of one use, but once you have the SSH hidden service running, you can push any notifications or files you might want to that folder.


Messages In This Thread
Pushing notifications from home network to cell phone - by wahdooyah - 05-30-2016, 08:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  PINE64 to allow use of SATA disk on network/FTP mwelbourne 10 17,337 11-18-2019, 04:09 PM
Last Post: evilbunny
  AIY - Google Home jauyzed 3 8,406 11-05-2017, 01:16 AM
Last Post: dkryder
  Creating a phone with the Pine64 and need a bit of help CHAOZM4 4 8,323 09-24-2016, 01:21 PM
Last Post: ltorsini
  Home Automation. MokaMx_GDL_DE 1 3,992 06-30-2016, 02:58 AM
Last Post: bonterra
  Home Media Center Myszaks 2 5,688 03-24-2016, 08:46 AM
Last Post: GoZone
  NVR (network video recorder) batrad 1 4,133 03-09-2016, 01:44 PM
Last Post: tllim
  Smart home on PINE A64 SystemDi 7 12,513 02-09-2016, 01:08 AM
Last Post: tllim

Forum Jump:


Users browsing this thread: 1 Guest(s)