Commit 053d9b7c by qianmo

Merge remote-tracking branch 'origin/main'

parents 136548f2 18636750
# chat/consumers.py
import urllib.parse
import json
from asgiref.sync import async_to_sync
......@@ -74,8 +75,9 @@ class ChatConsumer(AsyncWebsocketConsumer):
# Receive message from room group
async def chat_message(self, event):
message = dict(event["message"])
# print(event['message'])
message = event["message"]
# print(message)
# Send message to WebSocket
await self.send(text_data=json.dumps({"message": [message]}))
# await self.send(bytes_data=message)
......
......@@ -24,6 +24,7 @@ type propsType = {
devName: string
groupName: string
protocolName: string
type: string
}
const props = defineProps<propsType>()
......@@ -42,19 +43,13 @@ onMounted(() => {
// console.log(e.data);
let data = JSON.parse(e.data).message
for (const [key, value] of Object.entries(data[0] as Record<string, string>)) {
console.log(key, value);
if (tableTitles.value.indexOf(key) !== -1) {
tableData.value[0][key] = value
}
}
}
table_websocket.onclose = (e) => {
console.error('Table socket closed unexpectedly', e);
}
axios.get('/api/device_communication/performance/1/' + props.protocolName)
axios.get('/api/device_communication/performance/' + props.type + '/' + props.protocolName)
.then((res) => {
tableTitles.value = res.data
for (let key of res.data) {
......
......@@ -23,6 +23,8 @@ def on_message(mqtt_client, userdata, msg):
data, device_name = parse_proto(msg.payload)
# data = msg.payload.decode('utf-8')
print(f'Received message on topic: {msg.topic} with payload: {data}')
if len(data) == 0:
return
send_message(data, device_name)
......@@ -38,6 +40,8 @@ def send_message(data: dict, device_name: str):
name = dev_info.tcp_port
elif "UDP" in dev_info.comunitate_mode.upper():
name = dev_info.udp_port_src
else:
return
send_websocket_message(data, group_name=f'chat_{name}')
# cmds = data.get('CMDS')
......
......@@ -32,7 +32,7 @@ def cmd_fields_list(request, cmd_name: str):
cmd_fields = TableAllDevCmdDefine.objects.filter(cmd_name=cmd_name).all()
serializer = TableAllDevCmdDefineSerializer(cmd_fields, many=True)
ret_data = [data['fieldname'] for data in serializer.data]
ret_data = [{'fieldname': data['fieldname'], 'value': data['value']} for data in serializer.data]
return Response(data=ret_data, status=status.HTTP_200_OK)
......@@ -43,7 +43,6 @@ def publish_message(request):
:param request:
{
"type": "device",
"station_id": "XX1",
"device_id": 1,
"cmd_name": "HY_ACU7M5_PositionSet",
......@@ -63,6 +62,9 @@ def publish_message(request):
if request.data['station_id'] == "XX1":
topic = "/1/1/1/3"
dst_suid = 0x1113_0000
elif request.data['station_id'] == "XX2":
topic = "/1/1/2/3"
dst_suid = 0x1103_0000
elif request.data['station_id'] == "XX0":
topic = "/1/1/0/3"
dst_suid = 0x1103_0000
......
......@@ -37,7 +37,7 @@ urlpatterns = [
path("", index),
path("test/upload/", upload),
path("test/download/", download),
path("mqtt/", include("mqtt.urls")),
path("api/mqtt/", include("mqtt.urls")),
path("chat/", include("chat.urls")),
path("api/", include("device_data_op.urls")),
path("api/", include("download_db.urls")),
......
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