Exemplo n.º 1
0
def get_dashboard():
    sensors = Sensor.get_all()
    return render_template(
        "index.html",
        my_string="Wheeeee!",
        temp_sensors=[s for s in sensors if s.sensor_type == "temperature"],
        humidity_sensors=[s for s in sensors if s.sensor_type == "humidity"],
    )
def sensors():
    logging.info('/sensors. method=%s. data=%s', request.method, request.data)
    if request.method == "POST":
        saved_sensor = Sensor.save_sensor_from_json(request)
        if saved_sensor:
            response = jsonify(Sensor.to_json(saved_sensor))
            # response = jsonify(Sensor.to_json(s) for s in saved_sensors)
            response.status_code = 201  # Created
        else:
            response = jsonify({
                'error':
                'Sensor missing required fields. '
                'EXAMPLE JSON: 	sensorFixed = {\"sensor_id\":\"fixed1\",\"fixed\":true, \"lat\":5.394125,\"lon\":-23.287345,\"alt\":841}'
                '				sensorRover = {\"sensor_id\":\"rover1\",\"fixed\":false}'
            })
            response.status_code = 400  # Bad Request

    # GET
    else:
        sensors = Sensor.get_all()
        response = jsonify([Sensor.to_json(s) for s in sensors])
        response.status_code = 200  # Ok

    return response
Exemplo n.º 3
0
def get_sensors():
    return jsonify([s.to_json() for s in Sensor.get_all()]), 200
Exemplo n.º 4
0
def set_version_on_sensors(ver, dev_id):
    for s in Sensor.get_all():
        if s.id.startswith(dev_id + "-"):
            s.firmware_version = str(ver)
    db.session.commit()