Hello Everyone,
Things did not go as planned last week so this post is late. Its also the inspiration for this post’s quote of the moment. I did complete the design of the software modules on the BeagleBone Black. I ordered the electric solenoid valve. Also, I am waiting for my second camera module. I will need to order more smart plugs. However, I want to wait until I am sure I can communicate with the one I have before ordering more.
Note that I used Wi-Fi for accessing the cameras. Any literature I read on steaming camera data suggested using Wi-Fi instead of Bluetooth. The logic being that Bluetooth may not be fast enough and the slow speed may cause jerky or frozen video frames.
In the Security section I discuss how to use PuTTY to logon to the BeagleBone Black without using a password. I only have two sections for this post, plus the Security section:
Section I – High Level Design for the BeagleBone Black Software
Section II - Bluetooth Data Protocol
Section III – Security
This week I will try to communicate with the smart plug and start working on the web server design.
Talk to you soon.
Quote of the Moment -
Life is what happens while you are making plans.
-- John Lennon
Section I – High Level Design for the BeagleBone Black Software
There are four main software modules, the Initialization module, the Wi-Fi module, the Web Server module, and the Bluetooth module (See Figure 1). There are seven sub-modules, Natural Gas Sensor sub-module, Carbon Monoxide Sensor sub-module, Motion Sensor sub-module, Alarm sub-module, Smart Plug / Lights sub-module, Electric Solenoid Valve sub-module, and Proximity Sensor (Garage Door) sub-module.
The Initialization module is a standalone module. Its purpose is to ensure that the other modules are started properly.
The Wi-Fi module has two functions. One function is for communications between the BeagleBone Black web server and the home owner’s web browser. The second function is for accepting a camera stream from the two cameras and passing the streams to the Web Server module for displaying on the home owner’s web browser.
The web server module accepts data from the sub-modules and passes the data to the web browser. It will also accept the home owner’s browser responses and passes those responses back to the sub-modules for processing.
The Bluetooth module accepts data from the Bluetooth devices and passes the data to the appropriate sub-module. The sub-modules process the data and passes responses back to the Bluetooth module which sends the data back to the appropriate Bluetooth device.
The Natural Gas Sensor, Carbon Monoxide Sensor, and Motion Sensor sub-modules processes the data from its corresponding sensor. If the sensor is triggered it sends an alert. The appropriate sub-module formats a message and the message is sent to the Alarm sub-module. The Alarm sub-module sounds an alarm by making a beeping sound and speaking a message via speech-to-hardware.
The Smart Plug / Lights sub-module processes data from smart plugs and lights. Basically, the sub-modules will accept requests from the home owner to either turn a light / appliance on or off. The request is passed to the Bluetooth module and sent to the appropriate Bluetooth device.
The Electric Solenoid Valve sub-module is similar to the Smart Plug / Lights sub-module. The main difference is the Electric Solenoid Valve sub-module controls a solenoid value instead of a smart plug or light. The solenoid value will act as an on-off switch for a gas stove.
The Proximity Sensor sub-module will control the garage door. The proximity sensor module will send the status of the garage door (open or closed) via Bluetooth to the Proximity Sensor sub-module. The Proximity Sensor sub-module will interact with the home owner via the web browser to close or open the garage door.
Figure 1.
Section II – Bluetooth Data Protocol
In this section we will define the format of the data that the sensor modules will use to pass data to the BeagleBone Black. Data is sent through the Bluetooth network will be formatted as shown in Table 1. Each Bluetooth adapter is assigned an Adapter_Id.
This Adapter_Id is populated into the Source_Adapter_Id of a Bluetooth data packet so that modules in the network know who sent the packet. The Adapter_Id is populated into the Destination_ Adapter_Id so that modules receiving the packet knows whether the packet is intended for the receiving module. If a module receives a data packet with its own Adapter_Id in the Destination_ Adapter_Id field it will process it.
To keep a packet from endlessly traversing the Bluetooth network a predetermined Max_Transmission_Count will be added to each packet. Every module that receives a data packet that does not belong to it will decrement the Max_Transmission_Count in the packet and re-transmit it. If a module receives a packet with a zero Max_Transmission_Count it will discard it. If a module receives a packet with its own Source_Adapter_Id it will discard it.
The Status field is used as a binary switch for the software sub-modules, such as “0” for off and “1” for on or, “0” for closed and “1” for opened.
The Data field is a free form field that contains custom data depending on the requirements of the sub-module.
Columns | Name | Description |
1-3 | Source_Adapter_Id | A 3-digit Id assigned to each Bluetooth adapter. The Controller module uses the Id to determine which module should process the data in the packet. |
4-6 | Destination_ Adapter_Id | A 3-digit Id of the Bluetooth adapter that should receive this packet. If zero, the destination is the BeagleBone Black. |
7-8 | Max_Transmission_Count | A 2-digit number that is decremented each time this packet is received by a Bluetooth adapter. If the number is zero the packet is discarded by the Bluetooth adapter. |
9 | Status | Status of device that the adapter is attached to. |
10-80 | Data | Information to be acted upon by the destination device. |
Table 1.
Section III – Security
In Post II, I showed you how to install PuTTY. PuTTY comes with a utility called PuTTYgen and another utility called Pageant. With PuTTYgen you can generate SSH key pairs. Pageant is used to help manage your private keys. Storing your private key in Pageant allows you to log onto your BeagleBone Black without a password.
For those unfamiliar with public key authentication here is a short description extracted from the PuTTY documentation:
You generate a key pair, consisting of a public key (which everybody is allowed to know) and a private key (which you keep secret and do not give to anybody). The private key is able to generate signatures. A signature created using your private key cannot be forged by anybody who does not have that key; but anybody who has your public key can verify that a particular signature is genuine.
So, you generate a key pair on your own computer, and you copy the public key to the server. Then, when the server asks you to prove who you are, PuTTY can generate a signature using your private key. The server can verify that signature (since it has your public key) and allow you to log in. Now if the server is hacked or spoofed, the attacker does not gain your private key or password; they only gain one signature. And signatures cannot be re-used, so they have gained nothing.
Here is the process to generate SSH key pairs with PuTTYgen and to use Pageant to logon without a password.
Start PuTTYgen on your PC (Figure 2).
Figure 2.
Click on the Generate button (Figure 3).
Figure 3.
Move you mouse around when prompted to create some randomness.
PuTTYgen will re-display the window with your public key populated in the top text box (Figure 4).
Figure 4.
Enter something in the Key comment text box that identifies your PC (Figure 5).
Enter a strong password in the Key passphrase text boxes.
Click on the Save public key button.
Make sure you remember which directory you used to save the keys.
I called the public key kxelaptop.pub (Figure 6).
Click on the Save private key button
I called the private key kxelaptop.ppk.
Figure 5.
Figure 6.
Now we want to copy the public key we generated with PuTTYgen to the BeagleBone Black (Figure 7).
Figure 7.
Leave the Putygen window open.
Switch to your BeagleBone Black PuTTY session.
From your home directory, create a new directory called .ssh (Yes, you need the period before the ssh):
Run “mkdir .ssh”
Run “cd .ssh”
We need to create an authorized_keys file to hold PuTTY’s public key.
Run “nano authorized_keys”
In the PuTTYgen window, copy the public key in the top text box, to the system clipboard (Figure 7).
In the nano editor:
- Right click on the mouse - to paste the contents of the system clipboard (Figure 8).
- Note that the Public key is one line long, not multiple lines.
- Enter Ctl-O to save the file. Click the Enter key when you see the prompt (Figure 9):
- File Name to Write: authorized_keys
- Enter Ctl-X to exit nano.
Figure 8.
Figure 9.
The authorized_keys file permissions must be set to read/write for owner and no permissions for group & world. To set the permissions correctly run “chmod 600 authorized_keys”:
-rw------- 1 debian debian 787 Jun 1 00:34 authorized_keys
Also, verify the the .ssh directory is set to read/write/execute for owner only:
drwx------ 2 debian debian 4096 Jun 1 00:34 .ssh
Now back to your PC. The PuTTYgen window is no longer needed, therefore you can close it. At this point we could logon using the PuTTY’s private key, if we added the private key to the PuTTY Configuration. However, when we try to logon, the logon process would ask us for the PuTTY private key password instead of the BeagleBone Back user password. If we let Pageant manage our private we will not have to enter any password. So, let’s add our private key to Pageant so we can logon to the BeagleBone Black without entering any key.
Open Pageant (Figure 10).
Figure 10.
Click on the Add Key button (Figure 11).
Click on the open button and browse to your key directory and select the private key (Figure 12).
Figure 11.
Figure 12.
Enter your password for your private key (Figure 13).
Figure 13.
Your private key is now stored in Pageant (Figure 14).
Figure 14.
Now, start a PuTTY session as you normally would. However, this time when your PuTTY session starts the BeagleBone Black will automatically log you on (Figure 15).
Figure 15.
Keep in mind that Pageant must be running for auto logon to work. You can add it to the startup folder so that it starts whenever you logon to your PC. The following link explains how to add a program to the startup folder if you do not know how:
There is one caveat with Pageant. When you exit Pageant, the private keys stored in Pageant are deleted out of Pageant. Therefore, the next time you start Pageant you have to re-enter the private key. If you have your private key password protected it will ask you for the password. However, you only have to do this once every Pageant session. The keys are only deleted out of Pageant if you exit Pageant. If you close Pageant it is minimized into the System tray and is still running.
You could get around the problem by not password protecting your private key. However, it is a less secure solution. If you do not password protect your private key you could specify the path for your key in the PuTTY configuration. Just add the path in the text box next to the Browse button (Figure 16) in the SSH/Auth Category in the PuTTY configuration. Now you can logon without a password and without running Pageant. Just keep in mind that if the private key is not password protected anyone hacking into your PC will be able to see your private key since it will be stored in plaintext.
Figure 16.
You can also execute PuTTY from a batch file. I created a PuTTY configuration file called “BeagleBone Black - debian 2”. The configuration file for BeagleBone Black - debian 2 contains the path to the private key that is not password protected. I then created a batch file called Logon BBBW.bat Which contains one line (Figure 17). If I double click on the logon BBBW.dat file it logs me on to the BeagleBone Black (Figure 18).
Figure 17.
Figure 18.
Top Comments