Exemplo n.º 1
0
def main():

    post = phant.Phant("zD9obXl4K3UM1E0MY5q2", "privateKey")
    (chip_id, chip_version) = bme280.readBME280ID()
    total_temp = 0
    total_pressure = 0
    total_humidity = 0
    cycle_counter = 0
    print "Chip ID     :", chip_id
    print "Version     :", chip_version
    while 1:
        temperature, pressure, humidity = bme280.readBME280All()
        total_temp += temperature
        total_pressure += pressure
        total_humidity += humidity
        cycle_counter += 1
        time.sleep(1)
        if (cycle_counter == 60):
            post.post_data("{0:.2f}".format(total_humidity / cycle_counter),
                           "{0:.2f}".format(total_pressure / cycle_counter),
                           "{0:.2f}".format(total_temp / cycle_counter))
            print "Temperature : ", total_temp / cycle_counter, "C"
            print "Pressure : ", total_pressure / cycle_counter, "hPa"
            print "Humidity : ", total_humidity / cycle_counter, "%"
            total_pressure = total_temp = total_humidity = cycle_counter = 0
Exemplo n.º 2
0
 def test_stats(self):
     with HTTMock(self.server.mock_input, self.server.mock_stats):
         p = phant.Phant(PUBLIC, fields='field', privateKey=PRIVATE)
         p.log(123)
         remaining, used = p.remaining_bytes, p.used_bytes
         self.assertEqual(p.remaining_bytes, remaining)
         self.assertEqual(p.used_bytes, used)
Exemplo n.º 3
0
 def test_stats(self):
     with HTTMock(self.server.mock_input, self.server.mock_stats):
         p = phant.Phant(PUBLIC, 'field', private_key=PRIVATE)
         remaining, used = p.remaining_bytes, p.used_bytes
         p.log(123)
         self.assertLess(p.remaining_bytes, remaining)
         self.assertGreater(p.used_bytes, used)
Exemplo n.º 4
0
		lock.release()
	if (now - last_time) < 5000:
		total_time += (now - last_time)
	speed = distance_per_sense / (now - last_time)
	speed = speed * 3600000
#	if speed < 8:
	lock.acquire()
	sum_speed = sum_speed + speed
	count = count + 1
	avg_speed = (sum_speed) / (count)
#	print "SS: %f, C: %d" % (sum_speed, count)
	lock.release()
	distance += distance_per_sense
	last_time = millis()

p = phant.Phant('REPLACEME', 'distance', 'speed', 'time', private_key='REPLACEME')

next_call = time_.time()

def phantupdate():
	global next_call
	global distance
	global max_speed
	global avg_speed
	global sum_speed
	global count
	global total_time
	global t
	global p
	now = millis()
	if (last_time > 0) and (now - last_time) < 10000 and count > 1:
Exemplo n.º 5
0
#!/usr/bin/env python3

import phant
import time
import serial

# set up serial interface
s = serial.Serial('/dev/ttyUSB1', timeout=1)

# Set up date feed
p = phant.Phant('LQVlgNnAYgcqrljogEzp',
                'temp',
                'localtime',
                private_key="I'm not that stupid.")

while True:

    # Get temp
    s.write(bytearray("x", 'ascii'))  #send a character to start sampling
    temp = str(s.readline(), 'ascii').strip()
    print('Temp: ' + temp)

    # Get time
    ltime = time.strftime("%Y-%m-%d %H:%M:%S")

    p.log(temp, ltime)
    #print(p.remaining_bytes, p.cap)
    #data = p.get()
    #print('Submitted: ')
    #print(data)
    time.sleep(30)