rabin hace 7 años
padre
commit
a50eaef963
Se han modificado 6 ficheros con 47 adiciones y 12 borrados
  1. 2 1
      admin/page/origin.py
  2. 6 4
      mqtt/connect.py
  3. 16 4
      pub.py
  4. 1 1
      runtime/postgresql/msg_type
  5. 2 2
      service/record.py
  6. 20 0
      service/record_pic.py

+ 2 - 1
admin/page/origin.py

@@ -15,12 +15,13 @@ class batch_path(Load):
 			,path = '/origin/batch'
 			,width = '600'
 			,height = '600'
-			,search = (('farm_id-select-','load_id-select-'), (u'选择农场',u'地块'))
+			,search = (('farm_id-select-','land_id-select-'), (u'选择农场',u'地块'))
 			,thead = (u'所属农场', u'产品名称', u'种植时间', u'采收时间', u'设备', u'地块')
 			,tbody = ('farm','name', 'zzdate', 'csdate', 'device', 'land')
 			,state = True
 		)
 		self.data['common']['search_farm_id-select-'] = Demeter.config['setting']['farmList']
+		self.data['common']['search_land_id-select-'] = self.service('common').list('farm_work_land')
 		self.commonList('origin_batch')
 		if self.data['list']:
 			for key, value in enumerate(self.data['list']):

+ 6 - 4
mqtt/connect.py

@@ -7,8 +7,8 @@
 """
 from demeter import *
 import paho.mqtt.client as mqtt
-from gevent import monkey; monkey.patch_all()
-import gevent
+#from gevent import monkey; monkey.patch_all()
+#import gevent
 
 class Connect(object):
 
@@ -31,13 +31,15 @@ class Connect(object):
 
 	def connect(self, client, userdata, flags, rc):
 		#print("Connected with result code "+str(rc))
-		#client.subscribe("sensor/temperature/#")
-		
+		#client.subscribe("sensor/#")
+		client.subscribe("pic/#")
+		"""
 		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):

+ 16 - 4
pub.py

@@ -8,7 +8,6 @@
 from mqtt.pub import *
 import random
 import time
-import struct
 
 def sensor():
 	# 模拟设备数据
@@ -33,10 +32,23 @@ def pic():
 	gateway = '10086'
 	pub = Pub()
 	key = 'pic/'
-
+	key = 'pic/pic_'
+	gateway = '/' + gateway + '/100001'
 	with open('admin/static/images/banner.png', 'rb') as f:
-		for data in f:
-			print struct.pack('c', data)
+		data = f.readlines()
+		total = len(data)
+		key = key + str(total) + '_'
+		i = 0
+		print key
+		for value in data:
+			k = key + str(i) + gateway
+			pub.push(k, value)
+			print k
+			i = i+1
+
+
+	#with open('test.png', 'w') as f:
+		#f.writelines(data)
 
 	"""
 	handle = open('admin/static/images/banner.png', 'rb')

+ 1 - 1
runtime/postgresql/msg_type

@@ -1 +1 @@
-[["id", 1], ["name", 2], ["key", 3], ["sms", 4], ["state", 5], ["cdate", 6]]
+[["id", 1], ["name", 2], ["key", 3], ["push", 4], ["state", 5], ["cdate", 6]]

+ 2 - 2
service/record.py

@@ -15,5 +15,5 @@ class Record(object):
 	def push(self, key, value):
 		config = self.topic(key)
 		method = 'record_' + config['method']
-		cls = Demeter.getClass(method)
-		cls.handle(config, value)
+		cls = Demeter.getClass(method, 'service.')
+		cls().handle(config, value)

+ 20 - 0
service/record_pic.py

@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+"""
+    demeter service
+    name:record_pic.py 处理摄像头的图片数据
+    author:rabin
+    key:pic/图片名_图片总数_当前序号/gateway/device
+"""
+import time
+import json
+from demeter import *
+class Record_pic(object):
+
+	def handle(self, config, value):
+		print config['type']
+		method = config['type'].split('_')
+		name = method[0]
+		total = method[1]
+		index = method[2]
+