コード例 #1
0
    def test_decode_is_valid_case2(self):
        decoder = UrlDecoder()
        data = decoder.decode_data('AjgbAMFc')

        self.assertEqual(data['temperature'], 27)
        self.assertEqual(data['pressure'], 995)
        self.assertEqual(data['humidity'], 28)
        self.assertEqual(data['identifier'], None)
コード例 #2
0
    def test_decode_is_valid_weatherstation_2017_04_12(self):
        decoder = UrlDecoder()
        data = decoder.decode_data('AjUX1MAw0')

        self.assertEqual(data['temperature'], 25.12)
        self.assertEqual(data['pressure'], 992.0)
        self.assertEqual(data['humidity'], 26.5)
        self.assertEqual(data['identifier'], '0')
コード例 #3
0
def wait_for_finish(run_flag, name):
    max_time = 20

    while run_flag.running:
        time.sleep(0.1)
        max_time -= 0.1
        if max_time < 0:
            raise Exception('%s not finished' % name)


#
# UrlDecoder.decode_data
#
print_header('UrlDecoder.decode_data')

decoder = UrlDecoder()
data = decoder.decode_data('AjwYAMFc')
print(data)

if not data['temperature']:
    raise Exception('FAILED')
else:
    print('OK')

#
# Df3Decoder.decode_data
#
print_header('Df3Decoder.decode_data')

decoder = Df3Decoder()
data = decoder.decode_data('03291A1ECE1EFC18F94202CA0B5300000000BB')
コード例 #4
0

now = time.strftime('%Y-%m-%d %H:%M:%S')
print(now+"\n")

dweetData = {}
dbData = {}

for mac, name in tags.items():
	tag = Rtag(mac, name)

	print("Looking for {} ({})".format(tag._name, tag._mac))
	# if weather station
	if dataFormat == '1': # get parsed data
		encoded = RuuviTagSensor.convert_data(tag.getData());
		data = UrlDecoder().decode_data(encoded[1])
		print ("Data received:", data)

		dbData[tag._mac] = {'name': tag._name}
		# add each sensor with value to the lists
		for sensor, value in data.items():
			dweetData[tag._name+' '+sensor] = value
			dbData[tag._mac].update({sensor: value})

	elif dataFormat == '3': # under development
		print ("Data:", tag.getData())

	else: # if unknown format, just print raw data
		print ("Data:", tag.getData())

	print("\n")