Commit 0bff6759 authored by zwarag's avatar zwarag

Classes work now, but printing not yet

parent 2d2da09b
......@@ -2,12 +2,15 @@
# You need to have a mqtt broker running on for this server to work.
# If you run the broker on a different host/port, change the configuration below
import paho.mqtt.client as mqtt
from flask_restful import Resource, Api
from flask import Flask
from nodes import Nodes
from node import Node
from resources.nodes import Nodes
from resources.node import Node
import json
import pprint
app = Flask(__name__)
api = Api(app)
host = "localhost"
port = 1883
......@@ -22,17 +25,19 @@ def on_connect(client, userdata, flags, rc):
def on_message(client, userdata, msg):
print("[Index] msg: "+msg.topic+" "+json.dumps(json.loads(msg.payload))) # if message is not JSON, programm will crash here without error message.
if(msg.topic == "register"):
client.publish("test", "boo")
def handle_register(payload):
node = Node(payload)
print(json.dumps(nodes.get(), indent = 4))
def hello_world():
return 'Hello World!'
api.add_resource(Nodes, '/nodes');
if __name__ == '__main__':
client = mqtt.Client()
client.on_connect = on_connect
class Nodes:
from flask_restful import Resource
from json import dumps
class Nodes(Resource):
def __init__(self):
self.nodes = {}
......@@ -7,3 +10,6 @@ class Nodes:
self.nodes[] = node
print("[Nodes] Added node with id " +
def get(self):
return dumps(self.nodes)
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment