rabin 4 years ago
parent
commit
92d57772df
8 changed files with 72 additions and 25 deletions
  1. 2 0
      admin.py
  2. 2 0
      admin/page/device.py
  3. 10 2
      admin/page/hardware.py
  4. 2 0
      admin/page/msg.py
  5. 9 3
      admin/page/setting.py
  6. 8 16
      conf/dev.conf
  7. 4 4
      conf/env.conf
  8. 35 0
      service/zeus/core.py

+ 2 - 0
admin.py

@@ -6,5 +6,7 @@
 """
 from demeter.core import *
 
+Demeter.service('core', 'zeus').init()
+
 if __name__ == "__main__":
 	Demeter.webInit('admin')

+ 2 - 0
admin/page/device.py

@@ -410,6 +410,8 @@ class notice_type_path(Load):
 			,thead = (u'ID', u'错误码描述',u'错误码key', u'更新时间')
 			,tbody = ('id', 'name', 'key', 'cdate')
 			,state = False
+			,add = False
+			,edit = False
 		)
 		self.list('notice_type')
 		self.show('list')

+ 10 - 2
admin/page/hardware.py

@@ -72,13 +72,15 @@ class type_path(Load):
 		self.set(
 			name = u'硬件类型'
 			,path = '/hardware/type'
-			,button = ({'name':'重启守护进程','link':'/hardware/restart_cron','ajax':True,'icon':''},{'name':'重启mqtt订阅服务','link':'/hardware/restart_sub','ajax':True,'icon':''},{'name':'重启园区服务','link':'/hardware/restart_front','ajax':True,'icon':''},{'name':'重启后台服务','link':'/hardware/restart_admin','ajax':True,'icon':''},{'name':'重启网站服务','link':'/hardware/restart_web','ajax':True,'icon':''})
+			,button = ({'name':'重启守护进程','link':'/hardware/restart_cron','ajax':True,'icon':''},{'name':'重启mqtt订阅服务','link':'/hardware/restart_sub','ajax':True,'icon':''},{'name':'重启modbus服务','link':'/hardware/restart_modbus','ajax':True,'icon':''},{'name':'重启园区服务','link':'/hardware/restart_front','ajax':True,'icon':''},{'name':'重启后台服务','link':'/hardware/restart_admin','ajax':True,'icon':''})
 			,width = '600'
 			,height = '300'
 			,search = (('name-input-mlike',), (u'类型名称',))
 			,thead = (u'类型ID',u'类型名称',u'类型key', u'更新时间')
 			,tbody = ('id', 'name', 'key', 'cdate')
 			,state = False
+			,add = False
+			,edit = False
 		)
 		self.list('hardware_type')
 		self.show('list')
@@ -108,7 +110,7 @@ class restart_cron_path(Load):
 	@Web.setting
 	def post(self):
 		Shell.popen("ps -ef | grep cron.py | grep -v grep |awk '{print $1}'|xargs kill -9")
-		Shell.popen('/usr/local/demeter/cron.py >/dev/null &')
+		#Shell.popen('/usr/local/demeter/cron.py >/dev/null &')
 
 class restart_sub_path(Load):
 	@Web.auth
@@ -116,6 +118,12 @@ class restart_sub_path(Load):
 	def post(self):
 		Shell.popen("ps -ef | grep sub.py | grep -v grep |awk '{print $1}'|xargs kill -9")
 
+class restart_modbus_path(Load):
+	@Web.auth
+	@Web.setting
+	def post(self):
+		Shell.popen("ps -ef | grep modbus.py | grep -v grep |awk '{print $1}'|xargs kill -9")
+
 class restart_admin_path(Load):
 	@Web.auth
 	@Web.setting

+ 2 - 0
admin/page/msg.py

@@ -81,6 +81,8 @@ class type_path(Load):
 			,thead = (u'类型ID', u'类型名称',u'类型key', u'更新时间')
 			,tbody = ('id', 'name', 'key', 'cdate')
 			,state = False
+			,add = False
+			,edit = False
 		)
 		self.list('msg_type')
 		self.show('list')

+ 9 - 3
admin/page/setting.py

@@ -61,7 +61,9 @@ class product_path(Load):
 			,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'产品名称'))
 			,thead = (u'产品名称',u'产品标识', u'更新时间')
 			,tbody = ('name', 'key','cdate')
-			,state = True
+			,state = False
+			,add = False
+			,edit = False
 		)
 		self.list('setting_product')
 		self.show('list')
@@ -98,7 +100,9 @@ class device_type_path(Load):
 			,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike'), (u'日期范围',u'开始时间',u'截止时间',u'类型名称'))
 			,thead = (u'类型ID', u'类型名称', u'类型标识', u'类型单位', u'更新时间')
 			,tbody = ('id', 'name', 'key', 'unit', 'cdate')
-			,state = True
+			,state = False
+			,add = False
+			,edit = False
 		)
 		self.list('setting_device_type')
 		self.show('list')
@@ -138,7 +142,9 @@ class modbus_code_path(Load):
 			,search = (('label-1','cdate-time-start','cdate-time-end','name-input-mlike','product_id-select-'), (u'日期范围',u'开始时间',u'截止时间',u'设备名称',u'选择产品'))
 			,thead = (u'命令码名称', u'所属产品',u'关联设备类型', u'表达式', u'更新时间')
 			,tbody = ('name', 'product','device_type_key', 'exp', 'cdate')
-			,state = True
+			,state = False
+			,add = False
+			,edit = False
 		)
 		self.data['common']['search_product_id-select-'] = self.service('common').list('setting_product')
 		self.list('setting_modbus_code')

+ 8 - 16
conf/dev.conf

@@ -3,7 +3,7 @@
 [setting]
 ;以下几个配置都是云平台生成
 ;农场名称
-name				= 新农宝盒
+name				= 新农宝盒本地服务
 ;农场id
 farm				= 1
 ;农场站点
@@ -55,7 +55,7 @@ sub					= pic,sensor,control,power
 
 ;后台配置
 [admin]
-port				= 8087
+port				= 8090
 debug				= True
 ;请求的buffersize
 max_buffer_size		= 210763776
@@ -64,7 +64,7 @@ process				= 0
 ;定义后台父级菜单
 menu_parent			= 农场管理:,设备管理:,配置管理:
 ;定义后台子级菜单
-menu_child			= 基础资料:/farm/info?id=1,用户管理:/farm/user,产品管理:/farm/product,地块管理:/work/land,农事管理:/work/work;网关列表:/device/gateway,设备列表:/device/info;产品配置:/setting/product,服务配置:/setting/server,设备类型:/setting/device_type,硬件类型:/hardware/type,MODBUS命令码:/setting/modbus_code
+menu_child			= 基础资料:/farm/info?id=1,用户管理:/farm/user,产品管理:/farm/product,地块管理:/work/land,农事管理:/work/work;网关列表:/device/gateway,设备列表:/device/info;产品配置:/setting/product,服务配置:/setting/server,设备类型:/setting/device_type,硬件类型:/hardware/type,MODBUS命令码:/setting/modbus_code,错误码配置:/device/notice_type,消息类型设置:/msg/type
 
 ;cookie
 cookie_secret       = 61oETzKXQAGaYekL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=
@@ -74,22 +74,14 @@ xsrf_cookies        = True
 
 ;前台配置
 [front]
-port				= 8088
+port				= 8091
 debug				= True
 max_buffer_size		= 210763776
 process				= 0
-url					= http://192.168.33.10:8088/device
+url					= http://192.168.33.10:8091/device
 qrcode				= http://pan.baidu.com/share/qrcode?w=300&h=300&url=
 mobile				= True
 
-;网站前台配置
-[web]
-port                = 8089
-debug               = True
-max_buffer_size     = 210763776
-process             = 0
-;url                    = http://www.xinnongbaohe.com:8089/
-;farmurl                = http://www.xinnongbaohe.com:8089/farm?id=
-url                 = http://www.xinnongbaohe.com/
-farmurl             = http://farm.xinnongbaohe.com/?id=
-originurl           = http://s.xinnongbaohe.com/?id=
+;云端配置
+[zeus]
+host                = http://192.168.33.10:8088/

+ 4 - 4
conf/env.conf

@@ -1,7 +1,7 @@
 [base]
 
 [setting]
-name				= 新农宝盒
+name				= 新农宝盒本地服务
 ;园区默认id,如有cookie,此处的值会自动变成cookie的值
 farm				= 1
 site				= http://www.xinnongbaohe.com/
@@ -48,7 +48,7 @@ sub					= pic,sensor,control,power,status,log
 
 ;后台配置
 [admin]
-port				= 8087
+port				= 8090
 debug				= True
 ;请求的buffersize
 max_buffer_size		= 210763776
@@ -59,11 +59,11 @@ top 				= farm
 
 ;前台配置
 [front]
-port				= 8088
+port				= 8090
 debug				= True
 max_buffer_size		= 210763776
 process				= 0
-;url					= http://www.xinnongbaohe.com:8088/device
+;url					= http://www.xinnongbaohe.com:8090/device
 url					= http://v3.xinnongbaohe.com/device
 qrcode				= http://pan.baidu.com/share/qrcode?w=300&h=300&url=
 mobile				= True

+ 35 - 0
service/zeus/core.py

@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+from demeter.core import *
+
+class Core(object):
+
+    def init(self):
+        # 注册
+        zeus = Demeter.config['zeus']['host']
+        url = zeus + 'interface/init'
+        farm = Demeter.config['setting']['farm']
+        ip = '192.168.33.10'
+        data = Demeter.curl(url, {'id':farm,'ip':ip}, 'post')
+
+
+    # 保存需要同步的数据,定时同步
+    def save(self):
+        pass
+
+    # 实时同步
+    def rsync(self, table):
+        command = Demeter.path + 'sync.py -t ' + table
+        Shell.popen("python3 " + command, bg=True)
+        #self.sync(table)
+
+    # 远程同步
+    def sync(self, table):
+        zeus = Demeter.config['zeus']['host']
+        url = zeus + 'interface/sync'
+        farm = Demeter.config['setting']['farm']
+        data = Demeter.service('common').list(table)
+        param = {}
+        param['data'] = json.dumps(data)
+        param['table'] = table
+        param['farm'] = farm
+        Demeter.curl(url, param, 'post')