Install All Components

From UNamur InfoSec
Revision as of 15:05, 22 December 2017 by Mkuy (talk | contribs) (→‎Install composer)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

BLE Proxy

Install python library

  • Install paho-mqtt library:
sudo pip install paho-mqtt
  • Install bluepy
sudo apt-get install python-pip libglib2.0-dev
sudo pip install bluepy

More information about installation:

mqtt: https://pypi.python.org/pypi/paho-mqtt

bluepy: https://github.com/IanHarvey/bluepy/

Run BLE proxy on Raspberry Pi 3

I upload my code to gitlab.com: https://gitlab.com/unamur_iot/python-rpi-component

  1. Clone the repository to a Raspberry Pi 3
git clone https://gitlab.com/unamur_iot/python-rpi-component
  1. Go to folder called proxy_ble
  2. Configure MQTT Broker
edit config.txt file
update broker host, port, username, etc. 
  1. Run the code with:
sudo python main.py

LoRa Proxy

Install paho-mqtt

LoRa Proxy also use paho-mqtt library. We don't need to install it again, if we installed it already.

  • Install paho-mqtt library:
sudo pip install paho-mqtt

More information about installation:

mqtt: https://pypi.python.org/pypi/paho-mqtt

Run LoRa Proxy on Raspberry Pi

I upload my code to gitlab.com: https://gitlab.com/unamur_iot/python-rpi-component

  1. Clone the repository to a Raspberry Pi 3
git clone https://gitlab.com/unamur_iot/python-rpi-component
  1. Go to folder called proxy_lora_client
  2. Configure MQTT Broker
edit broker.txt file
update host, port, etc.
  1. If we want to configure TTN, and private LoRaWAN
edit network_info.txt
update ttn username, etc. 
  1. Run the LoRa proxy module
sudo python proxy.py


Web Application

I upload my code into: https://gitlab.com/unamur_iot/web-app-server-unamur use the username: unamur_iot, password: lora1234

Install php

sudo apt-get install php

Install Apache2

sudo apt-get install apache2


The web application use Laravel and can be run on Apache server.

  • Install php library that laravel use:
sudo apt-get install php-pgsql php-xml php-common php-mcrypt php-mbstring
  • Enable mode rewrite on Apache

Run

a2enmod rewrite

Add "AllowOverride all" to apache config file in /etc/apache2/apache2.conf

Change "AllowOverride" none in directory we of our application (ex: /var/www) to "AllowOverride all"

Restart Apache

service apache2 restart

Install composer

Laravel use composer to manage dependency. we need to install composer. More information about how to install composer: https://getcomposer.org/download/ Run the following command to download and install composer:

  1. Download composer setup php file
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
  1. Execute composer setup php file
php composer-setup.php
  1. Remove composer setup php file
php -r "unlink('composer-setup.php');"
  1. Add composer to execute command
sudo mv composer.phar /usr/local/bin/composer
  • Create database and user on postgresql

Note:To install postgresql for different machine is available on official website: https://www.postgresql.org/download/

Enter this command to go to psql console:

sudo -u postgres psql

Create user name "root" with:

create role root with login password 'root';

Create database name "scotchbox" for user "root":

create database scotchbox with owner root; 

Install web application to apache

More information about install Laravel application: https://laravel.com/docs/5.4/installation

  1. Clone project to /var/www
cd /var/www
git clone https://gitlab.com/unamur_iot/web-app-server-unamur
  1. Set folder permission. The folder storage and bootstrap/cache should be writable by the web server:
cd web-app-server-unamur
sudo chown -R www-data:www-data storage/ bootstrap/cache
  1. Install composer dependency
composer install
  1. Copy .env file from .env.example
cp .env.example .env
  1. Generate Application key by running:
php artisan key:generate
  1. Update database, username, password in .env file to match machine configuration
edit .env file
update database name, username, password, etc. 
  1. Migrate database and seed database
php artisan migrate --seed 
  1. Install Laravel Passport for API Authentication:
php artisan passport:install
  1. Change apache root directory to project public folder:
cd /etc/apache2/sites-available
nano 000-default.conf
Change the "DocumentRoot /var/www/html" to "DocumentRoot /var/www/web-app-server-unamur/public"

Cache Module

Install redis cache to server

  • Before installation:
sudo apt-get update
  • Install Build tool and tcl:
sudo apt-get install build-essential
sudo apt-get install tcl8.5
  • Install Redis
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
make test
sudo make install
cd utils
sudo ./install_server.sh


More information about redis installation:

https://www.digitalocean.com/community/tutorials/how-to-install-and-use-redis

https://redis.io/topics/quickstart

Install cache module for web application to get MQTT data from sensor

  1. Clone the module code into the server
git clone https://gitlab.com/unamur_iot/python-rpi-component
  1. Go to folder named redis-client
  2. Edit mqtt-config.txt
  3. Update host, port, etc.
  4. Run the module
python main.py

Android TV App

I upload my android tv code to: https://gitlab.com/unamur_iot/TVAppIOT.git

  • Install android studio:

Follow the official guide for installation: https://developer.android.com/studio/index.html

  • Clone the project:
  1. Run android studio
  2. Select File->New->Project From Version Control->Git
  3. Parse the project url:
  4. Edit folder name and click "clone"
  • Edit network configuration:

In project source code there is a file call "Application" Update "AUTH_BASE_URL" for web application url, "CLIENT_SECRET" OAuth password grant client secret

  • Build Apk file:
In android studio click: Build -> Build APK(s):
The build API is located at: app\build\outputs\apk\debug

Note: We can use dropbox to upload the apk to android tv device.