JNP3 16/17

Dependencies:   mbed nRF24L01P

Committer:
Jan Kopa?ski
Date:
Sat Jan 07 02:12:25 2017 +0100
Revision:
16:1569130916f1
Child:
30:27c08888a838
server init

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Jan Kopa?ski 16:1569130916f1 1 from flask import Flask, jsonify
Jan Kopa?ski 16:1569130916f1 2 from coapserver import CoAPServer
Jan Kopa?ski 16:1569130916f1 3 from databaseconnector import DatabaseConnector
Jan Kopa?ski 16:1569130916f1 4
Jan Kopa?ski 16:1569130916f1 5 app = Flask(__name__)
Jan Kopa?ski 16:1569130916f1 6
Jan Kopa?ski 16:1569130916f1 7
Jan Kopa?ski 16:1569130916f1 8 host = '46.101.12.31'
Jan Kopa?ski 16:1569130916f1 9 coapport = 5683
Jan Kopa?ski 16:1569130916f1 10 database = 'kubus.db'
Jan Kopa?ski 16:1569130916f1 11 tables = ['pir1', 'pir2', 'distance', 'volume']
Jan Kopa?ski 16:1569130916f1 12 connector = DatabaseConnector(database=database, tables=tables)
Jan Kopa?ski 16:1569130916f1 13
Jan Kopa?ski 16:1569130916f1 14
Jan Kopa?ski 16:1569130916f1 15 @app.route("/all")
Jan Kopa?ski 16:1569130916f1 16 def all():
Jan Kopa?ski 16:1569130916f1 17 d = connector.read()
Jan Kopa?ski 16:1569130916f1 18 return jsonify(**d)
Jan Kopa?ski 16:1569130916f1 19
Jan Kopa?ski 16:1569130916f1 20
Jan Kopa?ski 16:1569130916f1 21 if __name__ == '__main__':
Jan Kopa?ski 16:1569130916f1 22 coapserver = CoAPServer(host, coapport, tables, connector)
Jan Kopa?ski 16:1569130916f1 23 coapserver.daemon = True
Jan Kopa?ski 16:1569130916f1 24 coapserver.start()
Jan Kopa?ski 16:1569130916f1 25 app.run(host=host)
Jan Kopa?ski 16:1569130916f1 26 coapserver.close()