fix
This commit is contained in:
parent
4a294ec8ee
commit
f2dcd2efa7
@ -51,7 +51,6 @@ change_status(Device = #device{status = Status}, NewStatus) when is_integer(NewS
|
|||||||
Device;
|
Device;
|
||||||
change_status(Device = #device{device_uuid = DeviceUUID}, ?DEVICE_ONLINE) ->
|
change_status(Device = #device{device_uuid = DeviceUUID}, ?DEVICE_ONLINE) ->
|
||||||
iot_api:change_device_status(DeviceUUID, ?DEVICE_ONLINE),
|
iot_api:change_device_status(DeviceUUID, ?DEVICE_ONLINE),
|
||||||
report_event(DeviceUUID, ?DEVICE_ONLINE),
|
|
||||||
Device#device{status = ?DEVICE_ONLINE};
|
Device#device{status = ?DEVICE_ONLINE};
|
||||||
change_status(Device = #device{device_uuid = DeviceUUID}, ?DEVICE_OFFLINE) ->
|
change_status(Device = #device{device_uuid = DeviceUUID}, ?DEVICE_OFFLINE) ->
|
||||||
{ok, #{<<"status">> := Status}} = iot_api:get_device_by_uuid(DeviceUUID),
|
{ok, #{<<"status">> := Status}} = iot_api:get_device_by_uuid(DeviceUUID),
|
||||||
@ -64,7 +63,6 @@ change_status(Device = #device{device_uuid = DeviceUUID}, ?DEVICE_OFFLINE) ->
|
|||||||
Device#device{status = ?DEVICE_OFFLINE};
|
Device#device{status = ?DEVICE_OFFLINE};
|
||||||
?DEVICE_ONLINE ->
|
?DEVICE_ONLINE ->
|
||||||
iot_api:change_device_status(DeviceUUID, ?DEVICE_OFFLINE),
|
iot_api:change_device_status(DeviceUUID, ?DEVICE_OFFLINE),
|
||||||
report_event(DeviceUUID, ?DEVICE_OFFLINE),
|
|
||||||
Device#device{status = ?DEVICE_OFFLINE}
|
Device#device{status = ?DEVICE_OFFLINE}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -103,23 +101,4 @@ auth(Device = #device{auth_state = StateName, device_uuid = DeviceUUID}, Auth) w
|
|||||||
auth_state(?DEVICE_AUTH_AUTHED) ->
|
auth_state(?DEVICE_AUTH_AUTHED) ->
|
||||||
?STATE_ACTIVATED;
|
?STATE_ACTIVATED;
|
||||||
auth_state(?DEVICE_AUTH_DENIED) ->
|
auth_state(?DEVICE_AUTH_DENIED) ->
|
||||||
?STATE_DENIED.
|
?STATE_DENIED.
|
||||||
|
|
||||||
-spec report_event(DeviceUUID :: binary(), NewStatus :: integer()) -> no_return().
|
|
||||||
report_event(DeviceUUID, NewStatus) when is_binary(DeviceUUID), is_integer(NewStatus) ->
|
|
||||||
TextMap = #{
|
|
||||||
0 => <<"离线"/utf8>>,
|
|
||||||
1 => <<"在线"/utf8>>
|
|
||||||
},
|
|
||||||
%% 设备的状态信息上报给中电
|
|
||||||
Timestamp = iot_util:timestamp_of_seconds(),
|
|
||||||
FieldsList = [#{
|
|
||||||
<<"key">> => <<"device_status">>,
|
|
||||||
<<"value">> => NewStatus,
|
|
||||||
<<"value_text">> => maps:get(NewStatus, TextMap),
|
|
||||||
<<"unit">> => 0,
|
|
||||||
<<"type">> => <<"DI">>,
|
|
||||||
<<"name">> => <<"设备状态"/utf8>>,
|
|
||||||
<<"timestamp">> => Timestamp
|
|
||||||
}],
|
|
||||||
lager:debug("[iot_device] device_uuid: ~p, route fields: ~p", [DeviceUUID, FieldsList]).
|
|
||||||
@ -351,7 +351,9 @@ handle_event({call, From}, {activate_device, DeviceUUID, Auth}, _, State = #stat
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
%% todo
|
%% todo
|
||||||
handle_event(cast, {handle, {data, #data{service_id = ServiceId, device_uuid = DeviceUUID, route_key = RouteKey0, metric = Metric}}}, ?STATE_ACTIVATED, State = #state{uuid = UUID, has_session = true, device_map = DeviceMap}) ->
|
handle_event(cast, {handle, {data, #data{service_id = ServiceId, device_uuid = DeviceUUID, route_key = RouteKey0, metric = Metric}}}, ?STATE_ACTIVATED,
|
||||||
|
State = #state{uuid = UUID, has_session = true, device_map = DeviceMap}) ->
|
||||||
|
|
||||||
lager:debug("[iot_host] metric_data host: ~p, service_id: ~p, device_uuid: ~p, route_key: ~p, metric: ~p", [UUID, ServiceId, DeviceUUID, RouteKey0, Metric]),
|
lager:debug("[iot_host] metric_data host: ~p, service_id: ~p, device_uuid: ~p, route_key: ~p, metric: ~p", [UUID, ServiceId, DeviceUUID, RouteKey0, Metric]),
|
||||||
case DeviceUUID =/= <<"">> of
|
case DeviceUUID =/= <<"">> of
|
||||||
true ->
|
true ->
|
||||||
@ -451,6 +453,7 @@ code_change(_OldVsn, StateName, State = #state{}, _Extra) ->
|
|||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
|
-spec get_route_key(binary()) -> binary().
|
||||||
get_route_key(<<"">>) ->
|
get_route_key(<<"">>) ->
|
||||||
<<"default">>;
|
<<"default">>;
|
||||||
get_route_key(RouteKey) when is_binary(RouteKey) ->
|
get_route_key(RouteKey) when is_binary(RouteKey) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user