JNP3 16/17

Dependencies:   mbed nRF24L01P

Committer:
pannaanna
Date:
Mon Jan 23 14:18:23 2017 +0100
Revision:
68:e88f3fd2e9cf
Parent:
35:0f01042765d6
port changed

Who changed what in which revision?

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