Ejemplo n.º 1
0
def setrelay(projectname, relayid, stateid):
    """ This API call sets the relay state based on relay and project name """
    if request.method == 'POST':
        if int(relayid) > 4 or int(relayid) < 1:
            response = {"???": "Invalid relay id: (" + relayid + ") is > 4"}
            return Response(json.dumps(response),
                            420,
                            mimetype='application/json')
        if int(stateid) > 2:
            response = {"???": "Invalid relay state: (" + stateid + ") is > 2"}
            return Response(json.dumps(response),
                            420,
                            mimetype='application/json')
        canakit = relayobj(projectname)
        canakit.set_relay(relayid, stateid)
        return Response(json.dumps(
            jsontemplate(
                projectname,
                canakit.get_relaystate(1),
                canakit.get_relaystate(2),
                canakit.get_relaystate(3),
                canakit.get_relaystate(4),
                canakit.get_relayupdated(1),
                canakit.get_relayupdated(2),
                canakit.get_relayupdated(3),
                canakit.get_relayupdated(4),
            )),
                        200,
                        mimetype='application/json')
Ejemplo n.º 2
0
def getrelay(projectname):
    """ This API call gets the current relay status """
    canakit = relayobj(projectname)
    if request.method == 'GET':
        return Response( json.dumps( jsontemplate(
                                projectname,
                                canakit.get_relaystate(1), canakit.get_relaystate(2),
                                canakit.get_relaystate(3), canakit.get_relaystate(4),
                                canakit.get_relayupdated(1),canakit.get_relayupdated(2),
                                canakit.get_relayupdated(3),canakit.get_relayupdated(4),
                            ) ),200,mimetype='application/json')
Ejemplo n.º 3
0
def setrelays(projectname,stateid):
    """ This API call sets the relay state based on relay and project name """
    if request.method == 'POST':
        if int(stateid) > 2:
            response =  { "???": "Invalid relay state: (" + stateid + ") is > 2" }
            return Response(json.dumps(response),420,mimetype='application/json')
        canakit = relayobj(projectname)
        for i in [1,2,3,4]:
            canakit.set_relay(i,stateid)
        return Response( json.dumps( jsontemplate(
                                projectname,
                                canakit.get_relaystate(1), canakit.get_relaystate(2),
                                canakit.get_relaystate(3), canakit.get_relaystate(4),
                                canakit.get_relayupdated(1),canakit.get_relayupdated(2),
                                canakit.get_relayupdated(3),canakit.get_relayupdated(4),
                            ) ),200,mimetype='application/json')
Ejemplo n.º 4
0
def getrelay(projectname):
    """ This API call gets the current relay status """
    canakit = relayobj(projectname)
    if request.method == 'GET':
        return Response(json.dumps(
            jsontemplate(
                projectname,
                canakit.get_relaystate(1),
                canakit.get_relaystate(2),
                canakit.get_relaystate(3),
                canakit.get_relaystate(4),
                canakit.get_relayupdated(1),
                canakit.get_relayupdated(2),
                canakit.get_relayupdated(3),
                canakit.get_relayupdated(4),
            )),
                        200,
                        mimetype='application/json')