From 32a742f10d3e2e030cb256e2038ba16fc152026b Mon Sep 17 00:00:00 2001 From: dawnwinterLiu <1737801684@qq.com> Date: Thu, 21 Mar 2024 14:23:33 +0800 Subject: [PATCH] ping_all --- .gitignore | 1 + apps/dgiot/src/utils/dgiot_utils.erl | 23 ++++++++------ apps/dgiot_http/src/umeng/dgiot_umeng.erl | 37 +++++++++++++++++++++++ 3 files changed, 52 insertions(+), 9 deletions(-) diff --git a/.gitignore b/.gitignore index 45448482..6161f535 100644 --- a/.gitignore +++ b/.gitignore @@ -98,6 +98,7 @@ apps/dgiot_demo/ apps/dgiot_jingmao/ apps/dgiot_atom/ apps/dgiot_12184/ +apps/dgiot_rtsp2ws/ node_modules/ package-lock.json erlang_ls.config diff --git a/apps/dgiot/src/utils/dgiot_utils.erl b/apps/dgiot/src/utils/dgiot_utils.erl index 91cb5de1..a447f412 100644 --- a/apps/dgiot/src/utils/dgiot_utils.erl +++ b/apps/dgiot/src/utils/dgiot_utils.erl @@ -997,15 +997,20 @@ get_port(Socket) -> %%[global, {capture, all_but_first, binary}]) ping_all() -> - lists:map(fun({A, B, C, _D}) -> - Cmd = "for /l %i in (1,1,255) do ping -n 1 -w 50 " - ++ to_list(A) ++ "." - ++ to_list(B) ++ "." - ++ to_list(C) ++ "." - ++ "%i", - os:cmd(Cmd) - end, - get_ifaddrs()). + lists:map( + fun({A, B, C, _D}) -> + lists:map( + fun(N) -> + Cmd = + case os:type() of + {unix, linux} -> + "ping -c 1 -w 50 " ++ to_list(A) ++ "." ++ to_list(B) ++ "." ++ to_list(C) ++ "." ++ dgiot_utils:to_list(N); + _ -> + "ping -n 1 -w 50 " ++ to_list(A) ++ "." ++ to_list(B) ++ "." ++ to_list(C) ++ "." ++ dgiot_utils:to_list(N) + end, + os:cmd(Cmd) + end, lists:seq(1, 255)) + end, get_ifaddrs()). get_ifaddrs() -> case inet:getifaddrs() of diff --git a/apps/dgiot_http/src/umeng/dgiot_umeng.erl b/apps/dgiot_http/src/umeng/dgiot_umeng.erl index 9393db3e..138c3fdd 100644 --- a/apps/dgiot_http/src/umeng/dgiot_umeng.erl +++ b/apps/dgiot_http/src/umeng/dgiot_umeng.erl @@ -40,6 +40,7 @@ triggeralarm/2, send_msg/1, sendSubscribe/1, + send_dashboard/1, get_defultmessage/1, replace_miniparam/10 ]). @@ -203,6 +204,7 @@ add_notification(<<"start_", Ruleid/binary>>, DeviceId, Payload) -> NotificationId = dgiot_parse_id:get_notificationid(Ruleid), dgiot_data:insert(?NOTIFICATION, {DeviceId, Ruleid}, {start, dgiot_datetime:now_secs(), NotificationId}), Content = save_notification(Ruleid, DeviceId, Payload, NotificationId), + dgiot_umeng:send_dashboard(Content), dgiot_umeng:send_other(Content), dgiot_umeng:send_maintenance(Content#{<<"notificationid">> => NotificationId}), dgiot_umeng:send_msg(Content), @@ -625,6 +627,41 @@ sendSubscribe(_O) -> %% io:format("~s ~p _O = ~p.~n", [?FILE, ?LINE, _O]), pass. +%% 推送前端弹框 +send_dashboard(#{<<"_deviceid">> := DeviceId, <<"dgiot_alarmvalue">> := Alarmvalue} = Args) -> + case dgiot_parse:get_object(<<"Device">>, DeviceId) of + {ok, #{<<"name">> := DeviceName, <<"product">> := #{<<"objectId">> := ProductId}}} -> + ProductName = + case dgiot_parse:get_object(<<"Product">>, ProductId) of + {ok, #{<<"name">> := Name1}} -> + Name1; + _ -> + <<>> + end, + <> = dgiot_utils:random(), + Timestamp = dgiot_datetime:format(dgiot_datetime:to_localtime(dgiot_datetime:now_secs()), <<"YY-MM-DD HH:NN:SS">>), +%% BinAlarmvalue = dgiot_utils:to_binary(Alarmvalue), + Data = #{ + <<"id">> => Number, + <<"deviceid">> => DeviceId, + <<"devicename">> => DeviceName, + <<"productid">> => ProductId, + <<"productname">> => ProductName, + <<"value">> => Alarmvalue, + <<"time">> => Timestamp, + <<"level">> => 1, + <<"type">> => <<"warn">>, + <<"description">> => maps:get(<<"description">>, Args, <<>>) + }, + Pubtopic = <<"$dg/user/dashboard/notification/report">>, + dgiot_mqtt:publish(DeviceId, Pubtopic, dgiot_json:encode(Data)); + _ -> + pass + end; + +send_dashboard(_O) -> + pass. + %% 推送第三方 send_other(#{<<"send_alarm_status">> := <<"start">>, <<"_deviceid">> := DeviceId, <<"_viewid">> := ViewId, <<"dgiot_alarmvalue">> := Alarmvalue}) -> case dgiot_parse:get_object(<<"View">>, ViewId) of