Giter Club home page Giter Club logo

kitchensensors's People

Contributors

joncojonathan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kitchensensors's Issues

question only

Hi Jonathan,

Thanks for the script I like it and using it to monitor T&H on a DHT22 connected to an RPi.
For some reason I receive the T&H data in the csv output but not visible in MQTT - only the Temp data.
If you have time and willing to help can you please take a look at the script?

Thanks in advance
Tom

import Adafruit_DHT
import paho.mqtt.client as paho
import os
import time

Define constants

Sensor type (Adafruit_DHT.DHT11 or Adafruit_DHT.DHT22)

DHT_SENSOR = Adafruit_DHT.DHT22

Configure GPIO pins

CUPBOARD_PIN = 2
#FLOOR_PIN = 4
#WASHINGMACHINE_PIN = 27

MQTT details

MQTT_BROKER="192.168.1.131"
MQTT_PORT=1883

Output file name

LOGFILE = "/home/pi/sensors.csv"

##########################################################

Only edit below if you know what you're doing!

##########################################################

def on_publish(client,userdata,result): #create function for callback
print("data published \n")
pass
client1= paho.Client("control1") #create client object
client1.on_publish = on_publish #assign function to callback
client1.connect(MQTT_BROKER,MQTT_PORT) #establish connection

try:
f = open(LOGFILE, 'a+')
if os.stat(LOGFILE).st_size == 0:
f.write('Date,Time,Sensor,Temperature,Humidity\r\n')
except:
pass

cupboardHumidity, cupboardTemperature = Adafruit_DHT.read_retry(DHT_SENSOR, CUPBOARD_PIN)
#floorHumidity, floorTemperature = Adafruit_DHT.read_retry(DHT_SENSOR, FLOOR_PIN)
#washingMachineHumidity, washingMachineTemperature = Adafruit_DHT.read_retry(DHT_SENSOR, WASHINGMACHINE_PIN)

if cupboardHumidity is not None and cupboardTemperature is not None:
ret= client1.publish("akna/temperature","{0:0.1f}".format(cupboardTemperature))
ret= client1.publish("akna/humidity","{0:0.1f}".format(cupboardHumidity))
f.write('{0},{1},akna,{2:0.1f}*C,{3:0.1f}%\r\n'.format(time.strftime('%y-%m-%d'), time.strftime('%H:%M'), cupboardTemperature, cupboardHumidity))
else:
ret= client1.publish("kitchen/cupboard/temperature","FAILED")
print("Failed to retrieve data from cupboard sensor")

#if floorHumidity is not None and floorTemperature is not None:
ret= client1.publish("kitchen/floor/temperature","{0:0.1f}".format(floorTemperature))
ret= client1.publish("kitchen/floor/humidity","{0:0.1f}".format(floorHumidity))
f.write('{0},{1},Floor,{2:0.1f}*C,{3:0.1f}%\r\n'.format(time.strftime('%y-%m-%d'), time.strftime('%H:%M'), floorTemperature, floorHumidity))
#else:
ret= client1.publish("kitchen/floor/temperature","FAILED")
print("Failed to retrieve data from floor sensor")

#if washingMachineHumidity is not None and washingMachineTemperature is not None:
ret= client1.publish("kitchen/washing-machine/temperature","{0:0.1f}".format(washingMachineTemperature))
ret= client1.publish("kitchen/washing-machine/humidity","{0:0.1f}".format(washingMachineHumidity))
f.write('{0},{1},Washing-Machine,{2:0.1f}*C,{3:0.1f}%\r\n'.format(time.strftime('%y-%m-%d'), time.strftime('%H:%M'), washingMachineTemperature, washignMachineHumidity))
#else:
ret= client1.publish("kitchen/washing-machine/temperature","FAILED")
print("Failed to retrieve data from washing-machine sensor")

def on_disconnect(client, userdata, rc):
print("client disconnected ok")
client1.on_disconnect = on_disconnect
client1.disconnect()

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.