• Tiada Hasil Ditemukan

System software installation and setting up

In document DECLARATION OF ORIGINALITY (halaman 73-87)

Chapter 5: System Specifications and Implementation

5.1 Specification: Analysis and Design

5.1.3 System software installation and setting up Raspberry Pi

The first thing that need to do is to ensure that the Raspbian OS has been installed on the system. The Raspbian is an OS that the Raspberry Pi is relying on. It handles all the events and provides GUI to the user. Make sure the Raspbian is installed on the SD card of the Raspberry Pi before any further action. To install Raspbian on the SD card, the laptop/PC. On the laptop/PC, copy the Raspbian image file that have been downloaded to the SD card. Then that’s, just plug the SD card into the Raspberry Pi’s SD card slot and boot the Raspberry Pi, the system will now start to install the Raspbian OS automatically.

After successfully launched the OS, check the OS version by entering the command:

$ uname -a to check the version of OS installed. The result will be something as shown below. One can observer the line that mentioned the Raspbian version, arm version and etc

Figure 5.12: Verify the OS installed on Raspberry Pi

Next, before any software setup and installation, first make sure the Raspberry Pi is connected to internet by checking internet status on Raspberry Pi. To check if the Raspberry Pi have connected to the internet and have access to internet, use the command: $ ifconfig. The output will shown as below.

Figure 5.13: Internet Configurations on Raspberry Pi 3 Model B

From the graph above, one can see if the Raspberry Pi has successfully get the internet access, the wlan0/Eth0 (depends on the connection type: wireless or ethernet) will show the respective IP address and Broadcast address, in this case, it is for the IP address with wireless mode (wlan0), as shown in the graph above. If the Raspberry Pi is not connected to the internet, the IP addresses will not be shown in this section.

After making sure that the Raspberry Pi has the internet access, the following list of software and dependencies can then be installed. The list of softwares and dependencies to be installed are as shown below:

1.) Python 3.x 2.) Python IDLE 3.x 3.) MySQL Database 4.) Openhab 2

5.) MQTT Python 3.x

First, to check if the Python 3.x is already installed, use the command: $ python3 --version. If Python 3.x is already installed on the Raspberry Pi system, it will shows its current version, as shown in the graph below.

Figure 5.14: Python 3.x version checking

In this case, the system is installed with Python 3.4.2 version. However, if the command does not show any of the Python 3 version, a manual installation is required.

To install Python 3.x, enter the command: $ sudo apt-get update to update the the packages before installing the python 3.x, the result of the updates will be something as shown below.

Figure 5.15: Update the packages on Raspberry Pi

After performed the updating command, the installation of Python 3.x is now ready. To install the Python 3.x, enter the command: $ sudo apt-get install -y python3. Note that the -y option is to accept to install the package on the system.

After this command, the python 3.x installation will begin shortly, the images below shows the sample installation process.

One can see that the Python 3.x is already installed on the system, hence, installation will be halted, however if Python 3.x is not installed on the system, this step will do the job.

After the installation is successfully completed, checking the version of the Python 3.x to make sure it is installed, by entering the command: $ python3 --version. It should now show the version of the Python 3.x installed.

To make sure that the python 3.x is working properly, enter the command: $ python3 to enter to the python console panel, and type: >>> print (“Hello from Python 3.x”) to make sure that it prints out a line of message. If the message is shown, the system already installed the Python 3.x properly, quit the console by entering the command: >>> quit() on the console panel, this will terminate the python3 console session. The process is shown in the image below.

Figure 5.17: Check if Python 3.x is working

After all these steps, the python 3.x should now be installed and ready to be used. Python IDLE 3.x

In order for Raspberry Pi to be able to run the program on its own as a server. A Python IDLE is needed in order to edit and compile/run the python program. There are 2 types of Python IDLEs, one is Python IDLE 2.x version and the other one is Python IDLE 3.x version. In this system, the Python IDLE 3.x is used to develop and run the program on the server.

To install the IDLE, first, check whether the current system have Python IDLE 3.x installed, enter the command: $ idle3. If the Python IDLE 3.x is installed, this command will open up the Python IDLE 3.x in another window as shown in the graph below, otherwise, the IDLE will not be started and an error message will be prompted.

Figure 5.18: IDLE is being opened up from terminal console

If the IDLE has not been installed, enter the command: $ sudo apt-get install -y idle3 to install the Python IDLE 3.x on the system. Once the installation has been done, check whether the Python IDLE 3.x has been installed by entering again the command: $ idle3 to see if the program can be launched. If the program has been successfully run, it will show something like the graph below.

Figure 5.19: A Python IDLE 3.x console window MySQL Database

MySQL Database is needed to store all the data collected from Arduino UNO (Base Station). The data collected from Arduino UNO will be stored inside this database based on the Bin Id of each respective remote site. The data stored in the database will then be extracted from a python program and sent to the openhab topics via the use of MQTT protocol. Hence, MySQL needs to be installed on the system before the data can be forwarded.

To ensure that the MySQL database has already been installed on the existing system, enter the command: $ mysql --version to check if it is installed. If the mySQL is installed, it will display the message as shown in the image below.

Figure 5.20: MySQL version checking Otherwise, an error message will be shown instead.

To install MySQL Database, first is to install the MySQL server by entering the command: $ sudo apt-get install -y mysql-server, as shown in the image below.

Figure 5.21: Installing MySQL-server

After that, you will be prompt for creating password for root of the MySQL account as shown in the picture below.

Figure 5.22: Creating password for MySQL account

If the command prompt does not show the configuration page for creating password, a manual setup for the MySQL will be needed. To create the user information manually, enter the command: $ sudo mysql_secure_installation. This will bring message as shown in graph below to create the password for ‘root’.

Figure 5.23: Create password for MySQL ‘root’ user

Enter the password for the ‘root’ user account then the MySQL is almost ready to go.

Now, logging to the MySQL server to see if it is working by entering the command:

$ mysql -u root -p. Then, the MySQL console page will be shown as shown in the picture below.

Figure 5.24: MySQL console view

Inside this MySQL console, the database querying, creating can be done. For example, to show the current available databases on MySQL server, enter the SQL query: > SHOW DATABASES; then the results will be shown, as in the picture below.

Figure 5.25: Querying mySQL in console

Some default databases will be shown up, such as information_schema, performance_schema, etc.

Now that the MySQL has been successfully installed and runned. The next step is to install the an dependency that allow the MySQL to communicate with Python 3.x. To install the dependency, enter the command: $ sudo apt-get install -y python-mysqldb.

This will install the required dependency for the communication between Python and MySQL. Hence, the querying using Python will be enabled.

Now, the MySQL has been fully installed and should be able to communicate with the Python 3.x. Openhab 2

Openhab 2 is an IoT framework that allow the sensor devices to send data to its server for visualizing the data in form of graph and different representations. This enable the IoT devices to share the data within a single platform so that it allows the user to monitor all the devices at once and in a single application.

Openhab 2 is used for this system to provide a simple, yet useful information for the user in a single application that allow the real-time monitoring and data visualization. This will enable the users to have the capabilities to keep track of the garbage bin information in palm of hand.

The following section discuss the steps that are required to install the Openhab 2 on the Raspberry Pi.

To install Openhab 2 ,first make sure that the system has the followings:

- Raspberry Pi 2 or newer

- Micro SD card (16GB or more to support wear-leveling) - Steady power supply

- Ethernet connection

- No connected display or keyboard needed

The first step is to add the openHAB 2 bintray repository key to package manager and allow apt to use the HTTPS Protocol by entering the command: $ wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -

After doing so, the console will print a message saying “ok” on screen, as shown in the image below.

Figure 5.26: Adding the openhab 2 bintray repository key to package manager

Then, enter the command: $ sudo apt-get install apt-transport-https. This will install the apt-transport-https for the installation of openhab 2 as shown in image below.

Figure 5.27: Installing apt-transport-https

Next, choose a stable version of Openhab2 to install on the raspbian system by using:

$ echo 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list. The console will output the selected stable version of openhab 2 that is be to installed as shown in image below.

Figure 5.28: Choosing the stable version of Openhab 2 to install

The next step is to resynchronize the package index by entering the command: $ sudo apt-get update. Now, install Openhab2 by using the command: $ sudo apt-get install -y openhab2. This will take for while for the installation to complete.

Figure 5.29: Installing openhab 2

Then, install the addons for further utilization of openhab 2: $ sudo apt-get install openhab2-addons. The installation will take for while, it depends on the network speed of the internet.

Figure 5.30: Installing the openhab 2 addons

After the installation of addons is done, the openhab 2 is nearly to be fully functional. In order for the openhab 2 to automatically startup at system startup, need to register openhab2 to be automatically executed at system startup by entering the command:

$ sudo systemctl start openhab2.service. This will enable the openhab services to launch

when the system startup.

To check whether the service is enabled for system startup, enter the command: $ sudo systemctl status openhab2.service, to see whether the service is “enabled”. The enabled openhab will look something as shown below.

Figure 5.31: Showing the status of Openhab 2

Next, enter the following command to enable the openhab 2 service at once: $ sudo systemctl daemon-reload | sudo systemctl enable openhab2.service. If the service has been successfully started, the following output message will be outputted.

Figure 5.32: Openhab 2 successfully launched

Finally, the openhab2 will now be set up and ready to be accessed from localhost. To access this address, open up the browser and enter the address: http://localhost:8080.

Then, an Openhab 2 simple configuration page will be shown up as shown in the picture below.

Figure 5.33: The startup page of openhab 2

To enable remote development for openhab:

The openhab 2 is now ready to be implemented on the system. However, sometime the remote development s required, for example, telnet from another computer to Raspberry Pi to perform remote openhab development. By default, the openhab 2 will ignore the other connection other than Raspberry Pi to have access to control its property, hence, in order to enable the other computer to have access to control the openhab 2’s platform:

- First, need to add openhab to the privileged groups by entering the command:

$ sudo adduser openhab dialout | sudo adduser openhab tty | sudo adduser openhab audio

- Then, allow the java environment to access the serial port of the connected peripheral by using the command: $



- Next, setting up a remote to be able to easily access and modify these files from local PC or Mac by installing Samba: $ sudo apt-get install samba samba-common-bin

- Edit the content of smb.conf by entering the command: $ sudo vim /etc/samba/smb.conf. Inside the configuration file, uncomment and enable WINS support:

Figure 5.34: Inside sambal configuration file

- Then, add the desired share configurations to the end of the file:

Figure 5.35: Adding lines of configurations inside sambal configuration file - Finally, create and add user to Samba group: $ sudo smbpasswd -a openhab By doing all these step, the openhab 2 will now allow the remote devices to have access to the localhost’s development. The sample result of remote access from windows browser.

Figure 5.36: Accessing Openhab 2 from remote laptop’s browser


The communication protocol between Python 3.x on Raspberry Pi and Openhab 2 is MQTT. Hence, the MQTT need to be installed first before they can sending and request data from each other. The MQTT service the system used is Mosquitto MQTT, to install the Mosquitto MQTT, enter the command: $ sudo pip3 install paho-mqtt, this will install the paho-mqtt library for later use.

Figure 5.37: Installing python MQTT library

In document DECLARATION OF ORIGINALITY (halaman 73-87)