Today, I want to start a small series of articles about the Sensor Kit V2.0 provided by www.sunfounder.com. I am planning to use Golang on a Raspberry Pi to interact with the sensors and outputs. As a Golang Library I am using periph.io. I am trying to find interesting use cases for each sensor. The goal of this project is to have a proof of concept for as many sensors as possible.
The idea of today’s project is to switch the Dual-Color LED using a simple HTML form. There are 3 buttons: “Red”, “Green” and off. Each button changes the state of the Dual-Color LED. Maybe the beginning of a new Smart Home?
The code of this example is hosted at github:
The files might change over time whenever I add improvements, but the concept will stay the same as described in this article.
The app is built out of the following parts:
- Interacts with the hardware using periph.io
- Provides a fileserver for the html/js/css in the ./static/ folder
- Provided 3 API endpoints (red, green, off) that change the states of the LED
Simple website with 3 Buttons: Red, Green, Off
Some styles (still quite ugly)
That’s all. Once the app is started, the website can be reached at http://ip-of-raspberry:8080/
Now the LED can be switched with a browser.