README.md 2.0 K raw
1
# Pi Widget
2
3
<p align="center">
4
  <img src="https://dweb.mypinata.cloud/ipfs/QmXL9vahr78uxmRQ4LNEFB7k2rQRP8wgYg4jcvZgdVfBPz?img-format=webp" alt="Alt text" width="200" height="auto">
5
</p>
6
7
This little Golang server can be used as a starting point to display your Raspberry Pi stats or any other information you want to display via the web. For my case it also shares information about my [IPFS](https://ipfs.io) node.
8
9
It uses some simple functions to get the data and then sends it through a server-sides events endpoint called  `/events`. There’s a separate `index.html` file that handles the data and renders it on the page. For ease or editing I have made this file embedded so it will be included during the build process.
10
11
## Usage and Deployment
12
13
If you plan to use this for yourself then you will likely want to remove the IPFS stats code from the repo (unless you too happen to be a nerd like me and enjoy messing with that stuff).
14
15
Building is pretty straight forward, however you will want to make sure you have the right target build using the following command:
16
17
```
18
GOOS=linux GOARCH=arm GOARM=6 go build -o ~/pi-widget .
19
```
20
21
You can either build this on device or move it over via SMTP. Once on the Pi it can be spun up simply by running `./pi-widget`. To make this more persistent to you can set up a service like so:
22
23
1. Make a new file under `/etc/systemd/user/pi-widget.service` and put the following contents inside.
24
```
25
[Unit]
26
Description=A little Pi Widget
27
Documentation=https://stevedylan.dev
28
After=network.target
29
30
[Service]
31
Type=simple
32
ExecStart=/home/steve/pi-widget
33
Restart=on-failure
34
KillSignal=SIGINT
35
36
[Install]
37
WantedBy=multi-user.target
38
```
39
40
2. Run the following commands to enable, run, and persist the daemon
41
42
```
43
systemctl --user enable pi-widget
44
systemctl --user start pi-widget
45
loginctl enable-linger $USER
46
```
47
48
With the daemon running out of port `4321` you can setup a [Cloudflare Tunnel](https://developers.cloudflare.com/cloudflare-one/connections/connect-networks/get-started/) pointing to `http://localhost:4321` and have a working site with your stats!