Connect GPIO4 pin with sensor data output, together with 3.3V and GND pins.
# Mount overlay to GPIO 4, and persist it between reboots
sudo sh -c 'echo "dtoverlay=dht11,gpiopin=4" >> /boot/firmware/config.txt'
sudo reboot
# Init .env file, modify and use your own InfluxDB Cloud tokens
cp .env.sample .env
# Do reading
go mod tidy
go run ./...
# Build executable
go build ./src/main.go # Output file will be placed under ./tmpcd ./Demos/golang-gpio && nohup ./tmp/main > output.log 2>&1 &Use with systemd:
# Initiate systemd config file
sudo nano /etc/systemd/system/golang-gpio.service[Unit]
Description=Golang-GPIO
After=network.target
[Service]
ExecStart=/home/pi/Demos/golang-gpio/tmp/main
Restart=always
User=pi
WorkingDirectory=/home/pi/Demos/golang-gpio
[Install]
WantedBy=multi-user.targetAfter that, enable service and start for the first time:
# Enable & start service
sudo systemctl enable golang-gpio.service
sudo systemctl start golang-gpio.service
# Check status
sudo systemctl status golang-gpio.service