simple iot_device
This commit is contained in:
parent
361a3bed9f
commit
3050841280
@ -14,7 +14,7 @@
|
|||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([get_name/1, get_pid/1, serialize/1]).
|
-export([get_name/1, get_pid/1]).
|
||||||
-export([start_link/2, is_activated/1, is_alive/1, change_status/2, reload/1, auth/2]).
|
-export([start_link/2, is_activated/1, is_alive/1, change_status/2, reload/1, auth/2]).
|
||||||
-export([ai_event/3, handle_data/3]).
|
-export([ai_event/3, handle_data/3]).
|
||||||
|
|
||||||
@ -50,28 +50,6 @@
|
|||||||
%%% API
|
%%% API
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
%% 格式化efka上传的数据格式
|
|
||||||
%"fields": [
|
|
||||||
%{
|
|
||||||
% "key": "test"
|
|
||||||
% "value": 124,
|
|
||||||
% "unit": "U",
|
|
||||||
% "type": "AI:遥测值,DI:遥信值,SOE:事件",
|
|
||||||
% "timestamp": int
|
|
||||||
%}
|
|
||||||
%],
|
|
||||||
%% 用来保存在内存中的格式,不需要序列话处理 !!!, 放入到influxdb的数据是基于base64的
|
|
||||||
-spec serialize(FieldsList :: [map()]) -> [{Key :: binary(), Values :: map()}].
|
|
||||||
serialize(FieldsList) when is_list(FieldsList) ->
|
|
||||||
lists:flatmap(fun serialize0/1, FieldsList).
|
|
||||||
serialize0(Fields = #{<<"key">> := Key}) when is_binary(Key) andalso Key /= <<>> ->
|
|
||||||
Values = maps:remove(<<"key">>, Fields),
|
|
||||||
%S = base64:encode(iolist_to_binary(jiffy:encode(#{Key => Values}, [force_utf8]))),
|
|
||||||
%[<<"base64:", S/binary>>];
|
|
||||||
[{Key, Values}];
|
|
||||||
serialize0(_) ->
|
|
||||||
[].
|
|
||||||
|
|
||||||
-spec is_alive(DeviceUUID :: binary()) -> error | {ok, Pid :: pid()}.
|
-spec is_alive(DeviceUUID :: binary()) -> error | {ok, Pid :: pid()}.
|
||||||
is_alive(DeviceUUID) when is_binary(DeviceUUID) ->
|
is_alive(DeviceUUID) when is_binary(DeviceUUID) ->
|
||||||
case iot_device:get_pid(DeviceUUID) of
|
case iot_device:get_pid(DeviceUUID) of
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user