public override void OnSubdevPropertiesSet(string requestId, PropsSet propsSet) { if (propsSet.deviceId == null) { return; } string nodeId = IotUtil.GetNodeIdFromDeviceId(propsSet.deviceId); if (nodeId == null) { return; } Session session = nodeIdToSesseionDic[nodeId]; if (session == null) { Log.Error("session is null ,nodeId:" + nodeId); return; } // 这里我们直接把对象转成string发给子设备,实际场景中可能需要进行一定的编解码转换 session.channel.WriteAndFlushAsync(JsonUtil.ConvertObjectToJsonString(propsSet)); // 为了简化处理,我们在这里直接回响应。更合理做法是在子设备处理完后再回响应 GetClient().RespondPropsSet(requestId, IotResult.SUCCESS); Log.Info("WriteAndFlushAsync " + propsSet); }
public override void OnSubdevMessage(DeviceMessage message) { if (message.deviceId == null) { return; } string nodeId = IotUtil.GetNodeIdFromDeviceId(message.deviceId); if (nodeId == null) { return; } Session session = nodeIdToSesseionDic[nodeId]; if (session == null) { Log.Error("session is null ,nodeId:" + nodeId); return; } session.channel.WriteAndFlushAsync(message.content); Log.Info("WriteAndFlushAsync " + message.content); }
public override void OnSubdevCommand(string requestId, Command command) { if (command.deviceId == null) { return; } string nodeId = IotUtil.GetNodeIdFromDeviceId(command.deviceId); if (nodeId == null) { return; } Session session = nodeIdToSesseionDic[nodeId]; if (session == null) { Log.Error("session is null ,nodeId is " + nodeId); return; } // 这里我们直接把command对象转成string发给子设备,实际场景中可能需要进行一定的编解码转换 session.channel.WriteAndFlushAsync(JsonUtil.ConvertObjectToJsonString(command)); // 为了简化处理,我们在这里直接回命令响应。更合理做法是在子设备处理完后再回响应 GetClient().RespondCommand(requestId, new CommandRsp(0)); Log.Info("WriteAndFlushAsync " + command); }