Bananus Kamerus v1.0!

Its been many years since the last time I wrote about something I built in a blog. But here goes!

Because I busted my Sony a77, and Raspberry Pi announced their HQ Camera, I figured I’d make a tiny WiFi controlled time-lapse device with a web interface. Y’know, to make life easier.

Disclaimers:

  • In this guide, I’ll assume you have some technical background.
  • I might skip some steps because they’re either explained in details in links I’d provide, or they’re really easy to go through.
  • If you find an opportunity to change a password to something you like, please do. I’m using almost default passwords only because I’m lazy.
  • Don’t connect this device to the internet (Or, don’t let it serve internet access). There are so many bad security configurations because I haven’t done Linux security, which I may or may not work on in later revisions.
  • I suck at PHP. Many friends suggested I use an existing platform Laravel, but figured I’d do a boatload of echos instead to minimize size consumed by PHP/System files and because I don’t use any SQL database. But yeah I’m a horrible PHP developer.

What you’ll need:

  • A Raspberry Pi (3+ or better).
  • A micro-SD card (Be generous) and a reader.
  • A camera (Built with HQ Camera).
  • A C/CS lens (I used this one).
  • A good battery. One that can deliver 5v at 2.5 Amps.
  • A good Type-A to Type-B Micro USB cable (Fancy way of saying Micro USB cable).
  • A tripod.
  • A computer to do things.
  • Ethernet connection to your Raspberry Pi.

Download things!

  • Download a Raspberry Pi image. I personally went with the Lite one to minimize storage use.
  • Download Rufus so you can load it in your micro-SD card.

Do the first things!

  • Extract the downloaded Raspberry Pi image, load the ISO file in Rufus, choose the relevant micro-SD card, then start the process.
  • Once you’re done, insert it in the Raspberry Pi and start it.
  • Connect the Raspberry Pi to your router (Or access point) through Ethernet (Since we’ll use WiFi as an access point), and a screen and keyboard. Although, if you feel adventurous and SSH to it, you do you.
  • Once you’re prompted to log in, user this combination:
    • Username: pi
    • Password: raspberry
  • First thing you do is to update stuff. Run the following:
    • sudo apt update
    • sudo apt upgrade
    • sudo apt full-upgrade
  • Download zip/unzip:
    • sudo apt install zip unzip

Do the camera thing!

  • Now we enable the camera port:
    • sudo raspi-config
    • Then choose ‘Interface Options’ > ‘Camera’ > ‘Enable’
  • Reboot by writing ‘sudo reboot

Do the nginx thing!

  • Now we install nginx:
    • sudo apt install nginx
    • Then we start the server by running ‘sudo /etc/init.d/nginx start‘ (Or if you want to use systemctl since init.d is being depricated, this: sudo systemctl start nginx)

Do the PHP thing!

  • sudo apt install php-fpm
  • Enable PHP in nginx
    • cd /etc/nginx
    • sudo nano sites-enabled/default
    • Find the line ‘index index.html index.htm;‘, and add ‘index.php‘ next to ‘index
    • Remove the ‘#‘ on these lines:
      location ~ \.php {
      include snippets/fastcgi-php.conf;
      fastcgi_pass unix:/var/run/php7.3-fpm.sock;
    • Save the file by pressing CTRL+X
  • Reload the configuration file ‘sudo /etc/init.d/nginx reload
  • Just to make sure things work, do the following:
    • cd /var/www/html
    • sudo nano index.php
    • Write: <?php echo phpinfo(); ?> (Just to display PHP info)
    • Save the file by pressing CTRL+X
    • Open the raspi’s IP Address in a browser (You can get it through ifconfig eth0)

Do the FTP thing!

Disclaimer: The FTP part here is taking ease of use into consideration, not security. In fact, the security in this part is potato since this device is NOT meant to connect to the internet. If you want to have your own method, skip the FTP part.

  • Once you get the PHP thingy running fine, we’ll get FTP running. The reason you’d want an FTP is to both upload PHP files and to download pictures easier. If you don’t like FTP, skip this series of steps and implement your own way of uploading/downloading files.
    • Install pure-ftpd: sudo apt install pure-ftpd
    • Create group ‘ftpgroup’: sudo groupadd ftpgroup
    • Add the user ‘ftpuser’ to that group: sudo useradd ftpuser -g ftpgroup -s /sbin/nologin -d /dev/null
    • Change ownership of /var/www to ‘ftpuser’: sudo chown -R ftpuser:ftpgroup /var/www (So that FTP goes directly to /var/www folder for ease of use. Security-wise, this is potato).
    • Add a virtual user to upload files named ‘upload’: sudo pure-pw useradd upload -f ftpuser -g ftpgroup -d /var/www
    • Choose a password for the ‘upload’ account
    • Set up the virtual user database: sudo pure-pw mkdb
    • Set up the authentication method: sudo ln -s /etc/pure-ftpd/conf/PureDB /etc/pure-ftpd/auth/60puredb
    • Restart pure-ftpd: sudo services pure-ftpd restart

Do the hotspot!

  • Install ‘hostapd’: sudo apt install hostapd
  • Enable and autostart hostapd on boot:
    • sudo systemctl unmask hostapd
    • sudo systemctl enable hostapd
  • Install ‘dnsmasq’ to enable DHCP: sudo apt install dnsmasq
  • Set up firewall rules to be persistent: sudo DEBIAN_FRONTEND=noninteractive apt install -y netfilter-persistent iptables-persistent
  • Configure DHCP: sudo nano /etc/dhcpd.cong
    • At the end of the file, add the following (choose a number between 0 to 255 as xxx, and 1 to 254 as yyy. Its usually 192.168.1.1/24, but choose what fits you):
      interface wlan0
      static ip_address=192.168.xxx.yyy/24
      nohook wpa_supplicant
    • Save the file by pressing CTRL+X
  • Backup the original ‘dnsmasq’ default configuration file, then edit the default one:
    • sudo mv /etc/dnsmasq.config /etc/dnsmasq.config.backup
    • sudo nano /etc/dnsmasq.config
    • Add the following to it:
      interface=wlan0
      dhcp-range=192.168.xxx.fff,192.168.xxx.lll,255.255.255.0,24h
      domain=wlan
      address=/*****.wlan/192.168.xxx.yyy
    • Save the file by pressing CTRL+X
      Please note that:
      • xxx is the same chunk from the IP Address you chose up
      • fff is the first IP Address you want guests/clients to use while connecting, since we’re going for a range
      • lll is the last IP Address of that range
      • ***** is the hostname you want your Raspberry Pi use. You can use bananus or anything you like. Just be sure to include .wlan in the end
  • Now let’s make sure that WiFi isn’t blocked: sudo rfkill unblock wlan
  • Now let’s configure the hotspot’s stuff:
    • sudo nano /etc/hostapd/hostapd.conf
    • Scroll down to these lines and edit them accordingly:
      • ssid=NNNN, where ‘NNNN‘ is the SSID you want it to broadcast
      • wpa_passphrase=PPPP, where ‘PPPP‘ is a password from 8 to 64 characters long (Don’t include quotes in them)
      • wpa_key_mgmt=WPA-PSK
      • Save the file by pressing CTRL+X
  • Now let’s reboot our device: sudo systemctl reboot

Do the housekeeping!

Now we’re going to do a lot of horrible, HORRIBLE security fixes to make things work.

Remember, this is not meant to be secure or safe. This device is meant to be used without any internet access and on the go. Maybe I’ll add more screws into the security part, but I’m focusing more on functionalities and features than securities and performance tweaks (For now).

  • Let’s start, do the following:
    • sudo nano /etc/sudoers
    • Add this at the end of the file: www-data ALL = NOPASSWD: /sbin/shutdown, /sbin/ifconfig, /sbin/iwconfig, /var/www, /bin/systemctl, /sbin/systemctl, /bin/sed
    • Save the file by pressing CTRL+X
  • Clone this GitHub project, copy the html folder to /var/www/html. Make sure that all the content is in /var/www/html, not /var/www/html/Bananus.
  • Let’s fix (Or butcher) things:
    • sudo chmod 777 /var/www/html/pictures
    • sudo chmod 777 /dev/vchiq
    • sudo usermod -aG video www-data

How does the UI look like?

Result?

This is a video I made from 459 pictures taken by “Continuous mode” with (I think) 5 seconds gap. I’m not sure, I don’t really remember.

The little blur is due to focus stuff (Since its a manual focus thing), and the little black dots you see is because the lens is dirty because, well, I realised how dirty the lens later.

What’s next?

There are things that I’d like to add later on:

  • Support for videos.
  • Video live preview instead of a frame to refresh a capture.
  • More control in terms of composition (Brightness, sharpness, and so on).
  • Manual mode.
  • Removing useless system components.
  • Compressing pictures and FTP are slow, so maybe NFS and SMB support?
  • Better writing. I definitely write like a potato.

Links that helped: