2024-10-18T13:01:07.062124+08:00 [error] at_state: <<“clean”>>, clientid: X6A11Y0000001984, input_bytes: <<“\bupload_1{"messageType":"0","deviceId":"X6A11Y0000001984","data":{"pm2d5":"9.53","pm10":"13.00","temperature":"30.6","humidity":"38.1","co2":"1855","tvoc":"1436","interval":"12","timeStamp":"1729227652"}}\r\n”>>, line: 772, mfa: emqx_connection:parse_incoming/2, parsed_packets: [{mqtt_packet,{mqtt_packet_header,0,false,0,true},undefined,undefined},{mqtt_packet,{mqtt_packet_header,12,false,0,false},undefined,undefined}], peername: 218.204.252.46:12390, reason: function_clause, stacktrace: [{emqx_frame,parse_packet,[{mqtt_packet_header,0,true,0,false},<<“pload_1{"messageType":"0","deviceId":"X6A11Y0000001984","data":{"pm2d5":"9.53","pm10":"13.00","temperature":"30.6","h”>>,#{max_size => 1048576,strict_mode => false,version => 4}],[{file,“emqx_frame.erl”},{line,258}]},{emqx_frame,parse_frame,4,[{file,“emqx_frame.erl”},{line,231}]},{emqx_connection,parse_incoming,3,[{file,“emqx_connection.erl”},{line,750}]},{emqx_connection,handle_msg,2,[{file,“emqx_connection.erl”},{line,729}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,466}]},{emqx_connection,handle_recv,3,[{file,“emqx_connection.erl”},{line,428}]},{proc_lib,wake_up,3,[{file,“proc_lib.erl”},{line,236}]}]
2024-10-18T13:01:07.062766+08:00 [error] clientid: X6A11Y0000001984, line: 601, mfa: emqx_channel:handle_in/2, msg: disconnecting_due_to_unexpected_message, packet: {mqtt_packet,{mqtt_packet_header,0,false,0,true},undefined,undefined}, peername: 218.204.252.46:12390
2024-10-18T13:01:07.063260+08:00 [error] clientid: X6A11Y0000001984, line: 1275, mfa: emqx_channel:handle_info/2, msg: unexpected_sock_close, peername: 218.204.252.46:12390, reason: function_clause
function_clause {emqx_frame,parse_frame} 是因为 MQTT 端口( 1883 或者 8883)收到了错误格式的 MQTT报文,看起来是个明文的 JSON 文本发过来了。
下面两个日志是客户端被断开了,因为这个报文解析失败。
这个json明文就是我们的协议内容,看着格式也没问题
应该是 通过你使用的 mqtt sdk 把 json 放在了你的 mqtt 协议 的 payload 里面,
但是你的mqtt 协议组包错了。
日志里面显示你的mqtt 都没有组,直接发了个 encode 的json过来,正常得用 mqtt 的 publish组包。