规则异常解析

1,规则书写


2,自己对规则进行测试,并且测试通过

3,但是在接收到点位上传信息后,又无法通过

4,日志信息如下

以下是各个部分的原文,方便测试:
1,规则
FOREACH
payload.values as t
DO
concat(replace(replace(replace( t.id,‘.’,‘‘),’ ‘,’’),‘-’,‘_’),‘_nlf’) as name,
float(substr(str(t.v),0,15)) as t.v,
t.t,
t.q,
t.id
FROM “D1_TAOS_TXGLJ/#”

2,样例数据:
{“timestamp”:1719045664263,“values”:[
{“id”:“D1.OPC.A1_B1_NY_PDSTXGLJ2.B1_PDSTXGLJ2.2_1A01_P_PJ”,“v”:5920167.96875,“q”:true,“t”:1719045575989},
{“id”:“D1.OPC.A1_B1_NY_PDSTXGLJ2.B1_PDSTXGLJ2.2_1A03_P_PJ”,“v”:8508.800048828125,“q”:true,“t”:1719038779055},
{“id”:“D1.OPC.A1_B1_NY_PDSTXGLJ2.B1_PDSTXGLJ2.2_1A02_P_PJ”,“v”:32935.198974609375,“q”:true,“t”:1719045042450}]}

3,日志信息:
D1_TAOS_TXGLJ, msg: FOREACH_clause_exception, peername: 172.17.0.1:51624, reason:
{error,{decode_json_failed,<<“{"timestamp":1719045664263,"values":[
{"id":"D1.OPC.A1_B1_NY_PDSTXGLJ2.B1_PDSTXGLJ2.2_1A01_P_PJ","v":5920167.96875,"q":true,"t":1719045575989},
{"id":"D1.OPC.A1_B1_NY_PDSTXGLJ2.B1_PDSTXGLJ2.2_1A03_P_PJ","v":8508.800048828125,"q":true,"t":1719038779055},
{"id":"D1.OPC.A1_B1_NY_PDSTXGLJ2.B1_PDSTXGLJ2.2_1A02_P_PJ","v":32935.198974609375,"q":true,"t":1719045042450},
{"id":"D1.OPC.A1_B1”…>>},[{emqx_rule_runtime,safe_decode_and_cache,1,[{file,“emqx_rule_runtime.erl”},{line,566}]},
{emqx_rule_runtime,eval,2,[{file,“emqx_rule_runtime.erl”},{line,409}]},
{emqx_rule_runtime,select_and_collect,3,[{file,“emqx_rule_runtime.erl”},
{line,219}]},{emqx_rule_runtime,‘-do_apply_rule/3-fun-0-’,2,[{file,“emqx_rule_runtime.erl”},{line,133}]},{emqx_rule_runtime,do_apply_rule,3,[{file,“emqx_rule_runtime.erl”},{line,132}]},{emqx_rule_runtime,apply_rule,3,[{file,“emqx_rule_runtime.erl”},{line,72}]},{emqx_rule_runtime,apply_rule_discard_result,3,[{file,“emqx_rule_runtime.erl”},{line,65}]},{emqx_rule_runtime,apply_rules,3,[{file,“emqx_rule_runtime.erl”},{line,61}]},{emqx_rule_events,on_message_publish,2,[{file,“emqx_rule_events.erl”},{line,142}]},{emqx_hooks,safe_execute,2,[{file,“emqx_hooks.erl”},{line,205}]},{emqx_hooks,do_run_fold,3,[{file,“emqx_hooks.erl”},{line,185}]},{emqx_broker,publish,1,[{file,“emqx_broker.erl”},{line,234}]},{emqx_channel,do_publish,3,[{file,“emqx_channel.erl”},{line,708}]},{emqx_connection,with_channel,3,[{file,“emqx_connection.erl”},{line,846}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,495}]},{emqx_connection,process_msg,2,[{file,“emqx_connection.erl”},{line,501}]},{emqx_connection,handle_recv,3,[{file,“emqx_connection.erl”},{line,457}]},{proc_lib,wake_up,3,[{file,“proc_lib.erl”},{line,250}]}]}, rule_id: <<“D1_TAOS_TXGLJ”>>

望各位大佬给予支持(跪求)

你好,看emqx 的日志提示是说 JSON Decode 失败了。方便检查下么?

或者把消息原文发来这里我试试

1 个赞

这部分就是消息原文(由于有重复发送检测)
{“timestamp”:1719045664263,“values”:[
{“id”:“D1.OPC.A1_B1_NY_PDSTXGLJ2.B1_PDSTXGLJ2.2_1A01_P_PJ”,“v”:5920167.96875,“q”:true,“t”:1719045575989},
{“id”:“D1.OPC.A1_B1_NY_PDSTXGLJ2.B1_PDSTXGLJ2.2_1A03_P_PJ”,“v”:8508.800048828125,“q”:true,“t”:1719038779055},
{“id”:“D1.OPC.A1_B1_NY_PDSTXGLJ2.B1_PDSTXGLJ2.2_1A02_P_PJ”,“v”:32935.198974609375,“q”:true,“t”:1719045042450}]}

我用另外一台客户机对数据进行了测试,发现测试时没有问题。但直接接收keepserver传输上来的数据均无法通过EMQX的规则,还望大佬能给我再检查检查


最新的规则是这样

你需要的是这个:

直接自己在规则里面调用 json_decode