コード例 #1
0
def delstation():
    ret_data = dict()
    if request.method == "POST":
        userlevel = User.get_fromid(current_user.get_id()).level
        if (int(userlevel) == int(User.ADMINLEVEL)):
            sitename = request.form['sitename']
            stationName = request.form['shadowName']
            site = ChargingSite.get_site(sitename)
            if (site == None):
                ret_data['result'] = False
                ret_data['reason'] = 'sitename is invalid'
                print(json.dumps(ret_data))
            else:
                if (site.del_station(stationName) == True):
                    ret_data['result'] = True

                    message = 'delete station ' + stationName
                    message += ' in ' + sitename
                    LogController.addEventLogging(userid=current_user.get_id(),
                                                  detail=message)
                else:
                    ret_data['result'] = False
                    ret_data['reason'] = 'station is invalid or database error'
        else:
            ret_data['result'] = False
            ret_data['reason'] = 'user level is restricetd'
    else:
        ret_data['result'] = False
    return jsonify(ret_data)
コード例 #2
0
def addsite():
    ret_data = dict()
    #if request.method == "GET":
    if request.method == "POST":
        userlevel = User.get_fromid(current_user.get_id()).level
        if (int(userlevel) == int(User.ADMINLEVEL)):

            sitename = request.form['sitename']
            longitude = request.form['longitude']
            latitude = request.form['latitude']

            if (ChargingSite.add_site(sitename, longitude, latitude) == True):
                ret_data['result'] = True
                message = 'new site operation: site name is ' + sitename
                LogController.addEventLogging(userid=current_user.get_id(),
                                              detail=message)
            else:
                ret_data['result'] = False
                ret_data['reason'] = 'adding new site is failed'
        else:
            ret_data['result'] = False
            ret_data['reason'] = 'user level is restricetd'
    else:
        ret_data['result'] = False
    return jsonify(ret_data)
コード例 #3
0
def deluser():
    ret_data = dict()
    try:
        if request.method == 'POST':
            userlevel = User.get_fromid(current_user.get_id()).level
            if (int(userlevel) == int(User.ADMINLEVEL)):
                userid = request.form['userid']
                email = request.form['email']

                if (User.deluser(userid, email)):
                    ret_data['result'] = True

                    ### add event log
                    message = 'deleted user, userid-' + userid + ', email-' + email
                    LogController.addEventLogging(userid=current_user.get_id(),
                                                  detail=message)

                else:
                    ret_data['result'] = False
                    ret_data['reason'] = 'error in deleting user'
            else:
                ret_data['result'] = False
                ret_data['reason'] = 'user level is restricetd'
    except:
        pass

    return jsonify(ret_data)
コード例 #4
0
def adduser():
    ret_data = dict()
    try:
        if request.method == 'POST':
            userlevel = User.get_fromid(current_user.get_id()).level

            if (int(userlevel) == int(User.ADMINLEVEL)):

                userid = request.form['userid']
                email = request.form['email']
                password = request.form['password']
                level = request.form['level']

                if (User.newuser(userid, email, password, int(level))):
                    ret_data['result'] = True

                    ### Add event logging
                    message = 'added new user, userid-' + userid + ', email-' + email
                    LogController.addEventLogging(userid=current_user.get_id(),
                                                  detail=message)

                else:
                    ret_data['result'] = False
                    ret_data[
                        'reason'] = 'error happened in adding user to dynamodb'
            else:
                ret_data['result'] = False
                ret_data['reason'] = 'user level is restricetd'
    except:
        pass
    return jsonify(ret_data)
コード例 #5
0
    def deltaCallback(self, payload, responseStatus, token):
        print("Received a delta message:")
        payloadDict = json.loads(payload)
        deltaMessage = json.dumps(payloadDict["state"])
        print(deltaMessage)

        commandDict = json.loads(deltaMessage)
        commandDict['shadowName'] = self.shadowName
        echo = False

        if ('iotConnected' in commandDict):
            self.iotConnected = commandDict['iotConnected']
            logmsg = ''
            if(self.iotConnected == True):
                logmsg = 'charging station ' + self.shadowName + ' is connected to AWS IOT.'
            else:
                logmsg = 'charging station ' + self.shadowName + ' is disconnected to AWS IOT.'
            LogController.addEventLogging(detail=logmsg)
            echo = True

        if ('station_state' in commandDict):
            self.station_state = commandDict['station_state']
            logmsg = 'charging station ' + self.shadowName + ' state changed to '
            if(self.station_state == EVSE_STATE_A):
                logmsg += 'EV disconnected status'
            elif(self.station_state == EVSE_STATE_B):
                logmsg += 'EV connecetd(charging ready) status'
            elif(self.station_state == EVSE_STATE_C):
                logmsg += 'charging status'
            elif(self.station_state == EVSE_STATE_D):
                logmsg += 'charging completed'

            LogController.addEventLogging(detail=logmsg)
            echo = True

        #if ('charge_max' in commandDict):
        #    self.charge_max = commandDict['charge_max']
        #    echo = True

        if ('charge_min' in commandDict):
            self.charge_min = commandDict['charge_min']
            echo = True

        if ('charge_curr' in commandDict):
            self.charge_curr = commandDict['charge_curr']
            echo = True

        if ('charge_volt' in commandDict):
            self.charge_volt = commandDict['charge_volt']
            echo = True

        if (echo == True):
            print("Request to update the reported state...")
            newPayload = '{"state":{"reported":' + payload + '}}'
            self.deviceShadowInstance.shadowUpdate(newPayload, None, 5)
            print("Sent.")
            if(ChargingStation.deltashadowcallback != None):
                ChargingStation.deltashadowcallback(self)
コード例 #6
0
def delsite():
    ret_data = dict()
    if request.method == "POST":
        userlevel = User.get_fromid(current_user.get_id()).level
        if (int(userlevel) == int(User.ADMINLEVEL)):
            sitename = request.form['sitename']
            if (ChargingSite.del_site(sitename) == True):
                ret_data['result'] = True
                message = 'delete site: site name is ' + sitename
                LogController.addEventLogging(userid=current_user.get_id(),
                                              detail=message)
            else:
                ret_data['result'] = False
                ret_data['reason'] = 'delete site is failed'
        else:
            ret_data['result'] = False
            ret_data['reason'] = 'user level is restricetd'
    else:
        ret_data['result'] = False
    return jsonify(ret_data)
コード例 #7
0
def updatesite():
    ret_data = dict()
    if request.method == 'POST':
        userlevel = User.get_fromid(current_user.get_id()).level
        if (int(userlevel) == int(User.ADMINLEVEL)):

            sitename = request.form['sitename']
            site = ChargingSite.get_site(sitename)

            if (site != None):
                message = ''
                message += 'update site information, site:'
                message += sitename

                if ('serialnumber' in request.form):
                    serialnumber = request.form['serialnumber']
                    message += ', SerialNumber from '
                    message += site.serialNumber
                    message += ' to '
                    message += serialnumber
                else:
                    serialnumber = None

                if ('longitude' in request.form):
                    longitude = request.form['longitude']

                    message += ', longitude from '
                    message += site.longitude
                    message += ' to '
                    message += longitude
                else:
                    longitude = None

                if ('latitude' in request.form):
                    latitude = request.form['latitude']

                    message += ', latitude from '
                    message += site.latitude
                    message += ' to '
                    message += latitude

                else:
                    latitude = None

                if ('supply' in request.form):
                    supply = request.form['supply']
                    message += ', supply from '
                    message += str(site.supply)
                    message += ' to '
                    message += supply
                else:
                    supply = None

                if (ChargingSite.update_site(sitename, serialnumber, longitude,
                                             latitude, supply)):
                    ret_data['result'] = True

                    LogController.addEventLogging(userid=current_user.get_id(),
                                                  detail=message)

                    ### enable socket emit to all client
                    enablesocket()

                else:
                    ret_data['result'] = False
                    ret_data['reason'] = 'Failed to update'
            else:
                ret_data['result'] = False
                ret_data['reason'] = 'sitename does not exist'
        else:
            ret_data['result'] = False
            ret_data['reason'] = 'user level is restricetd'
    else:
        ret_data['result'] = False
    return jsonify(ret_data)
コード例 #8
0
def updatestation():
    ret_data = dict()
    try:
        if request.method == 'POST':
            userlevel = User.get_fromid(current_user.get_id()).level
            if (int(userlevel) == int(User.ADMINLEVEL)):

                sitename = request.form['sitename']
                shadowName = request.form['shadowName']

                site = ChargingSite.get_site(sitename)

                if (site == None):
                    ret_data['result'] = False
                    ret_data['reason'] = 'sitename is invalid'
                else:
                    message = ''
                    message += 'update station information, site:'
                    message += sitename

                    message += ', station:'
                    message += shadowName

                    if ('serialNumber' in request.form):
                        serialNumber = request.form['serialNumber']
                        message += ', SerialNumber:'
                        message += serialNumber
                    else:
                        serialNumber = None

                    if ('charge_max' in request.form):
                        charge_max = int(request.form['charge_max'])
                        message += ', charge_max:'
                        message += str(charge_max)
                    else:
                        charge_max = None

                    if ('activate' in request.form):
                        activate = util.str_to_bool(request.form['activate'])
                        message += ', activate:'
                        message += request.form['activate']
                    else:
                        activate = None

                    if ('present_power' in request.form):
                        present_power = int(request.form['present_power'])
                        message += ', present_power:'
                        message += str(present_power)
                    else:
                        present_power = None

                    if (site.update_station(shadowName, serialNumber,
                                            charge_max, present_power,
                                            activate)):
                        ret_data['result'] = True
                        LogController.addEventLogging(
                            userid=current_user.get_id(), detail=message)
                    else:
                        ret_data['result'] = False
                        ret_data[
                            'reason'] = 'station is invalid or database error'
            else:
                ret_data['result'] = False
                ret_data['reason'] = 'user level is restricetd'
        else:
            ret_data['result'] = False
    except:
        print('error')

    print(json.dumps(ret_data))
    return jsonify(ret_data)
コード例 #9
0
def geteventlist():
    print('event list')
    return LogController.getlogs()