diff --git a/apps/iot/src/http_handler/device_handler.erl b/apps/iot/src/http_handler/device_handler.erl index 99dba1b..227cfee 100644 --- a/apps/iot/src/http_handler/device_handler.erl +++ b/apps/iot/src/http_handler/device_handler.erl @@ -21,7 +21,7 @@ handle_request("POST", "/device/reload", _, #{<<"host_id">> := HostId, <<"device_uuid">> := DeviceUUID}) when is_binary(DeviceUUID) -> lager:debug("[device_handler] host_id: ~p, will reload device uuid: ~p", [HostId, DeviceUUID]), AliasName = iot_host:get_alias_name(HostId), - case whereis(AliasName) of + case global:whereis_name(AliasName) of undefined -> {ok, 200, iot_util:json_error(404, <<"reload device failed">>)}; HostPid when is_pid(HostPid) -> @@ -37,7 +37,7 @@ handle_request("POST", "/device/reload", _, #{<<"host_id">> := HostId, <<"device %% 删除对应的主机信息 handle_request("POST", "/device/delete", _, #{<<"host_id">> := HostId, <<"device_uuid">> := DeviceUUID}) when is_binary(DeviceUUID) -> AliasName = iot_host:get_alias_name(HostId), - case whereis(AliasName) of + case global:whereis_name(AliasName) of undefined -> {ok, 200, iot_util:json_error(404, <<"delete device failed">>)}; HostPid when is_pid(HostPid) -> @@ -48,7 +48,7 @@ handle_request("POST", "/device/delete", _, #{<<"host_id">> := HostId, <<"device %% 处理主机的授权的激活 handle_request("POST", "/device/activate", _, #{<<"host_id">> := HostId, <<"device_uuid">> := DeviceUUID, <<"auth">> := Auth}) when is_binary(DeviceUUID) -> AliasName = iot_host:get_alias_name(HostId), - case whereis(AliasName) of + case global:whereis_name(AliasName) of undefined -> {ok, 200, iot_util:json_error(404, <<"activate device failed">>)}; HostPid when is_pid(HostPid) -> diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index fac5f36..1d3cc41 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -164,7 +164,7 @@ init([UUID]) -> %% 通过host_id注册别名, 可以避免通过查询数据库获取HostPid AliasName = get_alias_name(HostId), - erlang:register(AliasName, self()), + global:register_name(AliasName, self()), {ok, StateName, #state{host_id = HostId, uuid = UUID, aes = Aes}}; undefined ->