In this tutorial, I’ll show you how to grab temperature from a Raspberry Pi and build an endpoint to store the data, with Go. You will learn:

  • How to retrieve the temperature from a sensor
  • How to send that data in JSON
  • Build an API endpoint to receive it
  • Store the data in SQLite database

And we’ll do it all with Go. I did a live stream of the entire process that you can watch here.

What You’ll Need for This Tutorial

I’m using Pop!_OS to develop on, but you can use anything you’d like.

Note: If you’d like to learn more about Raspberry Pi, check out this new course, setting up a Raspberry Pi Home Server.

Why Are We Doing This?

I’ve previously written a tutorial to grab room temperature from a Raspberry Pi, and it’s very similar, only using Python. This is another “hand-rolled” tutorial. Why are we doing this by hand? Why not use a cloud service?

The purpose of this tutorial is to give you a deep understanding of IoT and how it works. You can easily use a cloud provider such as:

These services are great. They’re awesome. If you’re building a real project or working on IoT professionally, this is the way to go. They provide excellent secure services and handle so many things for you.

That’s great, but if you want to truly learn IoT you need to get down to the nuts and bolts. The cloud services have clients you configure, and you push the data up, and it’s visualized for you. In this tutorial, we’re going to build all that stuff ourselves and understand it.

Let’s Rock and Roll!

Connect the Temperature Sensor

The sensor will have three wires coming out from it and will need to be connected to the GPIO of the Raspberry Pi, as shown above.

  • There is a red power wire that goes to pin 1.
  • The black wire is ground and goes to pin 6.
  • The orange (sometimes yellow or white) is data and goes to Pin 11.

It’s pretty simple. If you need additional help, here’s a good guide to hooking up the AM2302.

#internet of things #raspberry pi #golang #raspberry pi tutorial

Get and Store Temperature From a Raspberry Pi With Go - DZone IoT
2.25 GEEK