Example: Security Camera

In this example we will develop a surveillance system that will save movies and snapshots when it detects movement. The pictures and movies will be then uploaded to Oficloud. This way, your pictures and movies will be saved in the cloud to remain safe in case someone steals the camera, but these will not be accessible to the cloud administrators. All your pictures and movies will remain private.

The materials needed are:

  • A Raspberry Pi model 3 B (or B+). That will be your gateway.
  • At least one camera connected to the gateway. It can be a USB camera or a special camera for the Raspberry Pi.

Some tested cameras:

SQ11 Mini Camera
Papalook PA452 Webcam 1080P


1. Create folder
Create a folder in your Oficloud account where you will save the files.

2. Create user
Create a new user in your Oficloud account.

3. Create folder for new user
Create a folder in the account of the new user where you will store your files. Change permissions of that folder to allow the second user to write on it but deny all other permissions. Allow all permissions to the main user.

4. Mount SD image
Mount an SD card with an image obtained from here. That image contains a installed Linux OS, the motioneye open source software and the Oficloud Sync client. We will use motioneye software to capture movies and save them to the /home/user/Documents/motioncaptures folder. Then we will use the Oficloud Sync client to upload these files to the cloud. Then a script will move your files from the folder where they were uploaded to the folder in your main account. This way, even if someone steals the gateway and finds the password, he won't be able to access the folder in which your files are.

5. Run VNC server
Connect through an SSH session to the gateway and execute this command to run a VNC server.
$ x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth /home/tester/.vnc/passwd -rfbport 5900 -shared
Alternatively, you can connect the gateway to a screen with an HDMI cable and avoid steps 5 and 6.
Access credentials:
user: user
password: ofi1111

Remember to change the password after first use.

6. Connect to VNC
Connect to the server with a VNC client from another computer.

7. Login to Sync
Open the Sync tool in the gateway and login to the account of the new user that you created.

8. Sync folder
Sync the folder in that account to the /home/user/Documents/motioncaptures folder in the gateway.

9. Edit script for moving files
Edit the /home/user/oficloud_projects/movefiles/main.js script to set your settings for the script that will move your files. This script is called periodically by a cron job.

var oficloud = require('./oficloud');

const DIR1=5795; //folder id in main account
const DIR2=5880; //folder id in second account

oficloud.login('myuser@myemail.com','MYPASSWORD',function(res){ //login to second account
        console.log("login res: "+res.desc);

    console.log("login res: "+res.res);
        console.log("list dir res: "+res);
        var bend=false;
        var d=null;          
        for(var i=0;i<res.list.length && !bend;i++)
            if(d.tipo=="image/jpeg" || d.tipo=="video/x-msvideo")
                    console.log("move res: "+res);

10. Done
You can now login from any computer to your main account and watch your files in the folder that you created in step 3.

11. MotionEye panel
You can also connect to the MotionEye admin panel with a browser if you want. The address is the IP of your gateway plus port 8765: http://your_ip:8765
The access credentials are:
user: admin
password: ofi1111

You should change password if your gateway is not in a private network or if it's accessible from the Internet.
TIP: Don't be too ambitious with the MotionEye settings. We have checked that it works indifinitely with a 320x200 resolution, but the Raspberry Pi may not have enough CPU for higher resolutions.