Esempio n. 1
0
  def __writeDevice(self, id, property, value):
    try:
      ow._put("/%s/%s" % (id, property), value);	
      logging.info("did update device \"%s\" with value \"%s\"", id, value);
		
    except ow.exUnknownSensor:
      logging.error("unknown sensor for deviceId \"%s\" and topic \"%s\"", temp.getId(), temp.getPath());
Esempio n. 2
0
def main_loop():
    """
    The main loop in which we stay connected to the broker
    """
    while True:
	logging.debug(("DeviceList.data is : %s") % (str(DevicesList.data)))
	item = 0
	for device in DevicesList.data:
            # Split up list into relevant parts for reuse
            owserver = DevicesList.data[item][0]
            owport = DevicesList.data[item][1]
            owpath = DevicesList.data[item][2]
	    owsensortype =  DevicesList.data[item][3]

	    logging.debug(("Querying %s on %s:%s") % (owpath, owserver, owport))

            # FIXME owserver to come from a list of devices, and their respective servers
            ow.init(owserver + ":" + owport)
            ow.error_level(ow.error_level.fatal)
            ow.error_print(ow.error_print.stderr)
        
            # FIXME This possibly needs done for each 1-wire host
            # Split it off to the connect() function
            # Enable simultaneous temperature conversion
            ow._put("/simultaneous/temperature","1")
            
            try:
	        # Create sensor object
		logging.debug(("Trying sensor %s with type %s on %s:%s") % (owpath, owsensortype, owserver, owport))
        #        sensor = ow.Sensor(owpath)
         	sensordata = ow.owfs_get(owpath + "/" + owsensortype)       
	#	sensordata = getattr(sensor, owsensortype)

		if (owsensortype == 'temperature' and METRICUNITS == '0'):
		    sensordata = (farenheitCon(float(sensordata)))

		if (owsensortype == 'pressure'):
		    if ("B1-R1-A" in owpath):
		    	pressureoffset = ow.owfs_get(owpath + "/gain")
		    sensordata = (float(sensordata) + float(pressureoffset)) * 0.02953
		
		# if (owsensortype == 'illuminance'):                   
                    # if ("S3-R1-A" in owpath):
                    #   solaroffset = ow.owfs_get(owpath + "/gain")
		    #	sensordata = float(solaroffset) + float(sensordata)
			
                #Query sensor state
                logging.debug(("Sensor %s : %s") % (owpath, sensordata))
	        mqttc.publish(MQTT_TOPIC + owpath + "/" + owsensortype, sensordata)
	        item += 1
	    
	    except ow.exUnknownSensor:
	        logging.debug("Threw an unknown sensor exception for device %s. Continuing", owpath)
	        continue

	# We only want to poll the sensors occasionally... not every one second that's the default for mqttc.loop
	time.sleep(POLLINTERVAL)
Esempio n. 3
0
  def __login(self):
    if (self.__getConfig().getOnewire().getHostname() != None and self.__getConfig().getOnewire().getPort() != None):
	
      ow.init(("%s:%s") % (self.__getConfig().getOnewire().getHostname(), str(self.__getConfig().getOnewire().getPort())));
      ow.error_level(ow.error_level.fatal);
      ow.error_print(ow.error_print.stderr);
	  
      for path, value in self.__getConfig().getOnewire().getInitDevices().items():
        try:
          ow._put(path, value);
        except ow.exUnknownSensor:
          logging.error("unknown sensor for deviceId \"%s\" and topic \"%s\"", temp.getId(), temp.getPath());
	
      return True;
	  
    return False;
Esempio n. 4
0
def main_loop():
    logging.debug(("onewire server : %s") % (OW_HOST))
    logging.debug(("  port         : %s") % (str(OW_PORT)))
    logging.debug(("MQTT broker    : %s") % (MQTT_HOST))
    logging.debug(("  port         : %s") % (str(MQTT_PORT)))
    logging.debug(("pollinterval   : %s") % (str(POLLINTERVAL)))
    logging.debug(("statustopic    : %s") % (str(STATUSTOPIC)))
    logging.debug(("sensors        : %s") % (len(SENSORS)))
    for owid, owtopic in list(SENSORS.items()):
        logging.debug(("  %s : %s") % (owid, owtopic))

    # Connect to the broker and enter the main loop
    mqtt_connect()

    # Connect to the broker and enter the main loop
    ow.init(("%s:%s") % (OW_HOST, str(OW_PORT)))
    ow.error_level(ow.error_level.fatal)
    ow.error_print(ow.error_print.stderr)

    while True:
        # simultaneous temperature conversion
        ow._put("/simultaneous/temperature", "1")
        item = 0
        # iterate over all sensors
        for owid, owtopic in list(SENSORS.items()):
            logging.debug(("Querying %s : %s") % (owid, owtopic))
            try:
                sensor = ow.Sensor(owid)
                owtemp = sensor.temperature
                logging.debug(("Sensor %s : %s") % (owid, owtemp))
                MQTTC.publish(owtopic, owtemp)

            except ow.exUnknownSensor:
                logging.info(
                    "Threw an unknown sensor exception for device %s - %s. Continuing",
                    owid, owname)
                continue

            time.sleep(float(POLLINTERVAL) / len(SENSORS))
def main_loop():
    """
    The main loop in which we stay connected to the broker
    """
    while True:
        logging.debug(("DeviceList.data is : %s") % (str(DevicesList.data)))
        item = 0
        for device in DevicesList.data:
            # Split up list into relevant parts for reuse
            owserver = DevicesList.data[item][0]
            owport = DevicesList.data[item][1]
            owpath = DevicesList.data[item][2]
            logging.debug(("Querying %s on %s:%s") % (owpath, owserver, owport))

            # FIXME owserver to come from a list of devices, and their respective servers
            ow.init(owserver + ":" + owport)
            ow.error_level(ow.error_level.fatal)
            ow.error_print(ow.error_print.stderr)

            # FIXME This possibly needs done for each 1-wire host
            # Split it off to the connect() function
            # Enable simultaneous temperature conversion
            ow._put("/simultaneous/temperature", "1")

            try:
                # Create sensor object
                sensor = ow.Sensor(owpath)

                # Query sensor state
                logging.debug(("Sensor %s : %s") % (owpath, sensor.temperature))
                mqttc.publish(MQTT_TOPIC + owpath, sensor.temperature)
                item += 1

            except ow.exUnknownSensor:
                logging.info("Threw an unknown sensor exception for device %s. Continuing", owpath)
                continue

        # We only want to poll the sensors occasionally... not every one second that's the default for mqttc.loop
        time.sleep(POLLINTERVAL)
Esempio n. 6
0
sleep_interval = 30
epoch_seconds = 450
median_hold_hours = 4

ow.init('127.0.0.1:2840')
ow.error_level(ow.error_level.fatal)
ow.error_print(ow.error_print.stderr)

conn = psycopg.connect("dbname='hcontrol' user='******'")
cur = conn.cursor()

while (1):
#    print time.asctime()
    read_count = 0
# start the simultaneaous temperature conversion on all 1-wire sensors
    ow._put('/simultaneous/temperature','1')

# get the list of sensors to read
    SQL = """SELECT id,ow_id FROM ow_sensors WHERE active = 1"""
    cur.execute(SQL)
    rows = cur.fetchall()

#loop through the rows doing reads and stores
    for row in rows:
        update = 0
        owpath = '/%s' % row[1]
        sensorid = int(row[0])

# create a sensor instance if it doesn't exist
        if (not sensors.has_key(owpath)):
            sensors[owpath] = ow.Sensor(owpath)
Esempio n. 7
0
import ow

if __name__ == "__main__":
    while True:
        # read device list
        with open('devices.json') as json_file:
            devicelist = json.load(json_file)
        # outputlist as dict
        outputlist = {}

        # connect to owfs
        ow.init('localhost:4304')

        # Enable simultaneous temperature conversation
        ow._put("simultaneous/temperature", "1")
        #ow._put("simultaneous/voltage","1")

        # read in connected sensor
        sensorlist = ow.Sensor('/').sensorList()
        #print(sensorlist)

        # loop through sensors and read values
        for sensor in sensorlist:
            try:
                sensorvalues = {}
                #print('Family: ' + sensor.family)
                #print('ID: ' + sensor.id)
                #print('Type: ' + sensor.type)
                sensorvalues["name"] = devicelist[sensor.id]