A simple website with buttons that activate a buzzer connected to a raspberry pi which is running a webserver.
Cross-compilation files can be found here
- host a website ✔
- host it on a Raspberry Pi Zero ✔
- the website contains a button that triggers a server-side event ✔
- use the Raspberry Pis GPIO to make a sound ✔
- make the button trigger the sound on the Raspberry Pi ✔
- can use https ✔ (only tested with self-signed certificate at the moment)
- use https
- Connect a buzzer to GPIO 2 (pin #3) on your raspberry pi
- On your main computer install Rust via the
rustup
- see https://rustup.rs/ for instructions - Clone this repository and enter it (run a shell from inside that folder)
- Install the correct target:
$ rustup target add arm-unknown-linux-gnueabihf
- download the toolchain files for crosscompilation\ (you can theoretically compile this directly on your Raspberry Pi, but I haven't actually tested it as it takes ages)
- In
.cargo/config.toml
change the 2 paths under[target.arm-unknown-linux-gnueabihf]
so that they point to the correct location on your machine. - To compile run the command
$ cargo build --release
and wait. Once compiled (successfully) the binary should lie attarget/arm-unknown-linux-gnueabihf/
.
Copy the files
buzzer_control_webserver
(binary file),index.html
,main.js
,key.pem
- your key,cert.pem
- your certificatefavicon.svg
to your Raspberry Pi Zero.
ATTENTION: putindex.html
,main.js
andfavicon.svg
in a different directory than the*.pem
-files! Otherwisekey.pem
can be accessed from outside! That's a BIG NO-NO!- Now you should be able to run the binary
- Specify the location of your website files with
-f <html-directory>
, the port with-p <port>
and the folder that holdskey.pem
andcert.pem
by setting commandline option-t <tls-directory>
.
Example usage:
$ ./buzzer_control_server -f html/ -p 8080 -t certificates/
- use websockets to communicate the state of the buzzer and remove client-side polling