install.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. # -*- coding: utf-8 -*-
  2. from demeter.core import *
  3. import os
  4. #cp -R modbus_tk/* /usr/lib/python3.6/site-packages/modbus_tk/
  5. def manage():
  6. model = Demeter.model('manage_admin')
  7. model.id = 1
  8. info = model.select(type='fetchone')
  9. if not info:
  10. model.role_id = 1
  11. model.username = 'admin'
  12. model.mobile = '15810090845'
  13. model.password = '123456'
  14. model.insert()
  15. model = Demeter.model('manage_role')
  16. model.id = 1
  17. info = model.select(type='fetchone')
  18. if not info:
  19. model.name = '管理员'
  20. model.insert()
  21. def farm():
  22. if 'IOT_FARM' in os.environ:
  23. Demeter.config['setting']['farm'] = int(os.environ['IOT_FARM'])
  24. farm_id = Demeter.config['setting']['farm']
  25. model = Demeter.model('farm')
  26. model.id = farm_id
  27. info = model.select(type='fetchone')
  28. if not info:
  29. model.id = farm_id
  30. model.name = '第' + str(farm_id) + '号本地园区';
  31. model.insert()
  32. def device():
  33. # 以下类型只能新增,不能随意更改或删除
  34. # 初始化默认服务
  35. '''
  36. setting_server = (
  37. {'name':'默认mqtt服务(暂时无效)', 'server_type':1, 'server_host': '192.168.33.10', 'server_port':'8010', 'server_time': '200'}
  38. ,{'name':'默认modbusTcp服务', 'server_type':2, 'server_host': '192.168.33.10', 'server_port':'8010', 'server_time': '200'}
  39. )
  40. model = Demeter.model('setting_server')
  41. for value in setting_server:
  42. model.server_type = value['server_type']
  43. model.server_host = value['server_host']
  44. model.server_port = value['server_port']
  45. info = model.select(type='fetchone')
  46. if not info:
  47. model.name = value['name']
  48. model.server_type = value['server_type']
  49. model.server_host = value['server_host']
  50. model.server_port = value['server_port']
  51. model.server_time = value['server_time']
  52. model.insert()
  53. '''
  54. # 初始化默认产品
  55. product = (
  56. {'name':'默认产品', 'key':'product'},
  57. )
  58. model = Demeter.model('setting_product')
  59. for value in product:
  60. model.key = value['key']
  61. info = model.select(type='fetchone')
  62. if not info:
  63. model.key = value['key']
  64. model.name = value['name']
  65. model.insert()
  66. # 初始化设备类型
  67. setting_device_type = (
  68. {'name':'温度', 'key':'temprature', 'unit':'℃'}
  69. ,{'name':'湿度', 'key':'humidity','unit':'%RH'}
  70. ,{'name':'光照', 'key':'light','unit':'LUX'}
  71. ,{'name':'二氧化碳', 'key':'co2','unit':'PPM'}
  72. ,{'name':'风速', 'key':'speed','unit':'km/h'}
  73. ,{'name':'风向', 'key':'direction','unit':'°'}
  74. ,{'name':'PM2.5', 'key':'pm2.5','unit':'μg/m3'}
  75. ,{'name':'电源', 'key':'power','unit':'V'}
  76. ,{'name':'阀门', 'key':'valve','unit':''}
  77. ,{'name':'放风机', 'key':'blower','unit':''}
  78. ,{'name':'卷帘机', 'key':'curtain','unit':'button'}
  79. ,{'name':'灯光', 'key':'lamp','unit':''}
  80. ,{'name':'除湿器', 'key':'airdryer','unit':''}
  81. ,{'name':'大气压', 'key':'atmos','unit':'hpa'}
  82. ,{'name':'开关', 'key':'sw','unit':'状态'}
  83. ,{'name':'流量', 'key':'flow','unit':'立方米'}
  84. ,{'name':'雨雪', 'key':'yuxue','unit':'button'}
  85. ,{'name':'雨量', 'key':'yuliang','unit':'mm'}
  86. ,{'name':'重量', 'key':'weight','unit':'kg'}
  87. ,{'name':'重量', 'key':'g','unit':'g'}
  88. ,{'name':'上限位', 'key':'uplimit','unit':'状态'}
  89. ,{'name':'下限位', 'key':'downlimit','unit':'状态'}
  90. ,{'name':'空气温度', 'key':'air_temp','unit':'℃'}
  91. ,{'name':'空气湿度', 'key':'air_hume','unit':'%'}
  92. ,{'name':'土壤温度', 'key':'soil_temp','unit':'℃'}
  93. ,{'name':'土壤湿度', 'key':'soil_hume','unit':'%'}
  94. ,{'name':'水泵', 'key':'pump','unit':''}
  95. )
  96. model = Demeter.model('setting_device_type')
  97. for value in setting_device_type:
  98. model.key = value['key']
  99. info = model.select(type='fetchone')
  100. if not info:
  101. model.key = value['key']
  102. model.name = value['name']
  103. model.exp = '{n}'
  104. model.unit = value['unit']
  105. model.insert()
  106. # 初始化硬件类型 1/1/2/3/4/5/6
  107. hardware_type = (
  108. {'name':'网关', 'key':'gateway'}
  109. ,{'name':'传感器', 'key':'sensor'}
  110. ,{'name':'控制器', 'key':'control'}
  111. ,{'name':'电源', 'key':'power'}
  112. ,{'name':'状态', 'key':'status'}
  113. ,{'name':'摄像头', 'key':'pic'}
  114. ,{'name':'摄像机', 'key':'camera'}
  115. )
  116. model = Demeter.model('hardware_type')
  117. for value in hardware_type:
  118. model.key = value['key']
  119. info = model.select(type='fetchone')
  120. if not info:
  121. model.key = value['key']
  122. model.name = value['name']
  123. model.insert()
  124. # 初始化消息类型
  125. msg_type = (
  126. {'name':'系统消息', 'key':'system'}
  127. ,{'name':'警告提醒', 'key':'notice'}
  128. ,{'name':'操作提示', 'key':'oper'}
  129. ,{'name':'新闻', 'key':'news'}
  130. )
  131. model = Demeter.model('msg_type')
  132. for value in msg_type:
  133. model.key = value['key']
  134. info = model.select(type='fetchone')
  135. if not info:
  136. model.key = value['key']
  137. model.name = value['name']
  138. model.insert()
  139. # 初始化错误码类型
  140. notice_type = (
  141. {'name':'设备离线', 'key':'offline'}
  142. ,{'name':'请求超时', 'key':'timeout'}
  143. ,{'name':'设备失联', 'key':'outlink'}
  144. ,{'name':'设备响应超时', 'key':'devtimeot'}
  145. )
  146. model = Demeter.model('notice_type')
  147. for value in notice_type:
  148. model.key = value['key']
  149. info = model.select(type='fetchone')
  150. if not info:
  151. model.key = value['key']
  152. model.name = value['name']
  153. model.insert()
  154. manage()
  155. farm()
  156. device()
  157. Demeter.echo('install success!')