import sys, os
from zigbee import *
from socket import *
from time import sleep
counter = 0
maxcounter = 100
time = 0
maxtime = 5
def sendIt(destination, DestEndpoint, message, bufferLength, cluster):
if cluster == 0x0001: #Cluster 0x0001 response 0x8001 gets sent 2 times from the end device.
x = 2#2 #So we have to clear the buffer twice. May only be Motion sensor.
else: # Yes Only Motion sensor
x = 1
sd = socket(AF_ZIGBEE, SOCK_DGRAM, XBS_PROT_TRANSPORT)
sd.bind(("", DestEndpoint, 0, 0))
print "Sending"
sd.sendto(message, 0, destination)
for x in range(x):
payload, src_addr = sd.recvfrom(bufferLength)
print "Received"
print "src_addr: ", src_addr
print "len(payload): %d" % len(payload)
if ord(payload[1]) == 0:
print "SUCCESS!"
for index, byte in enumerate(payload):
print "payload[%d] = %s (%d)" % (index, hex(ord(byte)), ord(byte))
#sd.close()
sleep(2)
#Hang out here and listen for messages.
while True:
for x in range(1):
payload, src_addr = sd.recvfrom(bufferLength)
print "Received"
print "src_addr: ", src_addr
print "len(payload): %d" % len(payload)
if ord(payload[1]) == 0:
print "SUCCESS!"
for index, byte in enumerate(payload):
print "payload[%d] = %s (%d)" % (index, hex(ord(byte)), ord(byte))
#sd.close()
sleep(2)
print "\n\rZoneIAScrap - "
Destination = ("28:6d:97:00:01:0a:02:3b!", 0x01, 0x0104, 0x0500)
sendIt(Destination, 0x01, "\x00"+"\x01"+"\x02"+"\x10\x00"+"\xf0"+"\x45\x73\x81\x41\x00\xa2\x13\x00", 100, 0x0500)