rabin 7 anos atrás
pai
commit
a9b2d803ab
3 arquivos alterados com 33 adições e 8 exclusões
  1. 1 1
      mqtt/sub.py
  2. 32 6
      service/record_pic.py
  3. 0 1
      service/record_sensor.py

+ 1 - 1
mqtt/sub.py

@@ -16,5 +16,5 @@ class Sub(object):
 		pass
 
 	def message(self, client, userdata, msg):
-		print(msg.topic+" "+str(msg.payload))
+		#print(msg.topic+" "+str(msg.payload))
 		self.connect.handle(msg.topic, str(msg.payload))

+ 32 - 6
service/record_pic.py

@@ -8,13 +8,39 @@
 """
 import time
 import json
+import uuid
+from datetime import *
 from demeter import *
 class Record_pic(object):
-
+	pic = {}
 	def handle(self, config, value):
-		print config['type']
 		method = config['type'].split('_')
-		name = method[0]
-		total = method[1]
-		index = method[2]
-		
+		name = method[0] + '.jpg'
+		if name not in self.pic:
+			self.pic[name] = {}
+		total = int(method[1])
+		index = int(method[2])
+		self.pic[name][index] = value
+		picLen = len(self.pic[name])
+		if picLen >= total:
+			self.create(name)
+
+	def create(self, name):
+		pic = sorted(self.pic[name].items(), key=lambda e:e[0], reverse=False)
+		data = []
+		day = str(date.today())
+		day = day.split('-')
+		file_name =  str(uuid.uuid5(uuid.uuid1(), 'file'))
+		file_path = day[0] + '/' + day[1] + '/' + day[2]
+		file_path = File.mkdirs(os.path.join(Demeter.path, 'runtime','camera', file_path)) + '/' + Demeter.md5(file_name) + '.jpg'
+
+		for value in pic:
+			data.append(value[1])
+		with open(file_path, 'wb') as f:
+			f.writelines(data)
+			del self.pic[name]
+
+		self.write(file_path)
+
+	def write(self, file):
+		return

+ 0 - 1
service/record_sensor.py

@@ -53,7 +53,6 @@ class Record_sensor(object):
 				data['device'] = config['child']
 				data['hard'] = config['method']
 				data['farm'] = gateway['farm_id']
-				data['time'] = now
 				data['source'] = value
 				data['value'] = show_value