Exemplo n.º 1
0
    def post(self, device_id):
        try:
            if 'UBLOX-HttpClient' not in request.headers.get('User-Agent'):
                rec = prepare_form(request.form.to_dict())
                get_db().update(device_id, rec['htr'], rec['str'], rec['tpr'], rec['pho'], rec['mod'])
                return "OK"
            if 'text/plain' in request.headers.get('Content-type'):
                if 'GPGSV' in request.data:
                    gpgsv_d = {}
                    get_db().update_sat(device_id, gpgsv=request.data)
                    data = request.data.split(',')
                    for key, val in zip(data[::2], data[1::2]):
                        gpgsv_d[key] = val
                    socketio.emit('newgpgsv', gpgsv_d, namespace='/' + str(device_id))
                if 'GPGSA' in request.data:
                    get_db().update_sat(device_id, gpgsa=request.data)
                    data = request.data.split(',')
                    socketio.emit('newgpgsa', {'gpgsa' : data}, namespace='/' + str(device_id))
                return "OK"
            data = json.loads(request.data, cls=Decoder)

            # insert data and change pos if not zero
            get_db().insert(device_id, data['utc'], data['flg'], data['lat'], data['lon'])
            if float(data['lat']) != 0.0 and float(data['lon']) != 0.0:
                socketio.emit('newpos', {'lat': float(data['lat']), 'lng': float(data['lon'])}, namespace='/' + str(device_id))

            # update integrity status
            socketio.emit('integrity', integlist.to_dict(int(data['flg'], 16)), namespace='/' + str(device_id))

            cfg = dict.fromkeys(['cfg'], get_db().is_config(device_id))
            return Response(json.dumps(cfg),  mimetype='application/json')
        except Exception as e:
            print e
            return "Failed"
Exemplo n.º 2
0
def io_newconn(args):
    devid = int(args['device'])

    data = get_db().get_last(devid)
    if data is None:
        return
    last_date = get_db().get_dates(devid)[0]

    print "Refreshing state of... " + str(devid)
    i, addtime, rectime, flags, lat, lon,_ = data

    emit('integrity', integlist.to_dict(int(flags, 16)), namespace='/' + str(devid))
    emit_route(last_date, devid)