dever 4 years ago
parent
commit
3945855303
6 changed files with 55 additions and 34 deletions
  1. 1 1
      conf/dev.conf
  2. 1 1
      conf/env.conf
  3. 22 0
      mqtt.py
  4. 0 32
      service/cron/mqtt_sub.py
  5. 0 0
      service/mqtt/pubs.py
  6. 31 0
      service/mqtt/subs.py

+ 1 - 1
conf/dev.conf

@@ -52,7 +52,7 @@ password			= public
 timeout				= 60
 ;topic定义
 topic				= method/type/gateway/device
-sub					= pic,sensor,control,power,status,log
+sub					= pic,sensor,power,status,log|control
 
 ;后台配置
 [admin]

+ 1 - 1
conf/env.conf

@@ -44,7 +44,7 @@ password			= public
 timeout				= 60
 ;topic定义
 topic				= method/type/gateway/device
-sub					= pic,sensor,control,power,status,log
+sub                 = pic,sensor,power,status,log|control
 
 ;后台配置
 [admin]

+ 22 - 0
mqtt.py

@@ -0,0 +1,22 @@
+# -*- coding: utf-8 -*-
+"""
+    demeter web
+    name:admin.py
+    author:rabin
+"""
+from demeter.core import *
+
+param = {}
+param['method'] = 'm'
+param['topic'] = 't'
+Demeter.getopt(param)
+
+
+#Demeter.echo(Demeter.option['method'])
+
+method = Demeter.option['method']
+
+if 'topic' in Demeter.option:
+	Demeter.service(method, 'mqtt').load(Demeter.option['topic'])
+else:
+	Demeter.service(method, 'mqtt').run()

+ 0 - 32
service/cron/mqtt_sub.py

@@ -1,32 +0,0 @@
-# -*- coding: utf-8 -*-
-"""
-    demeter web
-    name:sub.py
-    author:rabin
-"""
-import time
-from demeter.core import *
-from demeter.mqtt import *
-timeSleep = 1000
-import random
-class Mqtt_sub(object):
-	def run(self):
-		Sub()
-
-"""
-data = {}
-data['type'] = 'temprature'
-data['gateway'] = '10086'
-data['device'] = '100010'
-data['hard'] = 'sensor'
-data['farm'] = 1
-data['source'] = str(random.randint(1, 50))
-data['value'] = str(random.randint(1, 50))
-
-model = Demeter.model('data', 'tsdb')
-#model.insert(data)
-
-data = model.select(data['farm'], data['device'], type=data['type'], hard=data['hard'], gateway=data['gateway'])
-
-print data
-"""

+ 0 - 0
service/cron/mqtt_pub.py → service/mqtt/pubs.py


+ 31 - 0
service/mqtt/subs.py

@@ -0,0 +1,31 @@
+# -*- coding: utf-8 -*-
+"""
+    demeter web
+    name:sub.py
+    author:rabin
+"""
+import time
+from demeter.core import *
+from demeter.mqtt import *
+timeSleep = 1000
+import random
+class Subs(object):
+
+    def run(self):
+        self.handle()
+        time.sleep(timeSleep)
+
+    def handle(self):
+        topic = Demeter.config['mqtt']['sub'].split('|')
+        if topic:
+            mqtt = Demeter.path + 'mqtt.py'
+            for v in topic:
+                command = 'python3 ' + mqtt + ' -m sub -t ' + v
+
+                check = "ps aux|grep '"+command+"'|grep -v entrypoint|grep -v grep|grep -v process|awk '{print $1}'"
+                check = Shell.popen(check)
+                if not check:
+                    Shell.popen(command)
+
+    def load(self, topic):
+        Sub(topic)