|
@@ -7,6 +7,8 @@
|
|
"""
|
|
"""
|
|
from demeter import *
|
|
from demeter import *
|
|
import paho.mqtt.client as mqtt
|
|
import paho.mqtt.client as mqtt
|
|
|
|
+from gevent import monkey; monkey.patch_all()
|
|
|
|
+import gevent
|
|
|
|
|
|
class Connect(object):
|
|
class Connect(object):
|
|
|
|
|
|
@@ -30,7 +32,16 @@ class Connect(object):
|
|
def connect(self, client, userdata, flags, rc):
|
|
def connect(self, client, userdata, flags, rc):
|
|
#print("Connected with result code "+str(rc))
|
|
#print("Connected with result code "+str(rc))
|
|
#client.subscribe("sensor/temperature/#")
|
|
#client.subscribe("sensor/temperature/#")
|
|
- client.subscribe("sensor/#")
|
|
|
|
|
|
+
|
|
|
|
+ gevent.joinall([
|
|
|
|
+ gevent.spawn(self.subscribe, client, 'sensor/#'),
|
|
|
|
+ gevent.spawn(self.subscribe, client, 'pic/#'),
|
|
|
|
+ gevent.spawn(self.subscribe, client, 'msg/#'),
|
|
|
|
+ ])
|
|
|
|
+
|
|
|
|
+ @staticmethod
|
|
|
|
+ def subscribe(client, key):
|
|
|
|
+ client.subscribe(key)
|
|
|
|
|
|
def handle(self, key, value):
|
|
def handle(self, key, value):
|
|
Demeter.record(key, value)
|
|
Demeter.record(key, value)
|