JNP3 16/17

Dependencies:   mbed nRF24L01P

server/server.py

Committer:
Jan Kopa?ski
Date:
2017-01-11
Revision:
30:27c08888a838
Parent:
16:1569130916f1
Child:
35:0f01042765d6

File content as of revision 30:27c08888a838:

#!/usr/bin/python

from flask import Flask, jsonify
from coapserver import CoAPServer
from databaseconnector import DatabaseConnector

app = Flask(__name__)


host = '46.101.12.31'
coapport = 4242
database = '/home/jan/server/kubus.db'
tables = ['pir1', 'pir2', 'distance', 'volume']
connector = DatabaseConnector(database=database, tables=tables)


@app.route("/")
def all():
    d = connector.read()
    return jsonify(**d)


if __name__ == '__main__':
    coapserver = CoAPServer(host, coapport, tables, connector)
    coapserver.daemon = True
    coapserver.start()
    app.run()
    coapserver.close()