Hello Everyone,
Well, it looks like I am still taking one step forward and two steps backwards or maybe is it three steps backwards. The Adafruit BBIO library stopped working. While looking for the problem I noticed that I also lost my locale settings. I started getting errors when running packages that accessed the locale settings. This included trying to create a terminal session in Cloud9. I was able to fix the locale settings problem (See the Security Section for the fix), but not the root cause.
I tried to load some software and found out what was causing my problem. I ran out of space in the eMMC. The BeagleBone Black came with Debian 8 installed. I was in a hurry to get started with development so I just used eMMC instead of running to Walmart and buying a microSD card. The eMMC contains just 4G of space. Apparently, not enough for my purposes. I could have avoided the space problem if I would have waited until I bought an SD card to start development. As the old saying goes – you may not have time to do it right the first time, but you will find the time to do it right the second time. I now have a 32G microSD card.
I tried loading Debian 8 on the microSD card since the BeagleBone Black originally contained Debian 8. However, I could not get BoneScript working on it. Apparently, the image loaded on my BeagleBone Black is not the same image from the Beagleboard.org site.
I have an old BeagleBone Black (not wireless) that contains Debian 7. I never had any problems with Adafruit BBIO or BoneScript with Debian 7. Therefore, I loaded Debian 7 on the microSD card. However, the Debian 7 image does not support Wi-Fi or Bluetooth, so I could not use it with the BeagleBone Black wireless.
Next, I loaded the latest Debian image (9.4) onto the microSD card. The Adafruit BBIO and BoneScript libraries are working. However, I cannot initialize a UART port. I assume that the problem is due to how the device tree overlay is configured. I am still looking into the problem. I decided to resolve this problem instead of trying a different Debian image.
I did make some progress. I created code that allows the web server to communicate changes from the sensors to the web page. Each sensor is assigned a GPIO pin. Whenever a sensor change is sent to the HSS controller it changes the state of the appropriate GPIO pin to either high or low. The web server sends the GPIO pin status to the web page. The web page then changes the color of the appropriate button depending on the status received.
I also attached a text to speech hardware device to the BeagleBone Black. The device is connected via a serial interface (UART1). Whenever an alert is received by the HSS controller from one of the sensors the controller will send a message to the Emic2 Text to Speech module, which sounds an alert message through a speaker. Before I had the space problem the interface between the Emic2 and the BeagleBone black was working. However, I need to fix the UART problem before I can complete my testing of the sensor interfaces.
Once I resolve the UART problem and complete the testing of the code for the motion sensor, I will provide details on how the code works.
The details on creating an image on a microSD card and expanding the filesystem are given in the sections below:
Section I – Create a Debian Image on a SD card
Section II – Boot New Image and Expand the Filesystem
Section III – Security
I will continue working on the UART problem. If I do not resolve the problem in the next couple of days I can start developing the code for controlling the lights and appliances since they do not make use of a serial interface.
Talk to you soon.
Quote of the Moment -
Good judgment comes from experience, and a lot of that comes from bad judgment.
-- Will Rogers
Previous Bluetooth Challenge – Home Security System Posts |
---|
Section I - Create a Debian Image on a SD card
First, browse to:
https://beagleboard.org/latest-images
Then under:
Stretch IoT (without graphical desktop) for BeagleBone and PocketBeagle via microSD card
Click on: Debian 9.4 2018-06-17 4GB SD IoT
Save the file (Figure 1.)
Figure 1.
I moved the file from the Download directory to another directory incase I need it again. The image file is compressed. You need to un-compress it before loading it onto a microSD card. I used Zip-7 to un-compress my image file (Figure 2).
Click on the OK button when you see the window displayed in Figure 3.
Once the file is uncompressed, take note of the directory that contains the image file (Figure 4).
Figure 2.
Figure 3.
Figure 4.
Next, download the disk manager. The disk manager is used to load an image file onto a microSD card. Browse to:
https://sourceforge.net/projects/win32diskimager/files/latest/download
Save the file (Figure 5). Again, I moved the disk manager exe out of the download directory.
Double click on the win32diskimager-1.0.0-install exe (Figure 6).
Accept the license agreement (Figure 7). And click the Next button.
Click the Next button again (Figure 8).
Click the Install button (Figure 9).
Click the Finish Button (Figure 10). The disk manager will automatically start (Figure 11).
Figure 5.
Figure 6.
Figure 7.
Figure 8.
Figure 9.
Figure 10.
Figure 11.
Insert a microSD card into your PC. Click on the Format disk button when asked to format the disk (Figure 12).
Click on the Start button (Figure 13).
Click on the OK button (Figure 14).
Click on the OK button when the format is completed (Figure 15).
Figure 12.
Figure 13.
Figure 14.
Figure 15.
Click on the Folder Icon and browse to the directory that contains your image (Figure 16). Select your image, then Click on the Write button.
Click on the Yes button when you are asked to continue (Figure 17).
When the Write Successful pop-up window is displayed, click on the OK button (Figure 18).
Figure 16.
Figure 17.
Figure 18.
Section II – Boot New Image and Expand the Filesystem
Before booting with the new image copy any files you want to save from the old image to your PC. I used FileZilla to perform the copy (Figure 19 & 20).
Figure 19.
Figure 20.
Take the microSD card out of your PC and insert it into your BeagleBone Black. Plug your BeagleBone Black into your PC and press the power button. Once the BeagleBone Black is powered up logon onto the BeagleBone Black (Figure 21).
The first thing you want to do is expand the filesystem. Fortunately, Robert Nelson created a script for that. Run “sudo /opt/scripts/tools/grow_partition.sh” (Figure 22 & 23).
You need to re-boot for the expansion to take effect. Press the Reset button on the BeagleBone Black. Once the BeagleBone black has booted, logon.
Run “df -h –total” (Figure 24). Note that the filesystem has expanded. I used a 32G microSD card, so I have 27G of free space in the filesystem:
/dev/mmcblk0p1 30G 1.6G 27G 6% /
We are now ready to reload the software and scripts that was originally loaded on the eMMC.
Figure 21.
Figure 22.
Figure 23.
Figure 24.
Section II – Reload Software
I noticed that the Debian image I loaded did not have the man pages. Therefore, the first thing I did was installed them:
Run: “sudo apt-get install man” (Figure 25).
Figure 25.
This would be a good time to copy your application files to the new image. Again, I used Filezilla to perform the copy (Figure 26).
Figure 26.
Whenever possible, I used my previous blog posts to reload the software. I documented the steps below, noting any deviations from the Blog posts.
Blog Post II
Section IV – Configuring the Wi-Fi
Section VI – Updating the BeagleBone Black’s software packages
I did not receive any errors when running apt-get upgrade, so I did not have to re-run the apt-get upgrade.
Section VII – Creating a webserver
I did not receive any out of sync errors, so I did not have to install a newer version of Nodejs. However, I had to install pyserial.
To install pyserial run: “sudo pip install pyserial” (Figure 27).
The socket.io library is in a different directory. Therefore, the require statement was changed from:
var io = require('/usr/local/lib/node_modules/socket.io').listen(app);
to:
var io = require('/usr/lib/node_modules/socket.io').listen(app);
In the 09_01_led_control_server.js script (Figure 28).
Figure 27.
// 09_01_led_control_server.js
var app = require('http').createServer(handler);
var io = require('/usr/local/lib/node_modules/socket.io').listen(app);
var fs = require('fs');
var bb = require('bonescript');
var htmlPage = 'Prog BBB/09_01_led_control.html'; // use this for Angstrom
//var htmlPage = '09_01_led_control.html'; // use this for Debian
app.listen(8085);
function handler (req, res) {
fs.readFile(htmlPage,
function (err, data) {
if (err) {
res.writeHead(500);
return res.end('Error loading file: ' + htmlPage);
}
res.writeHead(200);
res.end(data);
});
}
function onConnect(socket) {
socket.on('digitalWrite', handleDigitalWrite);
}
function handleDigitalWrite(message) {
var data = JSON.parse(message);
console.log("write pin:" + data.pin + " value:" + data.value);
bb.pinMode(data.pin, bb.OUTPUT);
bb.digitalWrite(data.pin, data.value);
}
io.sockets.on('connection', onConnect);
Figure 28.
Section IX – Security
Blog Post III
Section I - Pair the BeagleBone Black Bluetooth adapter to the HC-06
Section II – Install the PyBluez Development Libraries
Section VI – Security
Blog Post IV
Section III – Security
You do not have to re-generate keys for your new image. You can use the keys from the previous image. Just copy the .ssh directory from the old image to the new image. I used FileZilla to copy my .ssh directory I saved on my PC, to the new Debian image. The .ssh directory should contain the authorized_keys file. Make sure you add the .ssh directory to your home directory.
Section III – Security
In addition to the locale settings, this week I am covering a couple of commands that help monitor disk, memory, and CPU utilization.
Locale Settings
Figure 29 is an example of an error caused by losing your locale settings. Lack of locale settings can cause package installations to fail, not to mention deny access to Cloud9. It is simple to fix. Just run “sudo locale-gen” (Figure 30).
Figure 29.
Figure 30.
Disk Usage
Figure 24 demonstrated how to display disk space utilization using the df command:
df -h --total
It is a good idea to run this command periodically to monitor your disk space utilization.
Memory/CPU usage
Here is another useful command. It helps determine why your system is running slow. It displays the processes that are currently using the most resources on your system. The display is updated in real time. Run “top” (Figure 31). To exit top press ctrl-C.
Figure 31.
Top Comments