init_dev_commands.py 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. # coding=utf-8
  2. import os
  3. from base import init_env
  4. init_env(True)
  5. from apps.web.device.models import DeviceCommand, DeviceCommandParam
  6. MQTT_HOSTNAME = os.environ['MQTT_HOSTNAME']
  7. MQTT_PORT = os.environ['MQTT_PORT']
  8. MQTT_PORT_SECURITY = os.environ['MQTT_PORT_SECURITY']
  9. def init_201_cmd():
  10. DeviceCommand(
  11. common=True,
  12. description=u"查询设备",
  13. cmd=201
  14. ).save()
  15. def init_202_turn_on_debug():
  16. param = DeviceCommandParam(
  17. description=u"开关打开",
  18. key="debug",
  19. default="true"
  20. )
  21. cmd = DeviceCommand(
  22. common=True,
  23. description=u"打开调试",
  24. cmd=202
  25. )
  26. cmd.params = [param]
  27. cmd.save()
  28. def init_202_turn_off_debug():
  29. param = DeviceCommandParam(
  30. description=u"开关关闭",
  31. key="debug",
  32. default="false"
  33. )
  34. cmd = DeviceCommand(
  35. common=True,
  36. description=u"关闭调试",
  37. cmd=202
  38. )
  39. cmd.params = [param]
  40. cmd.save()
  41. def init_202_update_driver():
  42. param = DeviceCommandParam(
  43. description=u"驱动地址",
  44. key="driver_set",
  45. default='{"driver_url": "http://121.43.232.118/uploaded/version/drivers/task/*/default.driver"}',
  46. allow_change=True
  47. )
  48. cmd = DeviceCommand(
  49. common=True,
  50. description=u"升级驱动",
  51. cmd=202
  52. )
  53. cmd.params = [param]
  54. cmd.save()
  55. def init_202_update_bin():
  56. param = DeviceCommandParam(
  57. description=u"版本地址",
  58. key="ota_set",
  59. default='{"fw_url": "http://121.43.232.118/uploaded/version/2g/*.bin"}',
  60. allow_change=True
  61. )
  62. cmd = DeviceCommand(
  63. common=True,
  64. description=u"升级版本",
  65. cmd=202
  66. )
  67. cmd.params = [param]
  68. cmd.save()
  69. def init_202_restart_83():
  70. param = DeviceCommandParam(
  71. description=u"重启IP",
  72. key="addr_set",
  73. default='{"ip1": %s, "port1": %s}' % (MQTT_HOSTNAME, MQTT_PORT)
  74. )
  75. cmd = DeviceCommand(
  76. common=True,
  77. description=u"83重启",
  78. cmd=202
  79. )
  80. cmd.params = [param]
  81. cmd.save()
  82. def init_202_restart_84():
  83. param = DeviceCommandParam(
  84. description=u"重启IP",
  85. key="addr_set",
  86. default='{"ip1": %s, "port1": %s}' % (MQTT_HOSTNAME, MQTT_PORT_SECURITY)
  87. )
  88. cmd = DeviceCommand(
  89. common=True,
  90. description=u"84重启",
  91. cmd=202
  92. )
  93. cmd.params = [param]
  94. cmd.save()
  95. def init_210_serial_test():
  96. param1 = DeviceCommandParam(
  97. description=u"功能码",
  98. key="funCode",
  99. default='01',
  100. allow_change=True
  101. )
  102. param2 = DeviceCommandParam(
  103. description=u"数据域",
  104. key="data",
  105. default='00',
  106. allow_change=True
  107. )
  108. cmd = DeviceCommand(
  109. common=True,
  110. description=u"210串口指令",
  111. cmd=210
  112. )
  113. cmd.params = [param1, param2]
  114. cmd.save()
  115. if __name__ == '__main__':
  116. init_201_cmd()
  117. init_202_restart_83()
  118. init_202_restart_84()
  119. init_202_turn_off_debug()
  120. init_202_turn_on_debug()
  121. init_202_update_bin()
  122. init_202_update_driver()
  123. init_210_serial_test()