Commit 02be7add by 周田

feat:接收从 device 过来的数据

parent 64744a23
...@@ -13,7 +13,7 @@ _sym_db = _symbol_database.Default() ...@@ -13,7 +13,7 @@ _sym_db = _symbol_database.Default()
from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2 from google.protobuf import any_pb2 as google_dot_protobuf_dot_any__pb2
from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2 from google.protobuf import timestamp_pb2 as google_dot_protobuf_dot_timestamp__pb2
import TDSCmd_pb2 as TDSCmd__pb2 from . import TDSCmd_pb2 as TDSCmd_pb2
DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x17\x44\x65vice_datastruct.proto\x1a\x19google/protobuf/any.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x0cTDSCmd.proto\"o\n\x12Proto3DeviceAllCMD\x12\n\n\x02ID\x18\x01 \x01(\x05\x12\x10\n\x08\x44\x45V_NAME\x18\x02 \x01(\t\x12\x15\n\rPROTOCOL_NAME\x18\x03 \x01(\t\x12$\n\x04\x43MDs\x18\x04 \x03(\x0b\x32\x16.Proto3DeviceCMDDefine\"~\n\x15Proto3DeviceCMDDefine\x12\x10\n\x08\x43MD_NAME\x18\x01 \x01(\t\x12\x0e\n\x06\x45NCODE\x18\x02 \x01(\t\x12\x1f\n\x17Timing_CMD_Cycle_period\x18\x03 \x01(\x05\x12\"\n\x06\x66\x65lids\x18\x04 \x03(\x0b\x32\x12.Proto3CMDFieldCfg\"\x9d\x01\n\x17Proto3ForReloadProtocol\x12\x10\n\x08\x64\x65v_name\x18\x01 \x01(\t\x12\x10\n\x08\x63md_name\x18\x02 \x01(\t\x12-\n\x05\x66lags\x18\x03 \x01(\x0e\x32\x1e.Proto3ForReloadProtocol.Flags\"/\n\x05\x46lags\x12\x13\n\x0fNORMAL_DISPATCH\x10\x00\x12\x11\n\rFULL_DISPATCH\x10\x01\"\xa8\x01\n\x19Proto3TableDevCmdNamePoll\x12\n\n\x02id\x18\x01 \x01(\x05\x12\x15\n\rprotocol_name\x18\x02 \x01(\t\x12\x10\n\x08\x63md_name\x18\x03 \x01(\t\x12\x10\n\x08\x63md_type\x18\x04 \x01(\t\x12\x0e\n\x06\x65ncode\x18\x05 \x01(\t\x12\x1f\n\x17timing_cmd_cycle_period\x18\x06 \x01(\x05\x12\x13\n\x0b\x63md_explain\x18\x07 \x01(\t\"\x85\x03\n\x1aProto3TableAllDevCmdDefine\x12\n\n\x02id\x18\x01 \x01(\x05\x12\x10\n\x08\x63md_name\x18\x02 \x01(\t\x12\x10\n\x08\x63md_type\x18\x03 \x01(\t\x12\x12\n\nfieldindex\x18\x04 \x01(\x05\x12\x11\n\tfieldname\x18\x05 \x01(\t\x12\x11\n\tfieldsize\x18\x06 \x01(\x05\x12\r\n\x05value\x18\x07 \x01(\t\x12\x10\n\x08minvalue\x18\x08 \x01(\t\x12\x10\n\x08maxvalue\x18\t \x01(\t\x12\x10\n\x08\x64\x61tatype\x18\n \x01(\x05\x12\x14\n\x0coperation_in\x18\x0b \x01(\x05\x12\x18\n\x10operation_in_num\x18\x0c \x01(\x05\x12\x15\n\roperation_out\x18\r \x01(\x05\x12\x19\n\x11operation_out_num\x18\x0e \x01(\x05\x12\x12\n\noperabo_in\x18\x0f \x01(\x05\x12\x13\n\x0boperabo_out\x18\x10 \x01(\x05\x12\x15\n\rlua_script_in\x18\x11 \x01(\t\x12\x16\n\x0elua_script_out\x18\x12 \x01(\t\"\xa2\x03\n\x13Proto3DeviceInfoCfg\x12\n\n\x02ID\x18\x01 \x01(\x05\x12\x0e\n\x06STA_ID\x18\x02 \x01(\t\x12\x0e\n\x06\x44\x45V_ID\x18\x03 \x01(\x05\x12\x10\n\x08\x44\x45V_NAME\x18\x04 \x01(\t\x12\x14\n\x0c\x44\x45V_NAME_CHN\x18\x05 \x01(\t\x12\x15\n\rPROTOCOL_NAME\x18\x06 \x01(\t\x12\x16\n\x0e\x43MD_EXCEL_PATH\x18\x07 \x01(\t\x12\x17\n\x0f\x43OMUNITATE_MODE\x18\x08 \x01(\t\x12\x0e\n\x06TCP_IP\x18\t \x01(\t\x12\x10\n\x08TCP_PORT\x18\n \x01(\x05\x12\x12\n\nUDP_IP_SRC\x18\x0b \x01(\t\x12\x14\n\x0cUDP_PORT_SRC\x18\x0c \x01(\x05\x12\x12\n\nUDP_IP_DST\x18\r \x01(\t\x12\x14\n\x0cUDP_PORT_DST\x18\x0e \x01(\x05\x12\x10\n\x08UDPMC_IP\x18\x0f \x01(\t\x12\x13\n\x0bUDPMC_IP_TX\x18\x10 \x01(\t\x12\x15\n\rUDPMC_PORT_TX\x18\x11 \x01(\x05\x12\x13\n\x0bUDPMC_IP_RX\x18\x12 \x01(\t\x12\x15\n\rUDPMC_PORT_RX\x18\x13 \x01(\x05\x12\x0f\n\x07REMARKS\x18\x14 \x01(\t\"\xed\x02\n\x11Proto3CMDFieldCfg\x12\n\n\x02ID\x18\x01 \x01(\x05\x12\x12\n\nfieldIndex\x18\x02 \x01(\x05\x12\x11\n\tfieldName\x18\x03 \x01(\t\x12\x11\n\tfieldSize\x18\x04 \x01(\x05\x12\r\n\x05value\x18\x05 \x01(\t\x12\x10\n\x08minValue\x18\x06 \x01(\t\x12\x10\n\x08maxValue\x18\x07 \x01(\t\x12\x10\n\x08\x64\x61taType\x18\x08 \x01(\x05\x12\x14\n\x0coperation_in\x18\t \x01(\x05\x12\x18\n\x10operation_in_num\x18\n \x01(\x05\x12\x15\n\roperation_out\x18\x0b \x01(\x05\x12\x19\n\x11operation_out_num\x18\x0c \x01(\x05\x12\x12\n\noperaBO_in\x18\r \x01(\x05\x12\x13\n\x0boperaBO_out\x18\x0e \x01(\x05\x12\x15\n\rLua_Script_in\x18\x0f \x01(\t\x12\x16\n\x0eLua_Script_out\x18\x10 \x01(\t\x12\x13\n\x0bvalue_bytes\x18\x13 \x01(\x0c\"\xaa\x01\n\x1cProto3TableSoftLimitAngleCfg\x12\n\n\x02ID\x18\x01 \x01(\x05\x12\x0e\n\x06STA_ID\x18\x02 \x01(\t\x12\x10\n\x08\x44\x45V_NAME\x18\x03 \x01(\t\x12\x14\n\x0c\x44\x45V_NAME_CHN\x18\x04 \x01(\t\x12\x15\n\rPROTOCOL_NAME\x18\x05 \x01(\t\x12\x1e\n\x16PITCH_SOFT_LIMIT_ANGLE\x18\x06 \x01(\t\x12\x0f\n\x07REMARKS\x18\x07 \x01(\t\"\xd9\x02\n\x0bTDSDBC_CURD\x12\r\n\x05table\x18\x01 \x01(\t\x12!\n\x05\x66lags\x18\x02 \x01(\x0e\x32\x12.TDSDBC_CURD.Flags\x12)\n\toperation\x18\x03 \x01(\x0e\x32\x16.TDSDBC_CURD.Operation\x12\x18\n\x04\x63ode\x18\x04 \x01(\x0e\x32\n.CodeValue\x12\x0b\n\x03msg\x18\x05 \x01(\t\x12\x0f\n\x07msg_CHN\x18\x06 \x01(\t\x12&\n\x08\x61ny_data\x18\x07 \x03(\x0b\x32\x14.google.protobuf.Any\"/\n\x05\x46lags\x12\x13\n\x0fNORMAL_DISPATCH\x10\x00\x12\x11\n\rFULL_DISPATCH\x10\x01\"\\\n\tOperation\x12\x11\n\rOPERATION_ADD\x10\x00\x12\x11\n\rOPERATION_DEL\x10\x01\x12\x14\n\x10OPERATION_UPDATE\x10\x02\x12\x13\n\x0fOPERATION_QUERY\x10\x03\"\xbc\x01\n\x11TDSXDC_Device_cmd\x12\x10\n\x08\x44\x65viceID\x18\x01 \x01(\r\x12\x10\n\x08\x64\x65v_name\x18\x02 \x01(\t\x12\x10\n\x08\x63md_name\x18\x03 \x01(\t\x12\x15\n\rprotocol_name\x18\x04 \x01(\t\x12\x18\n\x04\x63ode\x18\x05 \x01(\x0e\x32\n.CodeValue\x12\x0b\n\x03msg\x18\x06 \x01(\t\x12\x0f\n\x07msg_CHN\x18\x07 \x01(\t\x12\"\n\x06\x66ields\x18\x08 \x03(\x0b\x32\x12.Proto3CMDFieldCfg*\x7f\n\x0e\x41larmID_define\x12\x0b\n\x07ID_Base\x10\x00\x12\x15\n\x0e\x44\x65vAla_id_Base\x10\x80\x87\xa7\x0e\x12\x18\n\x11\x44\x65vAla_id_Offline\x10\x81\x87\xa7\x0e\x12/\n(DevAla_id_Antenna_pitch_angle_soft_limit\x10\x82\x87\xa7\x0e\x42\x0cZ\n../protogob\x06proto3') DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\n\x17\x44\x65vice_datastruct.proto\x1a\x19google/protobuf/any.proto\x1a\x1fgoogle/protobuf/timestamp.proto\x1a\x0cTDSCmd.proto\"o\n\x12Proto3DeviceAllCMD\x12\n\n\x02ID\x18\x01 \x01(\x05\x12\x10\n\x08\x44\x45V_NAME\x18\x02 \x01(\t\x12\x15\n\rPROTOCOL_NAME\x18\x03 \x01(\t\x12$\n\x04\x43MDs\x18\x04 \x03(\x0b\x32\x16.Proto3DeviceCMDDefine\"~\n\x15Proto3DeviceCMDDefine\x12\x10\n\x08\x43MD_NAME\x18\x01 \x01(\t\x12\x0e\n\x06\x45NCODE\x18\x02 \x01(\t\x12\x1f\n\x17Timing_CMD_Cycle_period\x18\x03 \x01(\x05\x12\"\n\x06\x66\x65lids\x18\x04 \x03(\x0b\x32\x12.Proto3CMDFieldCfg\"\x9d\x01\n\x17Proto3ForReloadProtocol\x12\x10\n\x08\x64\x65v_name\x18\x01 \x01(\t\x12\x10\n\x08\x63md_name\x18\x02 \x01(\t\x12-\n\x05\x66lags\x18\x03 \x01(\x0e\x32\x1e.Proto3ForReloadProtocol.Flags\"/\n\x05\x46lags\x12\x13\n\x0fNORMAL_DISPATCH\x10\x00\x12\x11\n\rFULL_DISPATCH\x10\x01\"\xa8\x01\n\x19Proto3TableDevCmdNamePoll\x12\n\n\x02id\x18\x01 \x01(\x05\x12\x15\n\rprotocol_name\x18\x02 \x01(\t\x12\x10\n\x08\x63md_name\x18\x03 \x01(\t\x12\x10\n\x08\x63md_type\x18\x04 \x01(\t\x12\x0e\n\x06\x65ncode\x18\x05 \x01(\t\x12\x1f\n\x17timing_cmd_cycle_period\x18\x06 \x01(\x05\x12\x13\n\x0b\x63md_explain\x18\x07 \x01(\t\"\x85\x03\n\x1aProto3TableAllDevCmdDefine\x12\n\n\x02id\x18\x01 \x01(\x05\x12\x10\n\x08\x63md_name\x18\x02 \x01(\t\x12\x10\n\x08\x63md_type\x18\x03 \x01(\t\x12\x12\n\nfieldindex\x18\x04 \x01(\x05\x12\x11\n\tfieldname\x18\x05 \x01(\t\x12\x11\n\tfieldsize\x18\x06 \x01(\x05\x12\r\n\x05value\x18\x07 \x01(\t\x12\x10\n\x08minvalue\x18\x08 \x01(\t\x12\x10\n\x08maxvalue\x18\t \x01(\t\x12\x10\n\x08\x64\x61tatype\x18\n \x01(\x05\x12\x14\n\x0coperation_in\x18\x0b \x01(\x05\x12\x18\n\x10operation_in_num\x18\x0c \x01(\x05\x12\x15\n\roperation_out\x18\r \x01(\x05\x12\x19\n\x11operation_out_num\x18\x0e \x01(\x05\x12\x12\n\noperabo_in\x18\x0f \x01(\x05\x12\x13\n\x0boperabo_out\x18\x10 \x01(\x05\x12\x15\n\rlua_script_in\x18\x11 \x01(\t\x12\x16\n\x0elua_script_out\x18\x12 \x01(\t\"\xa2\x03\n\x13Proto3DeviceInfoCfg\x12\n\n\x02ID\x18\x01 \x01(\x05\x12\x0e\n\x06STA_ID\x18\x02 \x01(\t\x12\x0e\n\x06\x44\x45V_ID\x18\x03 \x01(\x05\x12\x10\n\x08\x44\x45V_NAME\x18\x04 \x01(\t\x12\x14\n\x0c\x44\x45V_NAME_CHN\x18\x05 \x01(\t\x12\x15\n\rPROTOCOL_NAME\x18\x06 \x01(\t\x12\x16\n\x0e\x43MD_EXCEL_PATH\x18\x07 \x01(\t\x12\x17\n\x0f\x43OMUNITATE_MODE\x18\x08 \x01(\t\x12\x0e\n\x06TCP_IP\x18\t \x01(\t\x12\x10\n\x08TCP_PORT\x18\n \x01(\x05\x12\x12\n\nUDP_IP_SRC\x18\x0b \x01(\t\x12\x14\n\x0cUDP_PORT_SRC\x18\x0c \x01(\x05\x12\x12\n\nUDP_IP_DST\x18\r \x01(\t\x12\x14\n\x0cUDP_PORT_DST\x18\x0e \x01(\x05\x12\x10\n\x08UDPMC_IP\x18\x0f \x01(\t\x12\x13\n\x0bUDPMC_IP_TX\x18\x10 \x01(\t\x12\x15\n\rUDPMC_PORT_TX\x18\x11 \x01(\x05\x12\x13\n\x0bUDPMC_IP_RX\x18\x12 \x01(\t\x12\x15\n\rUDPMC_PORT_RX\x18\x13 \x01(\x05\x12\x0f\n\x07REMARKS\x18\x14 \x01(\t\"\xed\x02\n\x11Proto3CMDFieldCfg\x12\n\n\x02ID\x18\x01 \x01(\x05\x12\x12\n\nfieldIndex\x18\x02 \x01(\x05\x12\x11\n\tfieldName\x18\x03 \x01(\t\x12\x11\n\tfieldSize\x18\x04 \x01(\x05\x12\r\n\x05value\x18\x05 \x01(\t\x12\x10\n\x08minValue\x18\x06 \x01(\t\x12\x10\n\x08maxValue\x18\x07 \x01(\t\x12\x10\n\x08\x64\x61taType\x18\x08 \x01(\x05\x12\x14\n\x0coperation_in\x18\t \x01(\x05\x12\x18\n\x10operation_in_num\x18\n \x01(\x05\x12\x15\n\roperation_out\x18\x0b \x01(\x05\x12\x19\n\x11operation_out_num\x18\x0c \x01(\x05\x12\x12\n\noperaBO_in\x18\r \x01(\x05\x12\x13\n\x0boperaBO_out\x18\x0e \x01(\x05\x12\x15\n\rLua_Script_in\x18\x0f \x01(\t\x12\x16\n\x0eLua_Script_out\x18\x10 \x01(\t\x12\x13\n\x0bvalue_bytes\x18\x13 \x01(\x0c\"\xaa\x01\n\x1cProto3TableSoftLimitAngleCfg\x12\n\n\x02ID\x18\x01 \x01(\x05\x12\x0e\n\x06STA_ID\x18\x02 \x01(\t\x12\x10\n\x08\x44\x45V_NAME\x18\x03 \x01(\t\x12\x14\n\x0c\x44\x45V_NAME_CHN\x18\x04 \x01(\t\x12\x15\n\rPROTOCOL_NAME\x18\x05 \x01(\t\x12\x1e\n\x16PITCH_SOFT_LIMIT_ANGLE\x18\x06 \x01(\t\x12\x0f\n\x07REMARKS\x18\x07 \x01(\t\"\xd9\x02\n\x0bTDSDBC_CURD\x12\r\n\x05table\x18\x01 \x01(\t\x12!\n\x05\x66lags\x18\x02 \x01(\x0e\x32\x12.TDSDBC_CURD.Flags\x12)\n\toperation\x18\x03 \x01(\x0e\x32\x16.TDSDBC_CURD.Operation\x12\x18\n\x04\x63ode\x18\x04 \x01(\x0e\x32\n.CodeValue\x12\x0b\n\x03msg\x18\x05 \x01(\t\x12\x0f\n\x07msg_CHN\x18\x06 \x01(\t\x12&\n\x08\x61ny_data\x18\x07 \x03(\x0b\x32\x14.google.protobuf.Any\"/\n\x05\x46lags\x12\x13\n\x0fNORMAL_DISPATCH\x10\x00\x12\x11\n\rFULL_DISPATCH\x10\x01\"\\\n\tOperation\x12\x11\n\rOPERATION_ADD\x10\x00\x12\x11\n\rOPERATION_DEL\x10\x01\x12\x14\n\x10OPERATION_UPDATE\x10\x02\x12\x13\n\x0fOPERATION_QUERY\x10\x03\"\xbc\x01\n\x11TDSXDC_Device_cmd\x12\x10\n\x08\x44\x65viceID\x18\x01 \x01(\r\x12\x10\n\x08\x64\x65v_name\x18\x02 \x01(\t\x12\x10\n\x08\x63md_name\x18\x03 \x01(\t\x12\x15\n\rprotocol_name\x18\x04 \x01(\t\x12\x18\n\x04\x63ode\x18\x05 \x01(\x0e\x32\n.CodeValue\x12\x0b\n\x03msg\x18\x06 \x01(\t\x12\x0f\n\x07msg_CHN\x18\x07 \x01(\t\x12\"\n\x06\x66ields\x18\x08 \x03(\x0b\x32\x12.Proto3CMDFieldCfg*\x7f\n\x0e\x41larmID_define\x12\x0b\n\x07ID_Base\x10\x00\x12\x15\n\x0e\x44\x65vAla_id_Base\x10\x80\x87\xa7\x0e\x12\x18\n\x11\x44\x65vAla_id_Offline\x10\x81\x87\xa7\x0e\x12/\n(DevAla_id_Antenna_pitch_angle_soft_limit\x10\x82\x87\xa7\x0e\x42\x0cZ\n../protogob\x06proto3')
......
...@@ -20,7 +20,9 @@ def send_websocket_message(message, group_name="chat_mqtt"): ...@@ -20,7 +20,9 @@ def send_websocket_message(message, group_name="chat_mqtt"):
def on_connect(mqtt_client, userdata, flags, rc): def on_connect(mqtt_client, userdata, flags, rc):
if rc == 0: if rc == 0:
print('Connected successfully') print('Connected successfully')
mqtt_client.subscribe('django/mqtt') mqtt_client.subscribe([('/1/0/0/6', 2),
('/1/1/0/6', 2),
('/1/1/1/6', 2)])
else: else:
print('Bad connection. Code:', rc) print('Bad connection. Code:', rc)
...@@ -29,9 +31,10 @@ def on_message(mqtt_client, userdata, msg): ...@@ -29,9 +31,10 @@ def on_message(mqtt_client, userdata, msg):
# 接收mqtt消息的代码 # 接收mqtt消息的代码
# mqtt_message_received.send(sender=None, message=msg.payload) # mqtt_message_received.send(sender=None, message=msg.payload)
# print(f'Received message on topic: {msg.topic} with payload: {msg.payload}') # print(f'Received message on topic: {msg.topic} with payload: {msg.payload}')
# data = parse_proto(msg.payload) data = parse_proto(msg.payload)
data = msg.payload.decode('utf-8') # data = msg.payload.decode('utf-8')
send_websocket_message(data) print(f'Received message on topic: {msg.topic} with payload: {data}')
# send_websocket_message(data)
client = mqtt.Client() client = mqtt.Client()
......
import json import json
from .auto_generate_python import TDSCmd_pb2, OAM_datastruct_pb2 from .auto_generate_python import TDSCmd_pb2, OAM_datastruct_pb2, Device_datastruct_pb2
from google.protobuf.json_format import MessageToJson from google.protobuf.json_format import MessageToJson
......
...@@ -144,12 +144,14 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' ...@@ -144,12 +144,14 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
ASGI_APPLICATION = 'vue_django.asgi.application' ASGI_APPLICATION = 'vue_django.asgi.application'
MQTT_SERVER = '192.168.0.89' # mqtt 设置
MQTT_SERVER = '192.168.0.176'
MQTT_PORT = 1883 MQTT_PORT = 1883
MQTT_KEEPALIVE = 60 MQTT_KEEPALIVE = 60
MQTT_USER = "" MQTT_USER = ""
MQTT_PASSWORD = "" MQTT_PASSWORD = ""
# channel 的 websocket 设置
CHANNEL_LAYERS = { CHANNEL_LAYERS = {
'default': { 'default': {
'BACKEND': 'channels.layers.InMemoryChannelLayer', 'BACKEND': 'channels.layers.InMemoryChannelLayer',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment