I have a Digi zigbee device which is configured (Python code) to send data serially through a COM port. On the other end of the serial communication there is an embedded board which receives data.
After I connect digi (sending data) to the embedded board, the digi after sending few data reboots (COM PORT closes). But the embedded board remains alive throughout the whole period.
This embedded board has a software through which I can see its logs. When I checked the logs, I received some data (three sensor values) and the digi device dies. I don't know where the problem is occuring. Is it with the digi-zigbee device which is sending data or PYTHON CODE(used in digi device) or the embedded board which is receiving the data?
Here is just a part of python source code :
open()
flushInput()
flushOutput()
while True:
# Retrieve a sample reading from the LT
io_sample = xbee.ddo_get_param(sensor_address, "is")
light = parseIS(io_sample)["AI1"]
temp = parseIS(io_sample)["AI2"]
hum = parseIS(io_sample)["AI3"]
mVanalog = (float(temp) / 1023.0) * 1200.0
temp_C = (mVanalog - 500.0)/ 10.0 # - 4.0
lux = (float(light) / 1023.0) * 1200.0
print "hum:%f" %hum
sync=254
temp=round(temp_C,2)
light=round(lux,2)
no_temp = len(str(temp))
no_light = len(str(light))
total_length=no_temp+no_light+3+3
if total_length<256:
low_byte=total_length
high_byte=0
else:
low_byte=total_length%256
high_byte=high_byte/256
msg_id_low=0
msg_id_high=0
checksum=low_byte+high_byte+msg_id_low+msg_id_high+ord('#')+ord(':')+ord(',')
t=str(temp)
for c in t:
if c == '.':
checksum+=ord('.')
else:
checksum+=ord(c)
t=str(light)
for c in t:
if c == '.':
checksum+=ord('.')
else:
checksum+=ord(c)
checksum=256-(checksum%256)
if checksum == 256:
checksum=0
print "Checksum Value after applying mod operator:%d" %checksum
packet=str(chr(254))+str(chr(low_byte))+str(chr(high_byte))+str(chr(msg_id_low))+str(chr(msg_id_high))+str('#')+str(temp)+str(':')+str(light)+str(',')+str(chr(checksum))
print "packet:%s" %packet
bytes_written = write(packet)
print "bytes_written : %s value : %s" %(bytes_written,packet)
time.sleep(5)
This Code gets the temperature and light value from sensors and converts it into a packet(sync,checksum etc) to be send to the embedded board .