diff --git a/logDataClean.awk b/logDataClean.awk index 92ea0ce..9f8fc8e 100644 --- a/logDataClean.awk +++ b/logDataClean.awk @@ -7,15 +7,15 @@ ############################# BEGIN{ - + filePath=/data/log/myJsonLog # system("echo '\n\n\n----------' >> "awk_run_log_path" && date '+%x %X' >> "awk_run_log_path) - dp_recv_from_device = @/ dp rept_type:[[:digit:]]+, data:{/ - dp_is_condition = @/dp [[:digit:]]+ match/ - dp_not_condition = @/no [[:digit:]]+ match/ - pattern = @/([[:digit:]]+-[[:digit:]]+ ([[:digit:]]+:){3}[[:digit:]]+)/ + dp_recv_from_device = @/ dp rept_type:[0-9]+, data:{/ + dp_is_condition = @/dp [0-9]+ match/ + dp_not_condition = @/no [0-9]+ match/ + pattern = @/([0-9]+-[0-9]+ ([0-9]+:){3}[0-9]+)/ - connection_check_ok = @ + connection_check_ok = @/condition set is ok,then execute action set./ # Get form OS } @@ -23,11 +23,7 @@ BEGIN{ } $0~dp_recv_from_device{ - matchRet(/([0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3})/); - substr($0,RSTART,RLENGTH) - match($0,"^\\[([[:digit:]]+-[[:digit:]]+ ([[:digit:]]+:){3}[[:digit:]]+).*? dp .*?, data:(.*)$",d) - print d[1],d[3] - echo '[12-09 19:03:03:863 TUYA Debug][smart_frame.c:2110] dp rept_type:0, data:{"1":true}' + matchRet(/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/); } $0~dp_is_condition{ @@ -41,6 +37,18 @@ END{ } function matchRet(reg ,RSTART,RLENGTH){ - match($0,reg); - return substr($0,RSTART,RLENGTH) + if(match($0,$reg)){ return substr($0,RSTART,RLENGTH) }else{ return "Nothing Matched" } +} + +function maker_Json(){ + return { + "time":matchRet(/[0-9]{1,2}-[0-9]{1,2} ([0-9]{1,2}:){3}[0-9]{1,3}/), + "event":matchRet(), + "value":matchRet(), + "dps":matchRet(/\{.+\}/) + } +} + +function write2file(){ + echo $1 >> $filePath } \ No newline at end of file diff --git a/start_monitor.sh b/start_monitor.sh index 10aab70..3adeeb3 100644 --- a/start_monitor.sh +++ b/start_monitor.sh @@ -1,10 +1,10 @@ # 创建场景 -tail -f /tmp/tuya.log | grep '\] Rev MQTT:' | grep '"ruleId":' >> /data/SceneLinkage & +tail -f /tmp/tuya.log | grep '\] Rev MQTT:' | grep '"ruleId":' | awk -f ./logDataClean.awk >> /data/SceneLinkage & # 触发场景 -tail -f /tmp/tuya.log | grep 'condition set is ok,then execute action set. scene:' >> +tail -f /tmp/tuya.log | grep 'condition set is ok,then execute action set. scene:' |awk -f >> # 子设备上报 # 是否有相关场景( dp \d+ match | no dp match) diff --git a/必要日志.log b/必要日志.log index e9e89bd..606a241 100644 --- a/必要日志.log +++ b/必要日志.log @@ -1,3 +1,14 @@ +[01-24 14:59:09:450 TUYA D][callback-stub.c:2545] ************ EuiStr:5c0272fffe1f8b9d cmd recv, data rept nodeId = 0x5ad.*************** + +[01-24 15:05:49:95 TUYA D][smart_frame.c:2149] dp rept_type:0, data:{"1":true} +[01-24 15:05:49:95 TUYA D][mqc_app.c:875] Send MQTT Msg.P:4 N:28755 Q:1 Data:{"dps":{"1":true},"cid":"5c0272fffe1f8b9d"} +[01-24 15:05:49:96 TUYA D][scene_linkage_dp_detect.c:377] rev id:5c0272fffe1f8b9d cmd:{"1":true} type:0 +[01-24 15:05:49:97 TUYA D][scene_linkage_dp_detect.c:393] no id match +[01-24 15:05:49:97 TUYA D][scene_linkage_dp_detect.c:377] rev id:5c0272fffe1f8b9d cmd:{"1":true} type:1 +[01-24 15:05:49:97 TUYA D][scene_linkage_dp_detect.c:393] no id match + + + [12-09 19:03:03:863 TUYA Debug][smart_frame.c:2110] dp rept_type:0, data:{"1":true} [12-09 19:03:03:884 TUYA Debug][mqc_app.c:862] Send MQTT Msg.P:4 N:54368 Q:1 Data:{"dps":{"1":true},"cid":"000d6ffffe972ab8"}