DIY ESP32 Weather Dashboard

What you will need-

ESP32 part

A pic of an ESP32

If you're into IOT, you may know about the ESP32 boards. They're amazing little microcontrollers like Arduino's but are super-fast, have WiFi and Bluetooth, have WAY more GPIO and have additional features you can check out here.
Note that I'm using a board with the 'esp32' module and not ESP32 S/C series, as they have quite different features.
You can buy them from here. I'm learning how to use it. If you want to get started, I recommend these links: Random Nerd Tutorials or Last Minute Engineers. I suggest you go to this this article for extra reference.


The DHT22 (also known as AM2302) is an easy-to-use, and cheap temperature/humidity sensor which is popular with hobbyists and tinkerers. Although their readings are not so accurate and have a limited range, I'm using them as there's a lot of support (libraries, tutorials) for it. You can buy it here.

I wanted to log data from a DHT22 and then display it on a dashboard on my MacBook. I researched different options like Influx DB, Blynk IOT, Arduino Cloud, Adafruit IO, but they're all paid, and their free plans suck. No offense    So I decided to create my own API! This API uses a simple HTTPPOST method to output the temperature in a JSON format. Here's the code:

Code
View raw code

Install Arduino IDE and the ESP32 core on your computer. I won't go into much detail, but you can find a specific tutorial here. Copy-paste the code in and Arduino IDE and replace "SSID" and "SecretPassword" with your 2.4 GHZ WiFi SSID and Password in lines 5,6.Then press the 'Upload' button. Then wire the ESP32 like the table below. Open the serial monitor, and a link like http://192.168.50.212 will be displayed. Type the link in you favourite browser, and Voila! something like
{
"temperature":34,
"humidity":12,
"heatIndex":32
}
will appear.

Wiring Diagram
ESP32 pin    DHT22 pin
3V → VCC
D2 → Data/SDA (Add a 10KΩ PullUp resistor to 3.3V)
GND → GND/-

Python/computer part

A pic of Matplotlib

So now we have a functional JSON api, so now what do we do with it? JSON is not that easy-to-understand so we'll make a graph to plot the data using Python. You can use any other programming language, but Python is an easy and fun language to code in, so I'm using.Thonny is a easy-to-use, beginner-friendly Python code editor, so we'll use it, but you can use any Python IDE if you want to. Go to the Thonny website and download Thonny. You can learn more about Python on RealPython and W3schools websites. We are going to use a popular plotting library called MatPlotLib and a JSON decoding library callled μjson.
Diagram of steps to install packages

Before you upload your code, open Thonny, then go to Tools > Manage packages and type Ujson and click ujson, then click install. Then click Close, go to Tools > Manage packages and type Matplotlib and click matplotlib. Or JUST FOLLOW THE GIF ABOVE

Replace "http://192.168.50.212" in the code with the link in the serial monitor. Run the code using F5. So, here's the code:

Code
View raw code

So there, we have a free, open-source, and highly customizeable ESP32 DHT22 weather dashboard! Get the code from my Github Repo . See you later for more blogs 😁.