def post(self, id): room = Room.query.get(id) if room is None: raise NotFoundError("room not found") data = request.get_json() for device_id in data: device = Devices.query.filter_by(id=device_id).first() remoteDesign = RemoteDesign.query.filter_by( id=device.remote_design_id).first() if device == None: raise NotFoundError("device not found") if remoteDesign.name == "Temperature Slider": status = 24 else: status = 'false' addDevice = RoomStatus(status=status, timestamp=datetime.today()) addDevice.device = device addDevice.room = room db.session.add(addDevice) db.session.commit() room_status = RoomStatus.query.all() # print(">>>>==================================",room_status,len(room_status)) # print("ADD-->") mqtt.publish("smartclassroom/reloadMqtt", "true")
def delete(self, id): room_status = RoomStatus.query.get(id) if room_status == None: raise NotFoundError("room status not found") data = get_room_status_details(room_status) db.session.delete(room_status) db.session.commit() mqtt.publish("smartclassroom/reloadMqtt", "true") log.debug("delete-->")
def irrigation(request): if request.method == 'POST': novo = IrrigationStatus() novo.status = 'ON' if IrrigationStatus.objects.all().exists(): status = IrrigationStatus.objects.latest('id') if status.status == 'ON': novo.status = 'OFF' novo.save() publish(novo.status) return home(request)
def put(self, id): #CONTROL DEVICES current_user = g.current_user room_status = RoomStatus.query.get(id) if room_status == None: raise NotFoundError("room status not found") payload = request.get_json()['value'] log.debug("Received payload: {}".format(payload)) if payload == True: payload = "true" elif payload == False: payload = "false" elif isinstance(payload, int) and payload >= 16 and payload <= 26: payload = int(payload) else: raise InvalidDataError("Invalid payload") data = get_room_status_details(room_status) log.debug("-----publish----") mqtt.publish( "smartclassroom/" + str(data['room_name']) + "/" + str(data['device_name']) + "/" + str(data['ext_topic']), payload)
def on_button_clicked(button, _e): global led, object2, message, state, i2cBus mqtt.publish('button', 'click')