Get Humidity/Temperature from Web

LAN Bottle server that handles HTTP requests using Raspberry Pi 4, Adafruit DHT11 and a RGB LED.

About

The idea of ​​the project is very simple. After accessing the web page, you can see in real time what temperature and humidity is in the area of ​​the DHT11 sensor used by the Raspberry Pi.

Sending a request to the server will light up the LED in a certain color depending on the route of the request. Then the client will get a response with the requested value and he will also be able to see the color of the diode in the HTML L.E.D. element.

View of circuit implementation

Accesing the web page

Sending a GET request with ‘/’ to the server will automatically light up the R LED attached to the board.

This is what happens on the board after the request.

After getting the response from the server, you will be able to check the temperature and humidity around the board using the blue(humidity) or green(temperature) buttons. Pressing one of the buttons will result in sending requests to the server once every second continuously until the stop button is pressed or until the page is closed/reloaded.

Pressing the blue button

Will change text and L.E.D. colors to blue and display the humidity around the sensor.

Pressing the green button

Will change text and L.E.D. colors to green and display the temperature around the sensor.

Pressing the red-stop button

Will change L.E.D. color to red, set the text value to default and will stop receiving updates about temperature/humidity.

Stop the server using Ctrl+C

After the server stops, the LED is turned off and the GPIO pins are cleaned.

Schematics

Code

from bottle import route, run, template, request
import RPi.GPIO as GPIO
import Adafruit_DHT


#setarea modului de citire a pinilor
GPIO.setmode(GPIO.BCM)


#setare pin senzor umiditate/temperatura
type = Adafruit_DHT.DHT11
dht11 = 25
GPIO.setup(dht11, GPIO.IN)

#setare pini leduri
GPIO.setup(14, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)


#stabilirea rutelor
@route('/')
def index():
    setLedsOnLow()
    GPIO.output(14,GPIO.HIGH)
    return template('index.html')

@route('/umiditate')
def umiditate():
    setLedsOnLow()
    GPIO.output(18,GPIO.HIGH)
    umiditate,temperatura= Adafruit_DHT.read(type, dht11)
    return {'umiditate':umiditate}

@route('/temperatura')
def temperatura():
    setLedsOnLow()
    GPIO.output(15,GPIO.HIGH)
    umidiate,temperatura = Adafruit_DHT.read(type, dht11)
    return {'temperatura':temperatura}

@route('/stop')
def stop():
    setLedsOnLow()
    GPIO.output(14,GPIO.HIGH)
    return {'stop':'Nimic de afisat...'}

def setLedsOnLow():
    GPIO.output(14,GPIO.LOW)
    GPIO.output(15,GPIO.LOW)
    GPIO.output(18,GPIO.LOW)
#start server
run(host = '0.0.0.0', port = '6789')
#la stop server, stinge leduri si curata pini
setLedsOnLow()
GPIO.cleanup()

Source: Get Humidity/Temperature from Web

Current Project / Post can also be found using:

  • how to do humidity project with humidity google chrome
Scroll to Top
Read previous post:
Peanutless-Peanut-MM-Sorter-Homemade-3D-Scanner
Peanut(less) Peanut M&M Sorter – Homemade 3D Scanner

I built a 3D scanner that can predict whether peanut M&Ms have peanuts in the center, or are pure chocolate....

Close