def gpio_overview(request): mode = pi.getMode() piType = pi.getType() pinList = pi.pins pinListData = [] for pin in pinList: pinStatus = '' pinBCM = pin.getBCM() pinBoard = pin.getBOARD() pinName = pin.getName() pinMode = pin.getMode() if (pinMode == 'IN'): pinStatus = pin.read() elif (pinMode == 'OUT'): pinStatus = pin.getValue() else: pinStatus = '' pinData = {} pinData['pinStatus'] = pinStatus pinData['BCM'] = pinBCM pinData['Physical'] = pinBoard pinData['Name'] = pinName pinData['mode'] = pinMode pinListData.append(pinData) piData = {} piData["mode"] = mode piData["type"] = piType piData["pinList"] = pinListData return ResponseProcessor.processSuccessResponse(piData)
def create_scheduler(request): scheduleName = request.GET.get('scheduleName') scheduleMode = Constants.SCHEDULE_MODE[request.GET.get('scheduleMode')] scheduleValue = int(request.GET.get('scheduleValue')) scheduleJobName = request.GET.get('scheduleJobName') createdScheduler = dao.createScheduler(scheduleName, scheduleMode, scheduleValue, scheduleJobName) return ResponseProcessor.processSuccessResponse( createdScheduler._convertToDict())
def gpio_setPinStatus(request, boardID, level): pin = pi.getPinByBoardId(boardID) setupLevel = None if (level == 1): setupLevel = Pin.PIN_HIGH else: setupLevel = Pin.PIN_LOW if (pin is not None): pin.output_setup(setupLevel) return ResponseProcessor.processSuccessResponse({ 'boardId': boardID, 'level': setupLevel })
def addHistoryChart(request): postBody = request.body postData = json.loads(postBody) piDeviceId = postData['piDeviceID'] deviceDataName = postData['deviceDataName'] title = postData['title'] unit = postData['unit'] displayType = postData['displayType'] resultChart = historyDao.addNewDeviceHistoryChart(piDeviceId, deviceDataName, title, unit, displayType) return ResponseProcessor.processSuccessResponse( resultChart._convertToDict())
def startMotor(request, piDeviceId, direction, speed): pinList = dao.getPiDevicePinByPiDeviceId(piDeviceId) gpioList = [] for pin in pinList: piDevicePinObj = pin._convertToDict() devicePinObj = _getPiDevicePinDetail(piDevicePinObj['devicePinID']) boardID = pin.pinBoardID if (devicePinObj['pinFunction'] == PIN_FUCNTION['GPIO']): gpioList.append(pi.getPinByBoardId(boardID)) motor = Motor(gpioList[0], gpioList[1]) motor.start(direction, speed) motorCacheData = {} motorCacheData['piDeviceId'] = piDeviceId motorCacheData['motorObj'] = motor return ResponseProcessor.processSuccessResponse()
def updateHistoryChart(request, chartId): postBody = request.body postData = json.loads(postBody) piDeviceId = None if ('piDeviceID' not in postData) else postData['piDeviceID'] deviceDataName = None if ('deviceDataName' not in postData) else postData['deviceDataName'] title = None if ('title' not in postData) else postData['title'] unit = None if ('unit' not in postData) else postData['unit'] displayType = None if ('displayType' not in postData) else postData['displayType'] resultChart = historyDao.updateDeviceHistoryChart(chartId, piDeviceId, deviceDataName, title, unit, displayType) return ResponseProcessor.processSuccessResponse( resultChart._convertToDict())
def getHistoryData(request, piDeviceId): dateFrom = request.GET.get('from') dateTo = request.GET.get('to') dateFromObj = None dateToObj = None if (dateFrom is None): dateFromObj = timezone.now() else: dateFromObj = datetime.strptime(dateFrom, '%Y-%m-%d %H:%M:%S') if (dateTo is None): dateToObj = timezone.now() else: dateToObj = datetime.strptime(dateTo, '%Y-%m-%d %H:%M:%S') deviceDataNames = request.GET.get('names') historyDataObjList = _getHistoryData(piDeviceId, dateFromObj, dateToObj, deviceDataNames) return ResponseProcessor.processSuccessResponse(historyDataObjList)
def start_process_scheduler(request): activeScheduleList = dao.findAllActiveScheduler() scheduledJobs = [] for scheduler in activeScheduleList: schedulerObj = scheduler._convertToDict() schedulerId = schedulerObj['id'] jobName = schedulerObj['scheduleJobName'] piDeviceId = schedulerObj['piDeviceID'] scheduleMode = schedulerObj['scheduleMode'] scheduleValue = schedulerObj['scheduleValue'] if (scheduleMode == Constants.SCHEDULE_MODE['SECONDS']): schedule.every(scheduleValue).seconds.do(saveJob, request, piDeviceId) elif (scheduleMode == Constants.SCHEDULE_MODE['MINUTS']): schedule.every(scheduleValue).minutes.do(saveJob, request, piDeviceId) elif (scheduleMode == Constants.SCHEDULE_MODE['HOUR']): schedule.every(scheduleValue).hour.do(saveJob, request, piDeviceId) elif (scheduleMode == Constants.SCHEDULE_MODE['DAY']): schedule.every(scheduleValue).day.do(saveJob, request, piDeviceId) scheduledJobs.append(dao.startAScheduler(schedulerId)._convertToDict()) return ResponseProcessor.processSuccessResponse(scheduledJobs)
def getTodaySingleGraphData(request, piDeviceId, deviceDataName): category = [] data = [] dateFrom = date.today() dateTo = date.today() dateTo = dateTo.replace(day=dateTo.day + 1) print(dateFrom) print(dateTo) # dateFrom = datetime.strptime('2020-04-27 00:00:00', '%Y-%m-%d %H:%M:%S') # dateTo = datetime.strptime('2020-04-28 00:00:00', '%Y-%m-%d %H:%M:%S') listData = _getHistoryData(piDeviceId, dateFrom, dateTo, deviceDataName) for listitem in listData: data.append(listitem['deviceDataValue']) timeObj = listitem['dataDateTime'] timeObj = timeObj.astimezone(pytz.timezone('Asia/Shanghai')) displayTime = timeObj.strftime('%H:%M') category.append(displayTime) result = {} result['category'] = category result['data'] = data return ResponseProcessor.processSuccessResponse(result)
def gpio_getPinStatus(request, boardID): data = None pin = pi.getPinByBoardId(boardID) if (pin is not None): data = pin.read() return ResponseProcessor.processSuccessResponse(data)
def saveJob(request, piDeviceId): data = _saveJob(piDeviceId) return ResponseProcessor.processSuccessResponse(data)
def stop_scheduler(request, schedulerId): scheduler = dao.stopAScheduler(schedulerId) return ResponseProcessor.processSuccessResponse(scheduler._convertToDict())
def getBMP180Data(request, piDeviceId): bmpDataObj = _getBMP180Data(piDeviceId) return ResponseProcessor.processSuccessResponse(bmpDataObj)
def getDHT22Data(request, piDeviceId): dhtDataObj = _getDHT22Data(piDeviceId) return ResponseProcessor.processSuccessResponse(dhtDataObj)
def getRotationCountDataV2(request, piDeviceId): deviceData = _getRotationCountDataV2(piDeviceId) return ResponseProcessor.processSuccessResponse(deviceData)