Commit d6047e7f authored by Piotr "PHT" Jasiek's avatar Piotr "PHT" Jasiek

Removing DHT11 module

Adding BMP280 module
Adding pressure
parent 3ba0d75b
......@@ -7,66 +7,52 @@ import time
import datetime
from modules.temp import *
from modules.database import *
from modules.dht11 import *
from modules.bmp280 import *
####Adding kernel modules
os.system('modprobe i2c-dev')
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
####
####Constant
outside_sensor = '/sys/bus/w1/devices/28-0000074e18a7/w1_slave'
inside_sensor = '/sys/bus/w1/devices/28-0000074e7326/w1_slave'
desktop_temp_sensor = '/sys/bus/w1/devices/10-00080229a477/w1_slave'
greenhouse_sensor_temp = '/sys/bus/w1/devices/10-00080229721f/w1_slave'
greenhouse_sensor_hum = 17
outside_sensor_hum = 27
outside_sensor = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8, address=0x76)
greenhouse_sensor = BME280(t_mode=BME280_OSAMPLE_8, p_mode=BME280_OSAMPLE_8, h_mode=BME280_OSAMPLE_8, address=0x77)
#outside_sensor = '/sys/bus/w1/devices/28-0000074e18a7/w1_slave'
#inside_sensor = '/sys/bus/w1/devices/28-0000074e7326/w1_slave'
#desktop_temp_sensor = '/sys/bus/w1/devices/10-00080229a477/w1_slave'
#greenhouse_sensor_temp = '/sys/bus/w1/devices/10-00080229721f/w1_slave'
###Requesting time
request_time = datetime.datetime.now().strftime("%s")
###Requesting sensors
temp_outside = get_temp(outside_sensor)
if temp_outside == 85 or temp_outside == 127.5:
temp_outside = get_prev_value('outside_temp')
temp_inside = get_temp(inside_sensor)
if temp_inside == 85 or temp_inside == 127.5:
temp_inside = get_prev_value('inside_temp')
temp_desktop = get_temp(desktop_temp_sensor)
if temp_desktop == 85 or temp_desktop == 127.687:
temp_desktop = get_prev_value('desktop_temp')
###Requesting sensors
temp_greenhouse = get_temp(greenhouse_sensor_temp)
if temp_greenhouse == 85 or temp_greenhouse == 127.687:
temp_greenhouse = get_prev_value('greenhouse_temp')
outside_temp = round(outside_sensor.read_temperature(), 2)
outside_humidity = round(outside_sensor.read_humidity(), 0)
outside_pressure = round(outside_sensor.read_pressure()/100, 1)
greenhouse_temp = round(greenhouse_sensor.read_temperature(), 2)
greenhouse_humidity = round(greenhouse_sensor.read_humidity(), 0)
greenhouse_pressure = round(greenhouse_sensor.read_pressure()/100, 1)
temp_station_controller = get_temp_rpi()
#hum_greenhouse = get_from_dht11(greenhouse_sensor_hum, "hum")
#hum_outside = get_from_dht11(outside_sensor_hum, "hum")
##Upload sensor reading
try:
add_record(request_time, 'outside_temp', temp_outside)
# add_record(request_time, 'outside_hum' , hum_outside)
add_record(request_time, 'inside_temp', temp_inside)
add_record(request_time, 'desktop_temp', temp_desktop)
add_record(request_time, 'greenhouse_temp', temp_greenhouse)
# add_record(request_time, 'greenhouse_hum', hum_greenhouse)
add_record(request_time, 'outside_temp', outside_temp)
add_record(request_time, 'outside_hum' , outside_humidity)
add_record(request_time, 'outside_pressure' , outside_pressure)
# add_record(request_time, 'inside_temp', temp_inside)
# add_record(request_time, 'desktop_temp', temp_desktop)
add_record(request_time, 'greenhouse_temp', greenhouse_temp)
add_record(request_time, 'greenhouse_hum', greenhouse_humidity)
add_record(request_time, 'greenhouse_pressure' , greenhouse_pressure)
add_record(request_time, 'device_proc_temp', temp_station_controller)
except:
print "Mysql Errorr"
#else:
###Debug output
# print "Outside:", temp_outside, "Inside:", temp_inside, "Desktop:", temp_desktop, "Green house:", temp_green_house
This diff is collapsed.
import Adafruit_DHT
def get_from_dht11(pin, type):
sensor = Adafruit_DHT.DHT11
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if type == "hum":
return humidity
elif type == "temp":
return temperature
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import RPi.GPIO as GPIO
import dht11
# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()
def get_humidity(sensor):
instance = dht11.DHT11(sensor)
result = instance.read()
if result.is_valid():
return result.humidity
else:
return result.error_code
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment