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")
myAWSIoTMQTTClient.configureCredentials(rootCAPath) else: myAWSIoTMQTTClient = AWSIoTMQTTClient(clientId) myAWSIoTMQTTClient.configureEndpoint(host, port) myAWSIoTMQTTClient.configureCredentials(rootCAPath, privateKeyPath, certificatePath) # AWSIoTMQTTClient connection configuration myAWSIoTMQTTClient.configureAutoReconnectBackoffTime(1, 32, 20) myAWSIoTMQTTClient.configureOfflinePublishQueueing(-1) # Infinite offline Publish queueing myAWSIoTMQTTClient.configureDrainingFrequency(2) # Draining: 2 Hz myAWSIoTMQTTClient.configureConnectDisconnectTimeout(10) # 10 sec myAWSIoTMQTTClient.configureMQTTOperationTimeout(5) # 5 sec # Connect and subscribe to AWS IoT myAWSIoTMQTTClient.connect() rgb.cyanSlow() with open('schedule.json') as json_data: data = json.load(json_data) data= data['data'] sch= data['feedSchedules'] length=len(sch) - 1 tmp = sch[0] fhour=tmp[0] fmins=tmp[1] fauto=tmp[2] fstat=tmp[3] fwght=tmp[4] if args.mode == 'subscribe':