忽略卫岗照明设备产生的数据,不推送给中电
This commit is contained in:
parent
1a14330913
commit
e69a49a866
4537
apps/iot/priv/weigang_light.txt
Normal file
4537
apps/iot/priv/weigang_light.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -18,6 +18,8 @@ start(_StartType, _StartArgs) ->
|
|||||||
%% 加载环境变量
|
%% 加载环境变量
|
||||||
ok = iot_env:new(),
|
ok = iot_env:new(),
|
||||||
|
|
||||||
|
ok = iot_ignore_devices:new(),
|
||||||
|
|
||||||
%% 启动数据库
|
%% 启动数据库
|
||||||
% start_mnesia(),
|
% start_mnesia(),
|
||||||
|
|
||||||
|
|||||||
@ -591,7 +591,7 @@ handle_data(#{<<"device_uuid">> := DeviceUUID, <<"service_name">> := ServiceName
|
|||||||
case iot_device:is_activated(DevicePid) of
|
case iot_device:is_activated(DevicePid) of
|
||||||
true ->
|
true ->
|
||||||
%% 查找终端设备对应的点位信息
|
%% 查找终端设备对应的点位信息
|
||||||
iot_router:route_uuid(DeviceUUID, FieldsList, Timestamp),
|
(not iot_ignore_devices:exists(DeviceUUID)) andalso iot_router:route_uuid(DeviceUUID, FieldsList, Timestamp),
|
||||||
|
|
||||||
%% 数据写入influxdb
|
%% 数据写入influxdb
|
||||||
NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName, <<"device_uuid">> => DeviceUUID},
|
NTags = Tags#{<<"uuid">> => UUID, <<"service_name">> => ServiceName, <<"device_uuid">> => DeviceUUID},
|
||||||
|
|||||||
59
apps/iot/src/iot_ignore_devices.erl
Normal file
59
apps/iot/src/iot_ignore_devices.erl
Normal 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.
|
||||||
Loading…
x
Reference in New Issue
Block a user