Example #1
0
def save_reading(timestamp, msg, file):
    global logger
    global mote_type
    delay = 0
    if msg.delay >= 5000:
        delay = 0
    else:
        delay = msg.delay
    publish_reading(msg)
    voltage = 0
    if mote_type == 'iris':
        voltage = raw_to_volts_iris(msg.readingVoltage)
    elif mote_type == 'micaz':
        voltage = raw_to_volts_micaz(msg.readingVoltage)
    if msg.source % 10 == 0:
        readingTemperature = 0
        msg.readingLight = 0
    else:
        readingTemperature = raw_to_celcius(msg.readingTemperature)
    logger.info(
        "Mote %d:    Temperature: %f    Light: %d    Voltage: %f    Parent: %d    Metric: %d    Delay: %d"
        % (msg.source, readingTemperature, msg.readingLight, voltage,
           msg.parent, msg.metric, msg.delay))
    file.write("%f %d %d %f %d %f\n" %
               (timestamp - delay, msg.source, msg.seqno, readingTemperature,
                msg.readingLight, voltage))
    file.flush()
Example #2
0
def publish_reading(msg):
    global mote_type
    if mote_type == 'iris':
        voltage = raw_to_volts_iris(msg.readingVoltage)
    elif mote_type == 'micaz':
        voltage = raw_to_volts_micaz(msg.readingVoltage)
    if msg.source % 10 == 0:
        readingTemperature = 0
        msg.readingLight = 0
    else:
        readingTemperature = raw_to_celcius(msg.readingTemperature)
    try:
        event = '%d %d %f %d %f %d %d' % (msg.source, msg.seqno, readingTemperature, msg.readingLight, voltage, msg.parent, msg.metric)
        publish(ALERT_INFO, (datetime.datetime.now() - datetime.timedelta(milliseconds=msg.delay)), event, EXCHANGE_READINGS)
    except TypeError, e:
        print e        
Example #3
0
    def get_value(self):
        value = None
        if self.type == TEMP_MSG:
            value = raw_to_celcius(self.reading)
        elif self.type == BATT_MSG:
            if self.reading > 0:
                if self.mote_type == 'iris':
                    value = raw_to_volts_iris(self.reading)
                elif self.mote_type == 'micaz':
                    value = raw_to_volts_micaz(self.reading)
        elif self.type == LIGHT_MSG:
            value = self.reading
        else:
            global logger
            logger.warning("Unknown message type %d" % (self.type))

        return value
def save_reading(timestamp, msg):#, file):
    global logger 
    global mote_type
    delay = 0
    if msg.delay >= 5000:
        delay = 0
    else:
        delay = msg.delay
    publish_reading(msg)
    voltage = 0
    if mote_type == 'iris':
        voltage = raw_to_volts_iris(msg.readingVoltage)
    elif mote_type == 'micaz':
        voltage = raw_to_volts_micaz(msg.readingVoltage)
    if msg.source % 10 == 0:
        readingTemperature = 0
        msg.readingLight = 0
    else:
        readingTemperature = raw_to_celcius(msg.readingTemperature)
Example #5
0
def save_reading(timestamp, msg):  #, file):
    global logger
    global mote_type
    delay = 0
    if msg.delay >= 5000:
        delay = 0
    else:
        delay = msg.delay
    publish_reading(msg)
    voltage = 0
    if mote_type == 'iris':
        voltage = raw_to_volts_iris(msg.readingVoltage)
    elif mote_type == 'micaz':
        voltage = raw_to_volts_micaz(msg.readingVoltage)
    if msg.source % 10 == 0:
        readingTemperature = 0
        msg.readingLight = 0
    else:
        readingTemperature = raw_to_celcius(msg.readingTemperature)
Example #6
0
def publish_reading(msg):
    global mote_type
    if mote_type == 'iris':
        voltage = raw_to_volts_iris(msg.readingVoltage)
    elif mote_type == 'micaz':
        voltage = raw_to_volts_micaz(msg.readingVoltage)
    if msg.source % 10 == 0:
        readingTemperature = 0
        msg.readingLight = 0
    else:
        readingTemperature = raw_to_celcius(msg.readingTemperature)
    try:
        event = '%d %d %f %d %f %d %d' % (msg.source, msg.seqno,
                                          readingTemperature, msg.readingLight,
                                          voltage, msg.parent, msg.metric)
        publish(ALERT_INFO, (datetime.datetime.now() -
                             datetime.timedelta(milliseconds=msg.delay)),
                event, EXCHANGE_READINGS)
    except TypeError, e:
        print e
def publish_reading(msg):
    global mote_type
    if mote_type == 'iris':
        voltage = raw_to_volts_iris(msg.readingVoltage)
    elif mote_type == 'micaz':
        voltage = raw_to_volts_micaz(msg.readingVoltage)
    if msg.source % 10 == 0:
        readingTemperature = 0
        msg.readingLight = 0
    else:
        readingTemperature = raw_to_celcius(msg.readingTemperature)
    try:
	# 45678|2015-11-11 15:47:37.136511|1|25.229326|237|3.338598|0|10|iris	
	# mote, time, sendCount, readingTemperature, readingLight, readingVoltage, parent, metric, moteModel
        time = (datetime.datetime.now() - datetime.timedelta(milliseconds=msg.delay))       
	event = '%d|%s|%d|%f|%d|%f|%d|%d|%s' % (msg.source, time, msg.seqno, readingTemperature, msg.readingLight, voltage, msg.parent, msg.metric, mote_type)
        ##publish(ALERT_INFO, (datetime.datetime.now() - datetime.timedelta(milliseconds=msg.delay)), event, EXCHANGE_READINGS)
	
	print event
    except TypeError, e:
        print e        
Example #8
0
def save_reading(timestamp, msg, file):
    global logger 
    global mote_type
    delay = 0
    if msg.delay >= 5000:
        delay = 0
    else:
        delay = msg.delay
    publish_reading(msg)
    voltage = 0
    if mote_type == 'iris':
        voltage = raw_to_volts_iris(msg.readingVoltage)
    elif mote_type == 'micaz':
        voltage = raw_to_volts_micaz(msg.readingVoltage)
    if msg.source % 10 == 0:
        readingTemperature = 0
        msg.readingLight = 0
    else:
        readingTemperature = raw_to_celcius(msg.readingTemperature)
    logger.info("Mote %d:    Temperature: %f    Light: %d    Voltage: %f    Parent: %d    Metric: %d    Delay: %d" % (msg.source, readingTemperature, msg.readingLight, voltage, msg.parent, msg.metric, msg.delay))
    file.write("%f %d %d %f %d %f\n" % (timestamp-delay, msg.source, msg.seqno, readingTemperature, msg.readingLight, voltage))
    file.flush()
Example #9
0
def publish_reading(msg):
    global mote_type
    if mote_type == 'iris':
        voltage = raw_to_volts_iris(msg.readingVoltage)
    elif mote_type == 'micaz':
        voltage = raw_to_volts_micaz(msg.readingVoltage)
    if msg.source % 10 == 0:
        readingTemperature = 0
        msg.readingLight = 0
    else:
        readingTemperature = raw_to_celcius(msg.readingTemperature)
    try:
        # 45678|2015-11-11 15:47:37.136511|1|25.229326|237|3.338598|0|10|iris
        # mote, time, sendCount, readingTemperature, readingLight, readingVoltage, parent, metric, moteModel
        time = (datetime.datetime.now() -
                datetime.timedelta(milliseconds=msg.delay))
        event = '%d|%s|%d|%f|%d|%f|%d|%d|%s' % (
            msg.source, time, msg.seqno, readingTemperature, msg.readingLight,
            voltage, msg.parent, msg.metric, mote_type)
        ##publish(ALERT_INFO, (datetime.datetime.now() - datetime.timedelta(milliseconds=msg.delay)), event, EXCHANGE_READINGS)

        print event
    except TypeError, e:
        print e