Creating the Pico W REST Server

With the program’s core components completed, there needs to be a way to have the Prometheus server remotely poll the Pico W’s recorded temperature measurements so these metrics can be visualized on the Grafana instance that was set up previously. Doing so requires setting up a network connection using the onboard Wi-Fi adapter, associating it with your preferred Wi-Fi network’s SSID and related password, and finally creating a simple HTTP server that will deliver the rounded celsius and fahrenheit values as a JSON payload.

Start your program by adding the package definition and the import statement to main.go:

 package​ main
 
 import​ (
 "bufio"
 "encoding/json"
 "io" ...

Get Automate Your Home Using Go now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.