The following are instructions on how to setup Mika Thing (Python)
project on Raspbian
operating system (a.k.a. Linux) to be used in the field.
Please note these instructions were made from MacOS.
-
Start by downloading a copy of
Raspbian
from the following link. It is recommended to download the Raspbian Stretch Lite version. -
Open up the app Balena Etcher and write the OS image to the SD card. If you've set everything up properly, you should see something like this:
- Click start and you should see something like this.
- Click start and you should see something like this.
- Afterwords eject the SD Card and insert it into the
Raspberry Pi
. Turn on the device.
- On your monitor you should see the login prompt. This means you have successfully setup
Raspbian
.
-
Login using the following credentials:
Username: pi Password: raspberry
-
Once you have successfully logged in, run the following command to enable
SSH
daemon. You will be able to remotely log into theraspberrypi
from your computer afterwords.sudo systemctl enable ssh sudo systemctl start ssh
-
Confirm you are able to log in. Run the following code on developer computer.
ssh -l pi 192.168.0.27
The following instructions are done through the SSH
session.
```
sudo apt-get upgrade
sudo apt-get upgrade
sudo apt-get install libssl-dev
```
We want to support python3
.
-
Run the following to install the pre-requisites.
sudo apt-get install build-essential checkinstall sudo apt-get install libreadline-gplv2-dev libssl-dev libncursesw5-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
-
Download and unzip
Python3
.cd /usr/src sudo wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz sudo tar xzf Python-3.6.0.tgz
-
Compile and install
Python3
.sudo -s cd /usr/src/Python-3.6.0 bash configure make altinstall exit
-
Install
pip
forPython3
.sudo apt-get install python3-pip
-
Install
git
.sudo apt install git
-
Install
virtualenv
.sudo apt install virtualenv
-
Steps 3 to X are taken from phidgets linux instructions.
-
Install our generic USB library.
sudo apt install libusb-1.0-0-dev
-
Download our Linux drivers.
wget https://www.phidgets.com/downloads/phidget22/libraries/linux/libphidget22.tar.gz
-
Unzip
tar zxvf libphidget22.tar.gz
-
Go into the directory.
cd libphidget22-1.0.0.20190129/
-
Pre-compile the code.
./configure make
-
Compile the code and install. Please note once this command is run the compilation time will take a while.
sudo make install
-
Run this code to verify the phidgets are working.
cd ~/ wget https://www.phidgets.com/downloads/phidget22/libraries/any/Phidget22Python.zip unzip Phidget22Python.zip cd Phidget22Python sudo python setup.py install cd ~/ wget https://www.phidgets.com/downloads/phidget22/examples/python/HumiditySensor/Phidget22_Humidity_Python_Ex.zip unzip Phidget22_Humidity_Python_Ex.zip sudo python Humidity.py
-
Clone our project.
cd ~/ git clone https://github.com/mikasoftware/mikathing.git cd ~/mikathing
-
Activate the
root
account so our application can access the hardware.sudo -s
-
Setup our virtual environment
virtualenv -p python3.6 env
-
Now lets activate virtual environment
source env/bin/activate
-
Now lets install the libraries this project depends on.
pip install -r requirements.txt
-
In the
src
directory create a file called.env
and populate it with the following content:# THE FOLLOWING VARIABLES ARE SET ACCORDING TO YOUR PHIDGET DEVICE VALUES. # PLEASE REVIEW THE PHIDGETS.COM WEBSITE TO GET MORE INFORMATION HOW TO GET # THESE VALUES FROM YOUR COMPUTER. HUMIDITY_SERIAL_NUMBER=538319 HUMIDITY_VINT_HUB_PORT_NUMBER=0 HUMIDITY_CHANNEL_NUMBER=0 TEMPERATURE_SERIAL_NUMBER=538319 TEMPERATURE_VINT_HUB_PORT_NUMBER=0 TEMPERATURE_CHANNEL_NUMBER=0 # THE FOLLOWING VARIABLES ADJUST THE OPERATION OF THIS APPLICATION. APPLICATION_DATA_INTERVAL_IN_MINUTES=5 APPLICATION_DATABASE=thing.db
-
Please change the contents of the
.env
file to match the configuration found in your systen. -
Once you are ready, run the application! (Please make sure all the Phidgets devices are connected to the Raspberry Pi.)
cd /home/pi/mikathing/src python mikathing.py
If you want a temporary solution of running Mika Thing in the background while you leave the SSH
session then follow these instructuions. Please note if the Raspberry Pi restarts you will lose the process and you'll need to manually re-create it. Special thanks to this link.
-
Install
screen
:sudo apt-get install screen
-
Run our screen.
screen
-
Run our app.
sudo -s source /home/pi/mikathing/env/bin/activate python /home/pi/mikathing/src/mikathing.py
-
On your keyboard, click
CTRL + A + D
. This will detach the process. -
Confirm our process is working.
screen -list
-
If you want to resume that process, run:
screen -r
The following set of instructions will show how to have Mika Thing application to automatically startup when the system startups. using systemd
.
-
While being logged in as
pi
run the following:$ sudo vi /etc/systemd/system/mikathing.service
-
Copy and paste the following contents.
[Unit] Description=Mika Thing Daemon After=multi-user.target [Service] Type=idle ExecStart=/home/pi/mikathing/env/bin/python3.6 /home/pi/mikathing/src/mikathing.py [Install] WantedBy=multi-user.target
-
We can now start the Gunicorn service we created and enable it so that it starts at boot:
sudo systemctl start mikathing sudo systemctl enable mikathing
-
Confirm our service is running.
systemctl status mikathing.service
-
If the service is working correctly you should see something like this:
* mikathing.service - Mika Thing (Python) Daemon Loaded: loaded (/etc/systemd/system/mikathing.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2019-02-10 04:48:55 GMT; 4s ago Main PID: 1286 (python3.6) CGroup: /system.slice/mikathing.service `-1286 /home/pi/mikathing/env/bin/python3.6 /home/pi/mikathing/src/mikathing.py Feb 10 04:48:55 raspberrypi systemd[1]: Started Mika Thing (Python) Daemon.
-
Congradulations! You have setup **Mika Thing`` application to automatically startup on boot. Just don't forget make sure the phidgets are connected to the raspberrypi whenver you run the computer.