The Sense HAT is an add-on board for Raspberry Pi, equipped with various sensors, an LED matrix, and a joystick. Creating a web application for Sense HAT allows users to remotely interact with and monitor the data from these sensors, providing a user-friendly interface for accessing information and controlling the device.
- Real-time Sensor Data Display View live data from sensors such as temperature, humidity, pressure, and orientation. Visualize sensor readings through charts or graphs for easy interpretation.
- LED Matrix Control Remote control of the LED matrix, allowing users to display custom messages or patterns. Integration with the web interface to design and preview LED matrix animations.
Frontend:
Backend:
You have to install on your Raspberry Pi PHP package.
$ sudo apt install phpIf you wont to use emulator instead of Sense Hat, make sure that it is installed on your device: Installation guide
Modify start_server.sh:
- set proper paths
- set port (by default 8080)
- comment out lines under
"apache server"
Now you can start server and sensors reading by typing following command inside src folder:
$ bash start_server.sh
PHP built-in server does not support SSL/TLS, so if you wont to establish connection with server via https you need to use stunnel4 tool.
- Install apache
$ sudo apt update
$ sudo apt install apache2
$ sudo systemctl enable apache2-
Modify
ServerAdminandDocumentRoot(by default set to/var/www/sense-hat-application/src) properties in.conffiles. -
Copy the contents of the
srcfolder to yourDocumentRootdirectory. -
To enable the site only via port 80 copy
sensehat.local.conffromapache_conf/sites-availablefolder to/etc/apache2/sites-available. Next comment lineRedirect / https://sensehat.local/if uncommented. To enable site use following commands:
$ sudo a2ensite sensehat.local.conf
$ sudo a2dissite 000-default.conf- If you wont to use port 443, copy
sensehatssl.local.conffromapache_conf/sites-availablefolder to/etc/apache2/sites-available. Then, uncomment lineRedirect / https://sensehat.local/in previously copiedsensehat.local.confif commented. To enable the site, use following commands:
$ sudo a2ensite sensehatssl.local.conf
$ sudo a2dissite default-ssl.conf
$ sudo a2enmod ssl- Make sure that properties
SSLCertificateFileandSSLCertificateKeyFilepoints to proper files, if you don't have certificate generated yet, you can use following command to generete self-signed certificate:
$ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/ssl/private/selfsigned.key -out /etc/ssl/certs/selfsigned.crt- Restart apache
$ sudo systemctl restart apache2If you have firewall enabled you should configure it to allow access to apache server via ports 80 and 443.
In order to enable autostart follow these steps:
- Insert
server-autostart.servicefromsrcfolder inside directory:/etc/systemd/system/. - Modify service file and bash script by setting correct paths.
- Change permissions for bash script:
$ chmod +x start_server.sh- Start service:
$ sudo systemctl daemon-reload
$ sudo systemctl enable server-autostart.service
$ sudo systemctl start server-autostart.service- Restart device
$ sudo rebootIf you are having any trouble running the app, check:
- whether the paths in the scripts are correct
- whether the scripts have been granted permissions
- whether you are using the appropriate environment