COM ポート経由でデータをシリアルに送信するように構成された (Python コード) Digi zigbee デバイスがあります。シリアル通信の反対側には、データを受信する組み込みボードがあります。
デジ(データの送信)を組み込みボードに接続した後、いくつかのデータを送信した後のデジが再起動します(COMポートが閉じます)。しかし、組み込みボードは全期間を通じて生き続けます。
この組み込みボードには、ログを表示できるソフトウェアがあります。ログを確認したところ、いくつかのデータ (3 つのセンサー値) を受信し、デジ デバイスが停止しました。どこで問題が発生しているのかわかりません。データを送信しているdigi-zigbeeデバイスまたはPYTHON CODE(デジデバイスで使用されている)またはデータを受信している組み込みボードですか?
以下は Python ソース コードの一部です。
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)
このコードは、センサーから温度と光の値を取得し、それをパケット (同期、チェックサムなど) に変換して組み込みボードに送信します。