Building a Circuit communication device using Raspberry PI

Building a Circuit communication device using Raspberry PI

This article intends to show the Circuit SDK’s portability and how it can be easily integrated with inexpensive hardware to build all kind of communication devices.

This article intends to show the Circuit SDK’s portability and how it can be easily integrated with inexpensive hardware to build all kind of communication devices.

Circuit is a team collaboration software supporting chat, voice, video, screen share and much more. It’s available on the browser, as desktop application, iOS and Android. The free version allows up to 100 users and 3 users per conference call without any feature limitation.

For an introduction to Circuit APIs you may want to read this article.

Circuit Receptionist Kiosk

This application can be ideal for office buildings with restricted access and without a human receptionist. This is how it works:

When the application starts (kiosk mode), it presents a splash screen (or idle screen) while it initializes all sensors, logs into Circuit, and updates the bottom bar with date, time, temperature and humidity.

When the presence of the visitor is detected, the application shows several options such as start typing the name, speak the name, or calling the receptionist. The receptionist is actually a Circuit group conversation where any of the participants can answer the call.

As the visitor types, a user search is requested to the back end and results are presented on the screen. For every change in the search string a new search is performed, and any previous pending search is cancelled.

Once the user search is successful the visitor taps on the user’s avatar and the application sets up a video call with the Circuit user.

The user inside the office, is alerted of the incoming call and is allowed to answer it using just voice or video.

Once the Circuit user answers the call, video and voice communication is established.

At the same time the Circuit user is prompted with two options, reject the visit and terminate the call, or allow access to the visitor. When the Circuit user clicks on the option to allow access, the device unlocks the door, and the video call is terminated.

About the hardware

Below is the list of the hardware components with a brief description. If you are already familiar with these components just refer to GitHub for the complete list.

Raspberry Pi: The Raspberry Pi is a small, affordable, and amazingly capable, credit card size computer. It is developed by the Raspberry Pi Foundation, and it might be the most versatile tech ever created. At the time of these writing you can buy it for less than US$40.-

Raspberry Pi 7" Touchscreen Display: Raspberry Pi touchscreens can be easily connected using a DSI ribbon cable and be powered from the GPIO. The full color display outputs up to 800 x 480 and features a capacitive touch sensing capable of detecting 10 fingers. It costs about US$70.-

When using the touchscreen display, a suitable case to house both the Raspberry Pi and the display makes it safer to handle. There are a couple of inexpensive options out there.

MicroSD Card: This is the persistent storage for the Raspberry Pi. Although 8Gb should be enough for this project, 16Gb is recommended. The adapter may come handy to flash Raspbian on a computer with a regular SD card reader slot.

Raspberry Camera Module (V2): The Camera Module can be used to take high-definition video, as well as stills photographs. It’s easy to use for beginners, but has plenty to offer advanced users. It is connected to the Raspberry Pi using a CSI ribbon cable. In this project we will use the camera module to stream the reception feed when the call between the visitor and the Circuit user is established. You can learn more about the Raspberry Camera Module on the Raspberry Pi Foundation.

Breadboard: Although not necessary, it is very convenient to quickly setup the electronic circuit, specially if soldering is not your thing. If you use a breadboard you will find the breadboard extension for the Raspberry Pi GPIO (General Purpose Input Output) very convenient. Also some jumpers (male-male and female-male) are needed.

Speaker and Microphone: Both are needed for this project and here you may have several options. Computer speaker with a 3.5mm jack, USB speakers or microphones, headsets or any combination. You may even use a webcam with microphone if you do not count with the Raspberry Camera Module.

Infrared Motion Sensor: This sensor is used to detect the presence of the visitor and switch the user interface view accordingly. I used HC SR501 which is inexpensive and can be adjusted for sensitivity and output timing using the on board variable resistors.

Green LED: Not strictly necessary. In my project the LED flashes when the app is listening the visitor speak the name she is looking for. It also remains ON when the door is being unlocked.

Active Buzzer: The active buzzer is a placeholder. It represents whatever relayed mechanism would be needed to unlock a door. Any real application may need different electronic components to achieve that objective.

Hygrotermograph Sensor: This sensor provides information about the temperature and humidity in the room. Not very functional to this specific application but I decided to include just because… I can. I used the inexpensive DHT11. You can use any other, or none.

Other components: If you use all the same sensors, LED and buzzer you will need one NPN transistor (S8050) and three resistors (1KΩ, 10KΩ, and 220Ω).

Electronic Circuit Schematic Diagram: Below you can see how the components shall be connected. You may use different GPIO pins, just remember to update the code in gpioWrapper.js

About the software

Operating System: The Raspberry Pi runs Raspbian Stretch with is the latest version of the Debian Linux distribution specifically for Raspberry Pi.

Framework: The application is a nodejs process using electron to have access to Chromium WebRTC APIs needed by the Circuit SDK to established a WebRTC communication. So, it is not an actual electron desktop application… but it could have been as well.

Caution: the nodejs (and npm) versions on the Debian repository are not the latest and this project needs the latest ones, so do not use apt-get, instead follow the instructions on my GitHub repository.

Vue: Although I am more familiar with AngularJS, I decided to go with Vue to handle the user interface. Vue is very lightweight in comparison and has a quick learning curve.

BCM2835: bcm2835 library. This C library for Raspberry Pi provides access to GPIO and other IO functions on the Broadcom BCM 2835 chip. Instructions to download and build the library can be found also on my GitHub repository.

Google Cloud Services: As I mentioned before the visitor can type on the touch screen to find the Circuit user, or just speak the name. For transcription I decided to use Google Cloud Speech API. The setup is outside the scope of this article but can learn all you need to know for this application with the Google Cloud Speech Quick Start. For speech recording I used sox.

Circuit SDK usage

On the GitHub circuitKiosk repository you will find examples on how to use some of the capabilities of the Circuit platform using the Javascript SDK. You will see how to instantiate the Circuit client, set the log levels, add event handlers, log your application, search for users, and process those search results. You will also learn how to find and create Circuit conversations, send text items, and process received ones. The application also makes use of Circuit forms that are sent as text items. Forms submissions are received as text items, and you will see how to process them. In the code you will also find how to setup a video call, process call events and handle the call media by getting the remote streams from the instantiated Circuit client.

Let’s see some specific examples:

In order to instantiate a Circuit client your code will look something like this:

gistfile1.txt

Circuit.logger.setLevel(Circuit.Enums.LogLevel.Debug);
let client = Circuit.Client({
        "client_id": "your-client-id",
        "client_secret": "your-client-secret",
        "domain": "circuitsandbox.net"});

Notice on line #1 the Circuit log level is set.

Besides logging in your application into Circuit, this has to add event handlers. Circuit raises a ton of different events. For this application we are just interest in a few of them.

gistfile1.txt

     client.addEventListener('itemAdded', processItemAddedEvent);
        client.addEventListener('itemUpdated', processItemUpdatedEvent);
        client.addEventListener('callStatus',processCallStatusEvent);
        client.addEventListener('callEnded',processCallEndedEvent);
        client.addEventListener('callIncoming', processCallIncomingEvent);
        client.addEventListener('formSubmission', processFormSubmission);
        client.addEventListener('basicSearchResults', evt => {
            processSearchResults(evt.data).then(users => {
                app.setUsers(users);
            });
        });
        client.addEventListener('searchStatus', evt => {
            processSearchStatus(evt.data).then(users => {
                if (users) {
                    app.setUsers(users);
                }
            });
        });

Basically the application needs to listen for new text items for maintenance commands, call events to handle WebRTC communications, formSubmission events to accept a command for a Circuit user (i.e. unlock the door), and search results to find specific Circuit users.

Finding a Circuit user it is an asynchronous process. So the application invokes the startUserSearch API, and wait for the corresponding events with the search results for which we already set the listeners above.

gistfile1.txt

let searchId = client.startUserSearch(searchString);

Once the user is found and selected to establish a communication the one to one conversation between the user and the application needs to be find, and if it doesn’t exist, then it needs to be created. Once the conversation is known then the call can be made. However, the SDK API makeCall does all this for you. You just need to know the id of the user destination of the call.

gistfile1.txt

client.makeCall(user.userId, {audio: true, video: true}, true);

As the call is being setup Circuit will raise callStatus events that need to be handled accordingly to properly setup the user interface and, eventually when the call is answer set the audio and video elements sources with the remote streams.

gistfile1.txt

    async function setupMedia(call) {
        let remoteStreams = client.getRemoteStreams(call.callId);
        let remoteAudioStream = remoteStreams.find((s) => s.getAudioTracks().length > 0);
        document.querySelector('audio').srcObject = remoteAudioStream;
        if(call.remoteVideoStreams && call.remoteVideoStreams.length) {
            Vue.nextTick().then(() => {
                document.querySelector('video').srcObject = call.remoteVideoStreams[0].stream;
             });
        }
        sendOpenDoorForm(call.convId);
    };

Now the call is setup and both parties can talk and see each other. Note line #10, here the application will send a form to the user with two buttons, one to unlock the door, and the other to reject the visitor by terminating call. Circuit SDK makes it easy to submit a form as a text message using the addTextItem API.

gistfile1.txt

    async function sendOpenDoorForm(convId) {
        await client.addTextItem(convId, {
            content: 'Select "Open Door" or "I do not know this person"',
            form: {
                id: 'openDoorForm',
                controls: [{
                    type: Circuit.Enums.FormControlType.BUTTON,
                    name: 'openDoor',
                    options: [{
                        text: 'Open Door',
                        notification: 'Opening Door',
                        value: 'openDoor'
                    }, {
                        text: 'I do not know this person',
                        value: 'endCall',
                        notification: 'Access Denied'
                    }]
                }]
            }
        });
    };

Finally as the user chooses to unlock the door for the visitor the application will process the form result.

gistfile1.txt

    function processFormSubmission(evt) {
        logger.info(`[RENDERER] process form submission. ${evt.form.id}`);
        evt.form.data.forEach(ctrl => {
            logger.debug(`${ctrl.key}: ${ctrl.value}`);
            switch (ctrl.name) {
                case 'openDoor':
                    switch(ctrl.value) {
                        case 'openDoor':
                            openDoor();
                            break;
                        case 'endCall':
                            break;
                        default:
                            logger.error(`Unknown value in submitted form: ${ctrl.value}`);
                            return;
                    }
                    app.currentCall && client.leaveConference(app.currentCall.callId);
                    client.updateTextItem({
                        itemId: evt.itemId,
                        content: (ctrl.value === 'openDoor' ? 'Door has been opened' : 'Entrance denied'),
                        form: {
                            id: evt.form.id
                        }
                    });
                    break;
                default:
                    logger.error(`Unknown key in submitted form: ${ctrl.key}`);
                    break;
            }
        });
    };

Let’s build it

Just follow the step-by-step instructions on GitHub circuitKiosk repository README.md . Here is a short video demonstration:

As you may already know the only limitation is your imagination. All the parts are out there, get them and build something cool and you will learn a lot in the process, after all there are only two kinds of adventure in life: love and knowledge.

30s ad

Raspberry Pi 3 Day Project: Retro Gaming Suite

Raspberry Pi Projects : Build a Media Centre Computer

Build Your Own Super Computer with Raspberry Pis

PiBot: Build Your Own Raspberry Pi Powered Robot

Internet of Things (IoT) Automation using Raspberry Pi 2

This article intends to show the Circuit SDK’s portability and how it can be easily integrated with inexpensive hardware to build all kind of communication devices.

Circuit is a team collaboration software supporting chat, voice, video, screen share and much more. It’s available on the browser, as desktop application, iOS and Android. The free version allows up to 100 users and 3 users per conference call without any feature limitation.

For an introduction to Circuit APIs you may want to read this article.

Circuit Receptionist Kiosk

This application can be ideal for office buildings with restricted access and without a human receptionist. This is how it works:

When the application starts (kiosk mode), it presents a splash screen (or idle screen) while it initializes all sensors, logs into Circuit, and updates the bottom bar with date, time, temperature and humidity.

When the presence of the visitor is detected, the application shows several options such as start typing the name, speak the name, or calling the receptionist. The receptionist is actually a Circuit group conversation where any of the participants can answer the call.

As the visitor types, a user search is requested to the back end and results are presented on the screen. For every change in the search string a new search is performed, and any previous pending search is cancelled.

Once the user search is successful the visitor taps on the user’s avatar and the application sets up a video call with the Circuit user.

The user inside the office, is alerted of the incoming call and is allowed to answer it using just voice or video.

Once the Circuit user answers the call, video and voice communication is established.

At the same time the Circuit user is prompted with two options, reject the visit and terminate the call, or allow access to the visitor. When the Circuit user clicks on the option to allow access, the device unlocks the door, and the video call is terminated.

About the hardware

Below is the list of the hardware components with a brief description. If you are already familiar with these components just refer to GitHub for the complete list.

Raspberry Pi: The Raspberry Pi is a small, affordable, and amazingly capable, credit card size computer. It is developed by the Raspberry Pi Foundation, and it might be the most versatile tech ever created. At the time of these writing you can buy it for less than US$40.-

Raspberry Pi 7" Touchscreen Display: Raspberry Pi touchscreens can be easily connected using a DSI ribbon cable and be powered from the GPIO. The full color display outputs up to 800 x 480 and features a capacitive touch sensing capable of detecting 10 fingers. It costs about US$70.-

When using the touchscreen display, a suitable case to house both the Raspberry Pi and the display makes it safer to handle. There are a couple of inexpensive options out there.

MicroSD Card: This is the persistent storage for the Raspberry Pi. Although 8Gb should be enough for this project, 16Gb is recommended. The adapter may come handy to flash Raspbian on a computer with a regular SD card reader slot.

Raspberry Camera Module (V2): The Camera Module can be used to take high-definition video, as well as stills photographs. It’s easy to use for beginners, but has plenty to offer advanced users. It is connected to the Raspberry Pi using a CSI ribbon cable. In this project we will use the camera module to stream the reception feed when the call between the visitor and the Circuit user is established. You can learn more about the Raspberry Camera Module on the Raspberry Pi Foundation.

Breadboard: Although not necessary, it is very convenient to quickly setup the electronic circuit, specially if soldering is not your thing. If you use a breadboard you will find the breadboard extension for the Raspberry Pi GPIO (General Purpose Input Output) very convenient. Also some jumpers (male-male and female-male) are needed.

Speaker and Microphone: Both are needed for this project and here you may have several options. Computer speaker with a 3.5mm jack, USB speakers or microphones, headsets or any combination. You may even use a webcam with microphone if you do not count with the Raspberry Camera Module.

Infrared Motion Sensor: This sensor is used to detect the presence of the visitor and switch the user interface view accordingly. I used HC SR501 which is inexpensive and can be adjusted for sensitivity and output timing using the on board variable resistors.

Green LED: Not strictly necessary. In my project the LED flashes when the app is listening the visitor speak the name she is looking for. It also remains ON when the door is being unlocked.

Active Buzzer: The active buzzer is a placeholder. It represents whatever relayed mechanism would be needed to unlock a door. Any real application may need different electronic components to achieve that objective.

Hygrotermograph Sensor: This sensor provides information about the temperature and humidity in the room. Not very functional to this specific application but I decided to include just because… I can. I used the inexpensive DHT11. You can use any other, or none.

Other components: If you use all the same sensors, LED and buzzer you will need one NPN transistor (S8050) and three resistors (1KΩ, 10KΩ, and 220Ω).

Electronic Circuit Schematic Diagram: Below you can see how the components shall be connected. You may use different GPIO pins, just remember to update the code in gpioWrapper.js

About the software

Operating System: The Raspberry Pi runs Raspbian Stretch with is the latest version of the Debian Linux distribution specifically for Raspberry Pi.

Framework: The application is a nodejs process using electron to have access to Chromium WebRTC APIs needed by the Circuit SDK to established a WebRTC communication. So, it is not an actual electron desktop application… but it could have been as well.

Caution: the nodejs (and npm) versions on the Debian repository are not the latest and this project needs the latest ones, so do not use apt-get, instead follow the instructions on my GitHub repository.

Vue: Although I am more familiar with AngularJS, I decided to go with Vue to handle the user interface. Vue is very lightweight in comparison and has a quick learning curve.

BCM2835: bcm2835 library. This C library for Raspberry Pi provides access to GPIO and other IO functions on the Broadcom BCM 2835 chip. Instructions to download and build the library can be found also on my GitHub repository.

Google Cloud Services: As I mentioned before the visitor can type on the touch screen to find the Circuit user, or just speak the name. For transcription I decided to use Google Cloud Speech API. The setup is outside the scope of this article but can learn all you need to know for this application with the Google Cloud Speech Quick Start. For speech recording I used sox.

Circuit SDK usage

On the GitHub circuitKiosk repository you will find examples on how to use some of the capabilities of the Circuit platform using the Javascript SDK. You will see how to instantiate the Circuit client, set the log levels, add event handlers, log your application, search for users, and process those search results. You will also learn how to find and create Circuit conversations, send text items, and process received ones. The application also makes use of Circuit forms that are sent as text items. Forms submissions are received as text items, and you will see how to process them. In the code you will also find how to setup a video call, process call events and handle the call media by getting the remote streams from the instantiated Circuit client.

Let’s see some specific examples:

In order to instantiate a Circuit client your code will look something like this:

gistfile1.txt

Circuit.logger.setLevel(Circuit.Enums.LogLevel.Debug);
let client = Circuit.Client({
        "client_id": "your-client-id",
        "client_secret": "your-client-secret",
        "domain": "circuitsandbox.net"});

Notice on line #1 the Circuit log level is set.

Besides logging in your application into Circuit, this has to add event handlers. Circuit raises a ton of different events. For this application we are just interest in a few of them.

gistfile1.txt

     client.addEventListener('itemAdded', processItemAddedEvent);
        client.addEventListener('itemUpdated', processItemUpdatedEvent);
        client.addEventListener('callStatus',processCallStatusEvent);
        client.addEventListener('callEnded',processCallEndedEvent);
        client.addEventListener('callIncoming', processCallIncomingEvent);
        client.addEventListener('formSubmission', processFormSubmission);
        client.addEventListener('basicSearchResults', evt => {
            processSearchResults(evt.data).then(users => {
                app.setUsers(users);
            });
        });
        client.addEventListener('searchStatus', evt => {
            processSearchStatus(evt.data).then(users => {
                if (users) {
                    app.setUsers(users);
                }
            });
        });

Basically the application needs to listen for new text items for maintenance commands, call events to handle WebRTC communications, formSubmission events to accept a command for a Circuit user (i.e. unlock the door), and search results to find specific Circuit users.

Finding a Circuit user it is an asynchronous process. So the application invokes the startUserSearch API, and wait for the corresponding events with the search results for which we already set the listeners above.

gistfile1.txt

let searchId = client.startUserSearch(searchString);

Once the user is found and selected to establish a communication the one to one conversation between the user and the application needs to be find, and if it doesn’t exist, then it needs to be created. Once the conversation is known then the call can be made. However, the SDK API makeCall does all this for you. You just need to know the id of the user destination of the call.

gistfile1.txt

client.makeCall(user.userId, {audio: true, video: true}, true);

As the call is being setup Circuit will raise callStatus events that need to be handled accordingly to properly setup the user interface and, eventually when the call is answer set the audio and video elements sources with the remote streams.

gistfile1.txt

    async function setupMedia(call) {
        let remoteStreams = client.getRemoteStreams(call.callId);
        let remoteAudioStream = remoteStreams.find((s) => s.getAudioTracks().length > 0);
        document.querySelector('audio').srcObject = remoteAudioStream;
        if(call.remoteVideoStreams && call.remoteVideoStreams.length) {
            Vue.nextTick().then(() => {
                document.querySelector('video').srcObject = call.remoteVideoStreams[0].stream;
             });
        }
        sendOpenDoorForm(call.convId);
    };

Now the call is setup and both parties can talk and see each other. Note line #10, here the application will send a form to the user with two buttons, one to unlock the door, and the other to reject the visitor by terminating call. Circuit SDK makes it easy to submit a form as a text message using the addTextItem API.

gistfile1.txt

    async function sendOpenDoorForm(convId) {
        await client.addTextItem(convId, {
            content: 'Select "Open Door" or "I do not know this person"',
            form: {
                id: 'openDoorForm',
                controls: [{
                    type: Circuit.Enums.FormControlType.BUTTON,
                    name: 'openDoor',
                    options: [{
                        text: 'Open Door',
                        notification: 'Opening Door',
                        value: 'openDoor'
                    }, {
                        text: 'I do not know this person',
                        value: 'endCall',
                        notification: 'Access Denied'
                    }]
                }]
            }
        });
    };

Finally as the user chooses to unlock the door for the visitor the application will process the form result.

gistfile1.txt

    function processFormSubmission(evt) {
        logger.info(`[RENDERER] process form submission. ${evt.form.id}`);
        evt.form.data.forEach(ctrl => {
            logger.debug(`${ctrl.key}: ${ctrl.value}`);
            switch (ctrl.name) {
                case 'openDoor':
                    switch(ctrl.value) {
                        case 'openDoor':
                            openDoor();
                            break;
                        case 'endCall':
                            break;
                        default:
                            logger.error(`Unknown value in submitted form: ${ctrl.value}`);
                            return;
                    }
                    app.currentCall && client.leaveConference(app.currentCall.callId);
                    client.updateTextItem({
                        itemId: evt.itemId,
                        content: (ctrl.value === 'openDoor' ? 'Door has been opened' : 'Entrance denied'),
                        form: {
                            id: evt.form.id
                        }
                    });
                    break;
                default:
                    logger.error(`Unknown key in submitted form: ${ctrl.key}`);
                    break;
            }
        });
    };

Let’s build it

Just follow the step-by-step instructions on GitHub circuitKiosk repository README.md . Here is a short video demonstration:

As you may already know the only limitation is your imagination. All the parts are out there, get them and build something cool and you will learn a lot in the process, after all there are only two kinds of adventure in life: love and knowledge.

30s ad

Raspberry Pi 3 Day Project: Retro Gaming Suite

Raspberry Pi Projects : Build a Media Centre Computer

Build Your Own Super Computer with Raspberry Pis

PiBot: Build Your Own Raspberry Pi Powered Robot

Internet of Things (IoT) Automation using Raspberry Pi 2

Raspberry Pi 4 on the Raspberry Pi 4 - Computerphile

Raspberry Pi 4 on the Raspberry Pi 4 - Computerphile

A quick tour of the Raspberry Pi 4 edited on the Raspberry Pi 4. Dr Steve Bagley gets out his knife.dll to unbox Sean's purchases! ☞ [I created a home IoT setup with AWS, Raspberry...

A quick tour of the Raspberry Pi 4 edited on the Raspberry Pi 4. Dr Steve Bagley gets out his knife.dll to unbox Sean's purchases!

I created a home IoT setup with AWS, Raspberry Pi

Benchmarking the Raspberry Pi 4

The easy way to set up Docker on a Raspberry Pi – freeCodeCamp.org

Creating a Rogue Wi-Fi Access Point using a Raspberry Pi

Building a Smart Garden With Raspberry Pi 3B+

Learn Raspberry Pi for Image Processing Applications

Learn Raspberry Pi for Image Processing Applications

New to the newly launched Raspberry Pi 3? Learn all the components of Raspberry Pi, connecting components to Raspberry Pi, installation of NOOBS operating system, basic Linux commands, Python programming and building Image Processing applications on Raspberry Pi. At just $9.

Description
Image Processing Applications on Raspberry Pi is a beginner course on the newly launched Raspberry Pi 3 and is fully compatible with Raspberry Pi 2 and Raspberry Pi Zero.

The course is ideal for those who are new to the Raspberry Pi and want to explore more about it.

You will learn the components of Raspberry Pi, connecting components to Raspberry Pi, installation of NOOBS operating system, basic Linux commands, Python programming and building Image Processing applications on Raspberry Pi.

This course will take beginners without any coding skills to a level where they can write their own programs.

Basics of Python programming language are well covered in the course.

Building Image Processing applications are taught in the simplest manner which is easy to understand.

Users can quickly learn hardware assembly and coding in Python programming for building Image Processing applications. By the end of this course, users will have enough knowledge about Raspberry Pi, its components, basic Python programming, and execution of Image Processing applications in the real time scenario.

The course is taught by an expert team of Electronics and Computer Science engineers, having PhD and Postdoctoral research experience in Image Processing.

Anyone can take this course. No engineering knowledge is expected. Tutor has explained all required engineering concepts in the simplest manner.

The course will enable you to independently build Image Processing applications using Raspberry Pi.

This course is the easiest way to learn and become familiar with the Raspberry Pi platform.

By the end of this course, users will build Image Processing applications which includes scaling and flipping images, varying brightness of images, perform bit-wise operations on images, blurring and sharpening images, thresholding, erosion and dilation, edge detection, image segmentation. User will also be able to build real-world Image Processing applications which includes real-time human face eyes nose detection, detecting cars in video, real-time object detection, human face recognition and many more.

The course provides complete code for all Image Processing applications which are compatible on Raspberry Pi 3/2/Zero.

Who is the target audience?

Anyone who wants to explore Raspberry Pi and interested in building Image Processing applications

To read more:

Raspberry Pi: Dummy tutorial on port forwarding and SSH

Raspberry Pi: Dummy tutorial on port forwarding and SSH

Raspberry Pi: Dummy tutorial on port forwarding and SSH .This is a continuation of my series on setting up Raspberry Pi to be a remote jupyter notebook code editor. In the last chapter Raspberry Pi was set up and could be accessed by SSH at your home network

This is a continuation of my series on setting up Raspberry Pi to be a remote jupyter notebook code editor. In the last chapter Raspberry Pi was set up and could be accessed by SSH at your home network. In this chapter I will guide you how to set up port forwarding and access the Pi remotely from the internet, so you could write command under CLI just like at home.

First time Pi user and first time reader? Check out the first part here.

But once your Pi is accessible from the internet, you need to be 100x cautious about potential security vulnerability. Most of the content you could find on Google Search should guide you to a term “Port Forwarding”, while in the Raspberry Pi official documentation it explicitly told you that port forwarding exposes a known security problem and you should consider altnerative ways to do it. I am going to introduce both ways in this series. And I promise we will get to host website soon, but let’s make sure it’s safe to do so first.

Table of Content
  • Increase your security before exposing your Pi to the internet
  • Port Fowarding
  • What’s next: Cloud Proxy Connections
Increase your security before exposing your Pi to the internet

There are two things you should do before exposing your Pi to the internet.

  1. Change the password of default user Pi

To change the password, simply type in passwd and follow the text instructions by re-typing your old password, your new password and re-tpying your new password.

  1. Create a new user without sudo access and use that user to access your pi remotely

sudo: similar to system admin preveilage in windows, which user can run command that is defined as superuser level, including rebooting your computer and installing any software. You can check out more here.
A good practice, for example, is to use sudo at home to install the software needed and give normal user read/write access to only some sub-folders, then use normal user to remotely login the Pi and only work on these sub-folders.

Let’s create a new user without sudo access, type in sudo adduser normal_user.

You will be asked a series of questions, including the password, basic information of the user and enter Y to confirm all information is correct.

Now we have created a new user normal_user.

To check whether this user have sudo access, we could simply type in sudo -l -U normal_user. And the text should show you ‘User normal_user is not allowed to run sudo on raspberrypi.’

So next time, you could try out SSH connection by not using pi as the login, but normal_user .

Want to know more about user access and organizing user? Check out the tutorial on digitalocean.

Port Forwarding

First, I want to reiterate that setting up port forwarding without any safety add-on to block malicious traffic is not recommended, and this article does not provide enough guidance to set that up. What I would recommend is to set up a cloud proxy server, which we will go through in the next chapter.

With all said, let’s go through a dummy example.

Your home network is known as Private LAN in that no external device could connect to your devices at home. This is controlled by firewall, which by default denies all incoming traffic.

But you don’t always spend your life in Raspberry Pi (me neither, just to be clear), you also love to play Diablo II, a classic rpg game which you could coop with other players. And you play it on another home device, PC. Turns out Diablo II is an old game which requires a direct connection between you and other players in order to hack-and-slash-and-loot the monsters. When you guys are in the game, data package including player’s location, level and action will need to be continuously streamed between players.

Your home PC has an internal IP address of 192.168.1.4. Diablo II automatcially configures a port 1033 for other players to get your data pacakge.

As I mentioned in last chatper, each device at your home will be automatically assigned an IP address by the router (e.g. my Pi’s address is at 192.168.1.50) and each internet application will use up one port number (e.g. 22). A quick refresher example: 192.168.1.50:22 represents <my Raspberry Pi>:<SSH Application>.

Finally, you do a google search and know that your external IP address is 50.247.207.5.

Turns out, if you were able to open a port on the external IP address, and map(point) that port to one set of <Internal IP Address>:<Port>, then you can tell your friends to enter your <External IP Address>:<Port your opened> to route their connection to your <PC's internal IP Address>:<Dialbo II data package application (1033)>.

This is what referred as Port Fowarding and you basically pinhole on your firewall to finally allow incoming traffic to a specific internal IP address and port.

Risk with Port Fowarding

Before I teach you how to forward a port, I want to crystalize what could happen at the worst case.

First, Port Forward won’t expose all your devices at your home. It only allow external user to connect to device you’ve pointed it at. In Diablo II, that’s perfectly fine. As the only application you opened is for other player to receive data package from your game. But for Raspberry Pi, the SSH application represents full access to your Pi’s CLI, and able to run any command including communication with your other home devices. And this is why opening Port for Diablo and XBox are generally safe and trivial but for Raspberry Pi it could be very dangerous.

The chance for any hacker to hide in the brush and wait til you open a port is nearly impossible, let alone to say that hacker needs to know a user / password pair in order to login. So it isn’t really a huge security problem for most of home users. But the possibility is there.

Port Forwarding your Pi to external network

Let’s clarify things we know before we started. From last chatper, we know how to check the internal IP address of our Pi, external IP address of our network and we also know that port 22 is opened for SSH from our Pi.

1~ Enter your router configuration page

Router configuration page is usually a website hosted inside your home network. The url should be printed on the router itself, and definitely shown in the router manual. If you still cannot find it, simply try http://192.168.1.1/ as most of the routers occupied this IP as their configuration page.

2~ Go to port forwarding configuration page

The page location will vary for different brands. Try your best to look for keywords including

  • Advanced Setting, Security Setting, Port Forwading, Virtual Server, Wan Setting

And you should be able to get to the port forwarding page.

3~ Configure rules

For some routers, they will require an extra step to enable port forwarding. Make sure to enable that!

Then, you will probably see a list of inputs, including

  • Service Name: text to describle the port foward service.
  • Source Target [optional]: Whitelist of external IP. Only IPs that are whitelisted could be able to connect to this port. Therefore, if you already know the IP where you are going to make the connection. Adding the whitelist IP here could tremendously increase your security. But this is only available for newer models of router. Leave it blank if you allow all IP to make connection.
  • Port Range: Port that is opened up from your router. In the above example, I open a port on 10300. Let’s say my external IP is 50.247.207.5, using 50.247.207.5:10300 could redirect me to the Pi later.
  • Local IP: IP address of your Pi in your private LAN. Check out last chapter if you don’t know how to find it. In this case it’ 192.168.1.50.
  • Port: Port / Application you want to open from the device specified in the local IP. In this case its 22, since Pi configure port 22 as the SSH application.
  • Protocol: TCP / UDP are usually available. You should also be able to select both. If only one of them can be selected. Please select TCP.

Once you apply the change, you are able to ssh to your Pi anywhere in the world! In this example, we can access our Pi by visiting 50.247.207.5:10300.

Accessing your Pi with windows

Same as last chatper, we could use Putty to connect to our Pi. But this time you could finally try this in a safe network (aka not Starbucks) outside your home wifi.

On Putty, type in your external IP address and Port you open up from the port forwarding setting. In this example it is 50.247.207.5:10300. Keep the connection type as SSH.

And you should be able to login with the CLI pop-up! This time let’s try out our normal_user username and password, so even if hackers get your credential, it’s just a non-sudo user.

And…. we are in! Now you can write and run any program in your Pi from anywhere!

What’s next: Cloud Proxy Connections

Port forwarding is always associated with risk. And we should consider other options like cloud proxy connections. Unfortunately on Raspberry Pi documentation there is no concreted instruction on how to do so, though it does recommend some free services we could use.

In next story, I am going to demonstrate how to use one of the cloud proxy connection service listed in the official documentation to connect to your Pi with SSH, remotely and securely. Stay tuned!