Raspberry Pi and its stream of IoT devices have serious importance in the digital work of getting data and analyzing it.
Esp devices,
- ESP8266
- ESP32
- ESP32-Sim800l
- I^2 C Bus
- Serial
- HTTP
- UART
- MQTT
- Wifi
- Core
- Control and view all your IoT devices through a single web app
- Mobile friendly - compatible with devices of all sizes
- Create switches, sliders, sensors, infrared remote controls
- Devices are monitored to ensure they are up and responding to requests
- Devices can be assigned to locations i.e. rooms
- Set timers based on sunset/sunrise
- Example scripts for ESP, Raspberry Pi, and sonoff
These instructions are based on installing espio on a Raspberry Pi with a fresh install of Raspberry Pi OS. The instructions should work for other Debian based systems i.e. Ubuntu, Mint Mosquitto is used as the MQTT broker
Raspberry Pi Static IP
Ensure your Raspberry Pi has a static IP address. Ideally this should be set on your router.
Setting up a Static IP Address on the Raspberry Pi
Mosquitto Broker
sudo apt update
sudo apt upgrade
sudo apt install -y mosquitto mosquitto-clients
sudo systemctl enable mosquitto.service
Configure Mosquitto Broker
sudo nano /etc/mosquitto/conf.d/mosquitto.conf
Replace contents of file with the text below:
listener 1883
protocol mqtt
listener 8083
protocol websockets
Once done save and exit by pressing CTRL + X and then pressing Y then ENTER.
Restart the mosquitto broker
sudo systemctl restart mosquitto.service
Testing mosquitto broker
mosquitto_pub -d -t testTopic -m "Hello world!"
Apache
For detailed instructions and explanations of the commands see How to Setup a Raspberry Pi Apache Web Server
sudo apt install apache2 -y
sudo usermod -a -G www-data pi
sudo mkdir /var/www/espio
sudo chown -R -f www-data:www-data /var/www/espio
Logout and log back in
PHP7 for Apache
sudo apt install php7.3 php7.3-mysql -y
MySql
For detailed instructions and explanations of the commands see Setup a Raspberry Pi MYSQL Database
Follow the prompts to set a password for the root user and to secure your MySQL installation.
sudo apt install mariadb-server
sudo mysql_secure_installation
sudo apt install php-mysql
Paho-mqtt
Install the python paho-mqtt module.
sudo pip3 install paho-mqtt
Creating a MySQL Database and User
Make sure you change enter a password here before executing the command. Make a note of the password, you will need to enter it later.
sudo mysql -u root -p
CREATE DATABASE espio;
CREATE USER 'espio'@'localhost' IDENTIFIED BY '_enter a password here_';
GRANT ALL PRIVILEGES ON espio.* TO 'espio'@'localhost';```
FLUSH PRIVILEGES;
Type quit
to exit mysql
Create Virtual Host
sudo nano /etc/apache2/sites-available/espio.conf
Replace contents of espio.conf with the text below
listen 8080
<VirtualHost *:8080>
ServerAdmin [email protected]
ServerName espio.local
DocumentRoot /var/www/espio/
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /var/www/espio/>
Options Indexes FollowSymLinks
AllowOverride ALL
Require all granted
Header set Access-Control-Allow-Origin "*"
IndexIgnore * # prevent directory listing
RewriteEngine on
# Rewrite /foo/bar to /foo/bar.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule (.*) $1.php [L]
</Directory>
</VirtualHost>
Once done save and exit by pressing CTRL + X and then pressing Y then ENTER.
Enable the New Virtual Host File
sudo a2ensite espio.conf
Enable the required apache modules and restart
sudo a2enmod headers
sudo a2enmod rewrite
sudo systemctl restart apache2
Download the Latest Release
wget https://github.com/jasonbrownza/espio/releases/download/v1.0.0/v1.0.0.zip
unzip v1.0.0.zip -d /var/www/espio/
Set Folder Permissions
sudo chmod 775 '/var/www/espio/api/config/'
Timers Service
Configure the timers script.
The only variable that needs to be changed is the mqttServerAddress. Change the IP address to the static IP address of your Raspberry Pi.
nano /var/www/espio/services/espio_timers.py
Make the timers script executable
sudo chmod +x /var/www/espio/services/espio_timers.py
Create a systemd service for the timers service
sudo nano /etc/systemd/system/espio_timers.service
Replace the contents of the file with the text below :
[Unit]
After=network.target
[Service]
ExecStart=/var/www/espio/services/espio_timers.py
[Install]
WantedBy=default.target
Once done save and exit by pressing CTRL + X and then pressing Y then ENTER.
Start the espio_timers service
sudo systemctl daemon-reload
sudo systemctl enable espio_timers.service
sudo systemctl start espio_timers.service
Running Espio
Point your browser to:-
http://raspberry-pi-static-ip:8080
Now, you would get a page to add devices and make a dashboard out of it.
No comments:
Post a Comment