Pappmaskin.no : Aka Morten Skoglys nerdcave
×

ReMorten v0.1 – Part 1

august 23rd, 2017 by

The ReMorten Project: A telepresence robot platform using nodejs running on the Raspberry Pi. Because why not.

Part 1: Snapping pictures using the Raspberry Pi, and exposing them outside your local network. A minimalist Peeping Tom system. It will also let me spy on my cat.

(Prerequsites: You’ve already got the Pi and the pi camera module up and running with Nodejs and npm installed. I use VNC viewer to connect to the Pi). You can purchase the camera module via eBay. This is the cheapest rpi2 I could find on eBay today

Make and enter a dir for your project and install node-raspistill:

npm install node-raspistill

make a file called interval.js and add this (taken straight from the node-raspistill example folder on Github):

1
2
3
4
5
6
7
8
9
10
11
12
const Raspistill = require('node-raspistill').Raspistill;
const raspistill = new Raspistill();
 
setInterval(function() {
    raspistill.takePhoto()
        .then((photo) => {
            console.log('took photo', photo);
        })
        .catch((error) => {
            console.error('something bad happened', error);
        });
}, 15000);

Run it by typing

node interval.js

Node-raspistill will create a subdirectory called photos, and start taking and adding pictures. Visit that dir to confirm that the pictures are showing up.

The easist way to serve the content of that directory as a webpage using http-server

sudo npm install -g http-server

Enter the photos directory and type:

http-server

You should see something like

Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
http://youriphere:8080

Now to the fun part.
To see the content of that folder from a machine outside your firewall/local network:

Go to ngrok.com and download the Linux Arm version of ngrok. Unpack the zip and type this in the terminal:

./ngrok http 8080

In the output from ngrok, find the Forwarding line, it looks something like this:

Forwarding: http://1234567.ngrok.io

where the 1234567 part will be unique every time you run ngrok (unless you make an account and pay them to get a permanent subdomain, which you should).

Visit that url on a remote machine outside your network to verify that it works. Refresh the page to see a list of newly added files.

Done.

Warning:
This is of course an insecure method that would leave your Pi and your network vulnerable, but it works well enough for testing purposes. Also: Leaving interval.js running willfill up your Pi until it dies, I suppose.

Next: Storing the images on Google Photo or another service with unlimited storage, and delete older images from the Pi to prevent it running full.

Posted in Code, Projects