Exemple #1
0
 def test_to_iso(self):
     dtime = iso8601.parse_date('2015-04-15 12:00:00+0300')
     iso_time = utils.to_iso(dtime)
     assert iso_time == '2015-04-15T15:00:00.000000Z'
     dtime = '2015-04-15 12:00:00'
     iso_time = utils.to_iso(dtime)
     assert iso_time == '2015-04-15T15:00:00.000000Z'
Exemple #2
0
 def test_to_iso(self):
     dtime = iso8601.parse_date('2015-04-15 12:00:00+0300')
     iso_time = utils.to_iso(dtime)
     assert iso_time == '2015-04-15T15:00:00.000000Z'
     dtime = '2015-04-15 12:00:00'
     iso_time = utils.to_iso(dtime)
     assert iso_time == '2015-04-15T15:00:00.000000Z'
Exemple #3
0
def get_timestamps(hourly_forecast):
    """
    Returns the timestamps for each hourly forecast as an array of ISO formatted 
    datetime strings.
    """
    timestamps = []
    for datum in hourly_forecast.data:
        try:
            timestamps.append(to_iso(datum.time))
        except:
            print "Error with hourly_forecast timestamp"

    return timestamps
Exemple #4
0
 def run(self):
     print "the run in thread A"
     global flag
     global val  #made global here
     global coordinates
     while True:
         print
         "the while loop in thread A"
         c.acquire()
         if flag == 0:
             print "A: val=", str(val)
             print "A: coordinates=", coordinates
             time.sleep(0.1)
             flag = 1
             val = 30
             postTime = to_iso(datetime.utcnow())
             self.stream.add_value(self.getDistance(), postTime)
             coordinates.put(self.getDistance())
             c.notify_all()
         else:
             c.wait()
         c.release()
Exemple #5
0
tempsensor = OneWireTempSensor(sensor_names[0])

# initialize flow meter
flowmeter = FlowMeter(tempsensor)


# Set up interreupt detection and call backs
def click(channel):
    currentTime = int(time.time() * FlowMeter.MS_IN_A_SECOND)
    if flowmeter.enabled:
        flowmeter.update(currentTime)


GPIO.add_event_detect(22, GPIO.RISING, callback=click, bouncetime=20)

try:
    while True:
        currentTime = int(time.time() * FlowMeter.MS_IN_A_SECOND)
        if (flowmeter.thisFlow > 0.0
                and currentTime - flowmeter.lastClick > 100):
            postTime = to_iso(datetime.utcnow())
            print("Sending values to m2x")
            flow_stream.add_value(flowmeter.getThisFlow(), postTime)
            temp_stream.add_value(flowmeter.checkTempC(), postTime)
            flowmeter.thisFlow = 0.0

except KeyboardInterrupt:
    print("Stopping faucet monitor.")
finally:
    GPIO.cleanup()