Reputation: 13
I am sending Temperature, Humidity and Light sensor data from a remote XBee module to a local one. The remote XBee is connected to a sensor board with STM32 microcontroller and two sensors, the data from the sensors is sent to a microconterller then to XBee in order to transfer it wirelessly to another XBee. I don't have any problem with the microcontroller part. but when I get the data from the remote XBee I want to display it in python. I am getting the correct data but I need to add variable names to my sensor data. for instance the first sensor data is the temperature data which comes as an integer and what I need is to see the temperature sensor values as; Temp = xx(integer values). Here is the python code I used.
#!/usr/bin/python
import serial
from xbee import ZigBee
serial_port = serial.Serial('COM22', 9600)
zb = ZigBee(serial_port)
while True:
try:
print('Data Received from Xbee')
data = zb.wait_read_frame() #Get data for later use
#print data # for debugging only
print data['rf_data']
except KeyboardInterrupt:
break
serial_port.close()
and this is my python sensor data output
Data Received from Xbee
23
32
103
Process finished with exit code -1
Upvotes: 0
Views: 257
Reputation: 236
print 'Temp = {}'.format(data['rf_data'])
where data['rf_data']
is your temperature data
{}
will be replaced but what values you have in the format method in order
So if you have print {} and {}'.format(1,2)
you will print 1 and 2
Upvotes: 0