diff --git a/apps/iot/src/iot_device.erl b/apps/iot/src/iot_device.erl index 36a088f..2f5da92 100644 --- a/apps/iot/src/iot_device.erl +++ b/apps/iot/src/iot_device.erl @@ -51,7 +51,6 @@ change_status(Device = #device{status = Status}, NewStatus) when is_integer(NewS Device; change_status(Device = #device{device_uuid = DeviceUUID}, ?DEVICE_ONLINE) -> iot_api:change_device_status(DeviceUUID, ?DEVICE_ONLINE), - report_event(DeviceUUID, ?DEVICE_ONLINE), Device#device{status = ?DEVICE_ONLINE}; change_status(Device = #device{device_uuid = DeviceUUID}, ?DEVICE_OFFLINE) -> {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_ONLINE -> iot_api:change_device_status(DeviceUUID, ?DEVICE_OFFLINE), - report_event(DeviceUUID, ?DEVICE_OFFLINE), Device#device{status = ?DEVICE_OFFLINE} end. @@ -103,23 +101,4 @@ auth(Device = #device{auth_state = StateName, device_uuid = DeviceUUID}, Auth) w auth_state(?DEVICE_AUTH_AUTHED) -> ?STATE_ACTIVATED; auth_state(?DEVICE_AUTH_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]). \ No newline at end of file + ?STATE_DENIED. \ No newline at end of file diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index e84a695..84dc24c 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -351,7 +351,9 @@ handle_event({call, From}, {activate_device, DeviceUUID, Auth}, _, State = #stat end; %% 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]), case DeviceUUID =/= <<"">> of true -> @@ -451,6 +453,7 @@ code_change(_OldVsn, StateName, State = #state{}, _Extra) -> %%% Internal functions %%%=================================================================== +-spec get_route_key(binary()) -> binary(). get_route_key(<<"">>) -> <<"default">>; get_route_key(RouteKey) when is_binary(RouteKey) ->