Post by Oren on Jul 4, 2015 13:59:24 GMT
Hi,
I'm working on this project for quite some time now and can't figure out how to send data out to openhab,
I have set up an Arduino Uno with DHT11 sensor and sent the sensor data to the raspberry pi using I2c protocol (Arduino slave, pi master),
I need to figure what lines of code I need to add to the below code in order to publish sensor data to openhab trough mosquito
the raspberry pi python code and the configuration files are :
I'm working on this project for quite some time now and can't figure out how to send data out to openhab,
I have set up an Arduino Uno with DHT11 sensor and sent the sensor data to the raspberry pi using I2c protocol (Arduino slave, pi master),
I need to figure what lines of code I need to add to the below code in order to publish sensor data to openhab trough mosquito
the raspberry pi python code and the configuration files are :
# sudo nano /opt/openhab/configurations/items/default.items
Group All
Group gGroundFloor (All)
Group GF_Living "Living Room" <video> (gGroundFloor)
Number TestTemperature "Temperature [%.1f C]" <temperature> (GF_Living) {mqtt="<[mymosquitto:home/temperature:st$
# sudo nano /opt/openhab/configurations/sitemaps/default.sitemap
sitemap default label="Main Menu"
{
Frame label="Oren Test" {
Text item=TempC
Text item=Humid
Text item=TempF
Text item=HeatIndx
}
Frame label="Sensor Alarm Status" {
Switch item=gas_alm_sta mappings=[OFF="Off"]
Switch item=flame_alm_sta mappings=[OFF="Off"]
Switch item=sound_alm_sta mappings=[OFF="Off"]
Switch item=pir_alm_sta mappings=[OFF="Off"]
}
}
# -*- coding: utf-8 -*-
import smbus
import time
# RPi rev 2 = SMBus(1) / RPi rev 1 = SMBus(0)
bus = smbus.SMBus(1)
# address of the Arduino use "i2cdetect -y 1" from the RPi prompt to detect the Arduinos (up to 127!)
device = 0x04
# ------------------------------------------------------------------------------------------------------------------------------------------------
# this routine send a request to the Arduino to provide a 30 byte status update, return all 30 bytes
def getStatus(device):
status = ""
for i in range(0, 30):
status += chr(bus.read_byte(device))
time.sleep(0.2);
time.sleep(0.2);
return status
# ------------------------------------------------------------------------------------------------------------------------------------------------
#main program starts
while True:
data_recieved=getStatus(device);
h=data_recieved[0] + data_recieved[1];
t=data_recieved[2] + data_recieved[3];
f=data_recieved[4] + data_recieved[5]+data_recieved[6] + data_recieved[7]+ data_recieved[8];
hi=data_recieved[9] + data_recieved[10]+data_recieved[11] + data_recieved[12]+ data_recieved[13];
print("30 byte status:" + data_recieved);
print("h=" + h);
print("t=" + t);
print("f=" + f);
print("hi=" + hi);