Example #1
0
import time
import ilififowriter

ilififowriter.init_fifo('/dev/mmcblk0p6')

devId = 1
collectionId = devId
sensorId = 'volt'
sampleValueStep = 1.0001
sampleValue = 0
for i in range(10):
	sampleTimestamp = int(time.time())
	sampleValue = sampleValue + sampleValueStep
	ilififowriter.store_sample(sampleTimestamp, collectionId, devId, sensorId, sampleValue)
	time.sleep(5)
	
Example #2
0
# Continuously listen for sensor mote packets and send them to Intelligent.li
print 'Continuously read packets and send them to Intelligent.li'
while True:
	try:
		response = xbee.wait_read_frame()
		msgType = struct.unpack("B", response['rf_data'][0])[0]
		if msgType == 0xf3:
			sourceAddress = ByteToHex(response['source_addr_long'])
			sensorString = response['rf_data'][1:]
			print 'info received from ' + sourceAddress + ': ' + sensorString
			sampleTimestamp = int(time.time())
			deviceID = int(sourceAddress, 16)
			collectionID = deviceID
			# parse the string we received from the sensor mote
			try:
				names = sensorString.split("&")[0].split("=")[1].split(",")
				values = sensorString.split("&")[1].split("=")[1].split(",")
				for idx, val in enumerate(names):
					sensorID = val
					sensorValue = float(filter( lambda x: x in '0123456789.', values[idx])) # cleaning up any funny non-numeric chars
					print 'storing: ' + sensorID + '=' + '%f' % sensorValue
					ilififowriter.store_sample(sampleTimestamp, collectionID, deviceID, sensorID, sensorValue)
			except IndexError:
				print sensorString
		else:
			print 'not a recognised message type.'
	except KeyboardInterrupt:
		break

ser.close()