def customCallback(client, userdata, message): print("Motor Run: ") rgb.blueOff() rgb.cyanOn() motor_runner.pulse(5) rgb.cyanOff() rgb.blueOn() print(userdata) print("--------------\n\n")
def pet_activity(): rgb.cyanOff() rgb.whiteZero() message = {} message['time'] =time.asctime( time.localtime(time.time()) ) message['pet_id'] = "oliver" message['photo_path'] = "www.hungrytail.com" message['quantity_eaten'] = "100" message['food_remaing_bowl'] = "100" message['food_remaing'] = "500" messageJson = json.dumps(message) myAWSIoTMQTTClient.publish("device", messageJson, 0) print('Published topic %s: %s\n' % (topic, messageJson)) rgb.whiteOff() rgb.cyanSlow(); print("--------------\n\n")
def physical_button_press(): rgb.cyanOff() rgb.whiteZero() print("Motor Run: ") print("Button was pushed!") message = {} message['action'] = "feedActivity" message['data'] = "1" message['type'] = "buttonDrop" message['quantity_dropped'] = "150" message['food_remaining_container'] = "300" message['timeStamp']=time.asctime( time.localtime(time.time()) ) messageJson = json.dumps(message) myAWSIoTMQTTClient.publish("device", messageJson, 0) print('Published topic %s: %s\n' % (topic, messageJson)) motor_runner.pulse(5) rgb.whiteOff() rgb.cyanSlow(); print("--------------\n\n")
def sch_drop(): rgb.cyanOff() rgb.whiteZero() print("Motor Run: ") print("schedule drop!") motor_runner.pulse(5) message = {} message['action'] = "feedActivity" message['data'] = "1" message['type'] = "scheduleDrop" message['scheduleTime'] = "[7:20]" message['quantity_dropped'] = "150" message['food_remaining_container'] = "300" message['autoFeed'] = "1" message['timeStamp']=time.asctime( time.localtime(time.time()) ) messageJson = json.dumps(message) myAWSIoTMQTTClient.publish("device", messageJson, 0) print('Published topic %s: %s\n' % (topic, messageJson)) rgb.whiteOff() rgb.cyanSlow(); print("--------------\n\n")
def customCallback(client, userdata, message): rgb.cyanOff() rgb.whiteZero() print("Publish Recieved from Server") rgb.whiteOff() rgb.cyanSlow(); print(message.topic); alldata=json.loads(message.payload.decode("utf-8")); action=alldata['action'] if(action=="write"): filename=alldata['fileName'] data=alldata['data'] writeToJSONFile('./',filename,data) message = {} message['success'] = 1 message['timeStamp'] = time.asctime( time.localtime(time.time()) ) messageJson = json.dumps(message) myAWSIoTMQTTClient.publish("device", messageJson, 0) print('Published topic %s: %s\n' % (action, messageJson)) elif(action=='read'): filename=alldata['fileName'] with open(filename) as json_file: data = json.load(json_file) message = {} message['fileName'] = filename message['data'] = data messageJson = json.dumps(message) myAWSIoTMQTTClient.publish("device", messageJson, 0) print('Published topic %s: %s\n' % (action, messageJson)) elif(action=='calibrate'): wieght=alldata['weight'] timestamp=alldata['timeStamp'] message = {} message['success'] = 1 #message['timeStamp'] = time.asctime( time.localtime(time.time()) ) message['timeStamp'] = timestamp messageJson = json.dumps(message) myAWSIoTMQTTClient.publish("device", messageJson, 0) print('Published topic %s: %s\n' % (action, messageJson)) elif(action=='appDrop'): quantity=alldata['quantity'] timestamp=alldata['timeStamp'] #Store Data into SQL, Read in While Loop" button_callback() message = {} message['success'] = 1 message['timeStamp'] = timestamp messageJson = json.dumps(message) myAWSIoTMQTTClient.publish("device", messageJson, 0) print('Published topic %s: %s\n' % (action, messageJson)) elif(action=='deviceStatus'): timestamp=alldata['timeStamp'] message = {} message['colorCode'] = "[125,255,75]" message['food_remaining_bowl'] = "50" message['food_remaining_container'] = "230" message['timeStamp'] = timestamp messageJson = json.dumps(message) myAWSIoTMQTTClient.publish("device", messageJson, 0) print('Published topic %s: %s\n' % (topic, messageJson)) print("--------------\n\n")