def interruption_handler(pin): print("mvt detected") #capture picture file_name = str(uuid4())+".jpeg" capture(file_name) #send notification #wait for command #excecute command payload= struct.pack(">B",1) payload+="mouvement detected".encode() xbee.tx(dest_addr=SERVER_ADDRESS,data=payload) del payload #wait for command from server ## TODO: in case server not found or does not respond #retry a couple of times response = xbee.wait_read_frame() print(response) command = response["rf_data"] #excecute command if command == b'1':#received notification from sensor node print('[+] sending image') sender.send_file(file_name) elif command == b'0':#received file header print('[+] running classification') payload= struct.pack(">B",3) classification_result = classify(file_name) print("image class:"+classification_result) payload += classification_result.encode() xbee.tx(dest_addr=SERVER_ADDRESS,data=payload)
def interruption_handler(pin): file_name = str(uuid.uuid4())+".jpeg" camera = PiCamera() camera.resolution = (299,299) camera.capture(open(file_name,'wb')) camera.close() sender.send_file(file_name)
def excecute_command(command): if command == "1":#received notification from sensor node print('[+] sending image') sender.send_file(file_name) elif command == "0":#received file header print('[+] running classification') payload= struct.pack(">B",3) classification_result = classify(file_name) print("image class:"+classification_result) payload+= classification_result xbee.tx(dest_addr=SERVER_ADDRESS,data=payload)