忽略卫岗照明设备产生的数据,不推送给中电

This commit is contained in:
anlicheng 2024-09-26 16:57:19 +08:00
parent 1a14330913
commit e69a49a866
4 changed files with 4599 additions and 1 deletions

File diff suppressed because it is too large Load Diff

View File

@ -18,6 +18,8 @@ start(_StartType, _StartArgs) ->
%%
ok = iot_env:new(),
ok = iot_ignore_devices:new(),
%%
% start_mnesia(),

View File

@ -591,7 +591,7 @@ handle_data(#{<<"device_uuid">> := DeviceUUID, <<"service_name">> := ServiceName
case iot_device:is_activated(DevicePid) of
true ->
%%
iot_router:route_uuid(DeviceUUID, FieldsList, Timestamp),
(not iot_ignore_devices:exists(DeviceUUID)) andalso iot_router:route_uuid(DeviceUUID, FieldsList, Timestamp),
%% influxdb
NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName, <<"device_uuid">> => DeviceUUID},

View File

@ -0,0 +1,59 @@
%%%-------------------------------------------------------------------
%%% @author anlicheng
%%% @copyright (C) 2024, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 30. 8 2024 10:44
%%%-------------------------------------------------------------------
-module(iot_ignore_devices).
-author("anlicheng").
-define(TAB, iot_device).
%%
-record(device, {
uuid
}).
%% API
-export([new/0, reload/0, exists/1]).
-spec new() -> ok.
new() ->
ets:new(?TAB, [public, set, named_table, {read_concurrency, true}, {keypos, 2}]),
DeviceIds = load_file(),
lager:debug("[iot_ignore_devices] load ids: ~p", [DeviceIds]),
[ets:insert(?TAB, #device{uuid = Id}) || Id <- DeviceIds],
ok.
-spec reload() -> ok.
reload() ->
ets:delete_all_objects(?TAB),
DeviceIds = load_file(),
lager:debug("[iot_ignore_devices] load ids: ~p", [DeviceIds]),
[ets:insert(?TAB, #device{uuid = Id}) || Id <- DeviceIds],
ok.
-spec exists(Key :: binary()) -> boolean().
exists(Key) when is_binary(Key) ->
case ets:lookup(?TAB, Key) of
[] ->
false;
[#device{uuid = Key}|_] ->
true
end.
-spec load_file() -> list().
load_file() ->
Dir = code:priv_dir(iot),
EnvFile = Dir ++ "/weigang_light.txt",
case file:read_file(EnvFile) of
{ok, Content} ->
Lines0 = binary:split(Content, <<$\n>>, [global, trim]),
Lines1 = lists:map(fun(L) -> string:trim(L) end, Lines0),
lists:filter(fun(L) -> string:trim(L) =/= <<"">> end, Lines1);
{error, Reason} ->
lager:warning("[iot] read .env file: ~p, get error: ~p", [EnvFile, Reason]),
[]
end.