예제 #1
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)
예제 #2
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;
예제 #3
0
def main_loop():
    """
    main loop 
    """
    logging.debug(("ow.init (%s:%s)") % (args.server, args.port))
    ow.init(("%s:%s") % (args.server, args.port))
    ow.error_level(ow.error_level.fatal)
    ow.error_print(ow.error_print.stderr)
    logging.debug(("Querying %s") % (args.sensor_id))
    try:
        # Create sensor object
        sensor = ow.Sensor(args.sensor_id)
        # Query sensor state
        owtemp = float(sensor.temperature)
        logging.debug(("Sensor %s : %s") % (args.sensor_id, owtemp))

        # Check critical
        if owtemp < args.crit_low or owtemp > args.crit_high:
            # CRITICAL - 24,58 C |temp=24,58;25:35;15:55;0;120
            print(("CRITICAL - %.2f C|temp=%.2f;%s:%s;%s:%s") %
                  (owtemp, owtemp, args.warn_low, args.warn_high,
                   args.crit_low, args.crit_high))
            sys.exit(2)
        elif owtemp < args.warn_low or owtemp > args.warn_high:
            # WARNING - 24,58 C |temp=24,58;25:35;15:55;0;120
            print(("WARNING - %.2f C|temp=%.2f;%s:%s;%s:%s") %
                  (owtemp, owtemp, args.warn_low, args.warn_high,
                   args.crit_low, args.crit_high))
            sys.exit(1)
        else:
            # OK - 24,58 C |temp=24,58;25:35;15:55;0;120
            print(("OK - %.2f C|temp=%.2f;%s:%s;%s:%s") %
                  (owtemp, owtemp, args.warn_low, args.warn_high,
                   args.crit_low, args.crit_high))
            sys.exit(0)

    except ow.exUnknownSensor:
        logging.info("CRITICAL - Sensor %s not found", args.sensor_id)
        print("CRITICAL - Sensor %s not found" % args.sensor_id)
        sys.exit(3)
예제 #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))
예제 #5
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]
            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)
예제 #6
0
activepaths = []
sensors = 
lastread = 
priorread = 
lastmread = 
priormread = 
median = 

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()
예제 #7
0
    choices=["C", "F", "R", "K"],
    help="set the temperature scale: C -  celsius, F - fahrenheit, R - rankine or K - kelvin.",
)
options, args = parser.parse_args()

if len(args) != 2:
    exit(nagios.unknown, "missing command line arguments")

init = args[0]
sensor_path = args[1]

if options.temperature:
    ow.opt(options.temperature)

try:
    ow.error_print(ow.error_print.suppressed)  # needed to exclude debug output which confuses nagios
    ow.init(init)
except ow.exUnknownSensor, ex:
    exit(nagios.unknown[0], "unable to initialize sensor adapter " + str(ex))


pieces = [x for x in sensor_path.split("/") if x]
if len(pieces):
    sensor = "/" + pieces[0]
else:
    sensor = "/"


try:
    s = ow.Sensor(sensor)
except ow.exUnknownSensor, ex:
예제 #8
0
def tree(sensor):
    print "%7s - %s" % (sensor._type, sensor._path)
    for next in sensor.sensors():
        if next._type in ["DS2409"]:
            tree(next)
        else:
            print "%7s - %s" % (next._type, next._path)


if __name__ == "__main__":
    if len(sys.argv) == 1:
        print "usage: errormessages.py u|serial_port_path"
        sys.exit(1)
    else:
        # Turn on the level of message to display
        # ow.error_level(ow.error_level.fatal)
        # ow.error_level(ow.error_level.default)
        # ow.error_level(ow.error_level.connect)
        ow.error_level(ow.error_level.call)
        # ow.error_level(ow.error_level.data)
        # ow.error_level(ow.error_level.debug)

        # Set where the messages are to be displayed
        # ow.error_print(ow.error_print.mixed)
        # ow.error_print(ow.error_print.syslog)
        ow.error_print(ow.error_print.stderr)
        # ow.error_print(ow.error_print.suppressed)

        ow.init(sys.argv[1])
        tree(ow.Sensor("/"))
예제 #9
0
    help=
    'set the temperature scale: C -  celsius, F - fahrenheit, R - rankine or K - kelvin.'
)
options, args = parser.parse_args()

if len(args) != 2:
    exit(nagios.unknown, 'missing command line arguments')

init = args[0]
sensor_path = args[1]

if options.temperature:
    ow.opt(options.temperature)

try:
    ow.error_print(ow.error_print.suppressed
                   )  # needed to exclude debug output which confuses nagios
    ow.init(init)
except ow.exUnknownSensor, ex:
    exit(nagios.unknown[0], 'unable to initialize sensor adapter ' + str(ex))

pieces = [x for x in sensor_path.split('/') if x]
if len(pieces):
    sensor = '/' + pieces[0]
else:
    sensor = '/'

try:
    s = ow.Sensor(sensor)
except ow.exUnknownSensor, ex:
    exit(nagios.unknown, 'unknown sensor ' + str(ex))