# Temperature Monitoring
# Overview
**Author**: sh224jz
**Project**: Temperature sensor (DHT11) connected to Heltec esp32 LoRa v2 and uploaded to Datacake.
**Estimated time to complete**: 5-10 hours.
# Objective
I chose to make this project to learn more about the basics of IoT and to write code especially in python. This project only serves as a learning platform.
# Material
| Product | Link | Price |
| ------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----- |
| AZDelivery NodeMCU ESP32 Heltec |[Link](https://www.amazon.se/AZDelivery-NodeMCU-Heltec-OLED-skärm-inklusive/dp/B08243JHMW/ref=sr_1_2?crid=3E0EDM0R9FDF9&keywords=heltec+esp32&qid=1656842246&sprefix=heltec+esp32%2Caps%2C94&sr=8-2) | 40$ |
| AZDelivery KY-015 DHT 11 |[Link](https://www.amazon.se/dp/B089W8DB5P/ref=twister_B08C8Z4325?_encoding=UTF8&psc=1) | 7$ |
| AZDelivery Mini Breadboard | [Link](https://www.amazon.se/dp/B07KKJSFM1/ref=twister_B08BFDKJDC?_encoding=UTF8&th=1) | 6$ |
| Elegoo Duplex Kabel | [Link](https://www.amazon.se/Elegoo-Flerfärgad-Breadboard-Bandkablar-Arduino/dp/B01EV70C78/ref=pd_bxgy_img_sccl_1/260-0418443-4154665?pd_rd_w=Bvr2I&content-id=amzn1.sym.ac31a142-07ec-4ec2-a56a-32921a0c41c2&pf_rd_p=ac31a142-07ec-4ec2-a56a-32921a0c41c2&pf_rd_r=PQYNPM0PA5K3B6B8W1F8&pd_rd_wg=2vVjl&pd_rd_r=80dc653c-2777-4b6b-9903-a42a6f8e9ea4&pd_rd_i=B01EV70C78&psc=1) | 8$ |
# Computer setup
**IDE**: Atom with Pymakr
The code is uploaded through Atom and posted on Datacake.
**Follow these links.**
Firmware Update & Running Code
https://hackmd.io/@lnu-iot/By5ZUqvOq
Installing Atom IDE
https://hackmd.io/@lnu-iot/SydH7MTcw
Datacake - WiFi, using MQTT
https://hackmd.io/@lnu-iot/r1aui0B59
# Putting everything together

# Platform
My choice of platform is Datacake, its easy to setup and uses MQTT to send data from the DHT11 sensor via WiFI to the Datacake dashboard. Datacake can be used for free but offers subscription plans.

# Code
```
from mqtt import MQTTClient
import time
import ujson
import machine
import config
from machine import Pin
from dht import DHT
def sub_cb(topic, msg):
print(msg)
# MQTT Setup
client = MQTTClient(config.SERIAL_NUMBER,
config.MQTT_BROKER,
user=config.TOKEN,
password=config.TOKEN,
port=config.PORT)
client.set_callback(sub_cb)
client.connect()
print('connected to MQTT broker')
# The MQTT topic that we publish data to
my_topic = config.TOPIC
# The Pin that DHT11 is connected to
th = DHT(Pin('P19', mode=Pin.OPEN_DRAIN), 0)
while True:
# Get Sensor data and send it to the broker, under topic
time.sleep(2)
result = th.read()
temperature = result.temperature
time.sleep(2)
client.publish(topic=my_topic, msg=str(temperature))
client.check_msg()
print("Data sent to MQTT, sleeping for 20 min")
time.sleep(1194)
```
# Transmitting the data / connectivity
Data is sent every 20 minutes via WiFi using MQTT as transport protocol, data is saved everytime its sent.


# Finalizing the design
