Пример #1
0
def getPiDevicesByDeviceId(request, deviceId):
    piDeviceList = dao.getPiDeviceByDeviceId(deviceId)
    piDeviceObjList = []
    for piDevice in piDeviceList:
        piDeviceObj = piDevice._convertToDict()
        piDeviceObjList.append(piDeviceObj)
    return ResponseProcessor.processSuccessResponse(piDeviceObjList)
Пример #2
0
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)
Пример #3
0
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())
Пример #4
0
def getDevices(request):
    deviceList = dao.getDevices()
    deviceObjList = []
    for device in deviceList:
        deviceObj = device._convertToDict()
        deviceObj['deviceInterfaceType_TR'] = getDictKeyByName(
            INTERFACE, deviceObj['deviceInterfaceType'])
        deviceObjList.append(deviceObj)
    return ResponseProcessor.processSuccessResponse(deviceObjList)
Пример #5
0
def getPiDevices(request):
    deviceList = dao.getPiDevices()
    deviceObjList = []
    for device in deviceList:
        deviceObj = device._convertToDict()
        deviceObj['status_TR'] = getDictKeyByName(STATUS, deviceObj['status'])
        piDevicePinList = _getPiDevicePin(device.id)
        deviceObj['pinList'] = piDevicePinList
        device = _getDeviceById(deviceObj['deviceID'])
        deviceObj['deviceDetail'] = device
        deviceObjList.append(deviceObj)
    return ResponseProcessor.processSuccessResponse(deviceObjList)
Пример #6
0
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
    })
Пример #7
0
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())
Пример #8
0
def led(request, piDeviceId, switch):
    pinList = dao.getPiDevicePinByPiDeviceId(piDeviceId)
    boardID = None
    for pin in pinList:
        piDevicePinObj = pin._convertToDict()
        devicePinObj = _getPiDevicePinDetail(piDevicePinObj['devicePinID'])
        if (devicePinObj['pinFunction'] == PIN_FUCNTION['GPIO']):
            boardID = pin.pinBoardID
    if (boardID is not None):
        led = SimpleEquipt.LED(pi.getPinByBoardId(boardID))
        if (switch == 'on'):
            led.light()
        else:
            led.shutdown()
    return ResponseProcessor.processSuccessResponse()
Пример #9
0
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()
Пример #10
0
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())
Пример #11
0
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)
Пример #12
0
def createPiDevice(request, deviceId):
    name = request.GET.get('name')
    if (name is not None):
        piDevice = dao.addPiDevice(deviceId, name)
        piDeviceObj = piDevice._convertToDict()
        devicePinList = dao.getDevicePinByDeviceId(deviceId)
        devicePinObjList = []
        for devicePin in devicePinList:
            devicePinID = devicePin.id
            piDevicePinObj = dao.addPiDevicePin(piDevice.id, [{
                'pinBoardId': -1,
                'devicePinID': devicePinID,
                'value': None
            }])
            piDevicePinObj = piDevicePinObj[0]
            piDevicePinObj = piDevicePinObj._convertToDict()
            devicePinObjList.append(piDevicePinObj)
        piDeviceObj['pinList'] = devicePinObjList
        return ResponseProcessor.processSuccessResponse(piDeviceObj)
    else:
        return ResponseProcessor.processFailResponse("设备名字为空")
Пример #13
0
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)
Пример #14
0
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)
Пример #15
0
def getRotationCountDataV2(request, piDeviceId):
    deviceData = _getRotationCountDataV2(piDeviceId)
    return ResponseProcessor.processSuccessResponse(deviceData)
Пример #16
0
def init(request):
    InitialDatabaseSetup.run()
    return ResponseProcessor.processSuccessResponse()
Пример #17
0
def getDHT22Data(request, piDeviceId):
    dhtDataObj = _getDHT22Data(piDeviceId)
    return ResponseProcessor.processSuccessResponse(dhtDataObj)
Пример #18
0
def unAttachPiDevicePinToBoard(request, piDevicePinId):
    updatedPiDevicePin = dao.updateDevicePinBoardId(piDevicePinId, -1)
    updatedPiDevicePin = dao.getPiDevicePinById(piDevicePinId)
    return ResponseProcessor.processSuccessResponse(
        updatedPiDevicePin._convertToDict())
Пример #19
0
def attachPiDevicePinToBoard(request, piDevicePinId):
    boardID = request.GET.get('boardId')
    updatedPiDevicePin = dao.updateDevicePinBoardId(piDevicePinId, boardID)
    updatedPiDevicePin = dao.getPiDevicePinById(piDevicePinId)
    return ResponseProcessor.processSuccessResponse(
        updatedPiDevicePin._convertToDict())
Пример #20
0
def deletePiDeviceById(request, piDeviceId):
    dao.deletePiDevice(piDeviceId)
    return ResponseProcessor.processSuccessResponse()
Пример #21
0
def getPiDeviceById(request, piDeviceId):
    piDevice = dao.getPiDeviceById(piDeviceId)
    return ResponseProcessor.processSuccessResponse(piDevice._convertToDict())
Пример #22
0
def gpio_pwn_change_frequency(request, boardID, frequency):
    pin = pi.getPinByBoardId(boardID)
    if (pin is not None):
        pin.PWM_ChangeFrequency(frequency)
    return ResponseProcessor.processSuccessResponse()
Пример #23
0
def gpio_pwn_change_duty_cycle(request, boardID, cycle):
    pin = pi.getPinByBoardId(boardID)
    if (pin is not None):
        pin.PWM_ChangeDutyCycle(cycle)
    return ResponseProcessor.processSuccessResponse()
Пример #24
0
def gpio_getPinStatus(request, boardID):
    data = None
    pin = pi.getPinByBoardId(boardID)
    if (pin is not None):
        data = pin.read()
    return ResponseProcessor.processSuccessResponse(data)
Пример #25
0
def stop_scheduler(request, schedulerId):
    scheduler = dao.stopAScheduler(schedulerId)
    return ResponseProcessor.processSuccessResponse(scheduler._convertToDict())
Пример #26
0
def getBMP180Data(request, piDeviceId):
    bmpDataObj = _getBMP180Data(piDeviceId)
    return ResponseProcessor.processSuccessResponse(bmpDataObj)
Пример #27
0
def updatePiDevice(request, piDeviceId):
    name = request.GET.get('name')
    updatedPiDevice = dao.updatePiDevice(piDeviceId, name)
    return ResponseProcessor.processSuccessResponse(
        updatedPiDevice._convertToDict())
Пример #28
0
def getPiDevicePin(request, piDeviceId):
    devicePinObjList = _getPiDevicePin(piDeviceId)
    return ResponseProcessor.processSuccessResponse(devicePinObjList)
Пример #29
0
def gpio_pwn_start(request, boardID):
    pin = pi.getPinByBoardId(boardID)
    if (pin is not None):
        pin.PWM_setup()
    return ResponseProcessor.processSuccessResponse()
Пример #30
0
def saveJob(request, piDeviceId):
    data = _saveJob(piDeviceId)
    return ResponseProcessor.processSuccessResponse(data)