Board logo

标题: 使用 Watson 和 IoT Platform 服务构建家庭助理移动应用程序(9) [打印本页]

作者: look_w    时间: 2018-1-13 19:09     标题: 使用 Watson 和 IoT Platform 服务构建家庭助理移动应用程序(9)

初始化实现 MQTT 回调向设备发送命令实现此函数来向设备发送命令。主题的格式为            iot-2/type/[DEV_TYPE]/id/[DEV_ID]/cmd/[light|camera]/fmt/json。
1
2
3
4
5
6
7
8
func sendToDevice(_ command: Command, subtopic: String) {
    if let json = command.toJSON() {
      let topic = "iot-2/type/\(Credentials.DevType)/id/\(Credentials.DevId)/cmd/\(subtopic)/fmt/json"
      let message = CocoaMQTTMessage(topic: topic, string: json)
      print("publish message \(json)")
      mqttClient.publish(message)
    }
  }






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0