Reputation: 495
What is the approach to be followed (on the device) if we have to publish events to cloud and subscribe for MQTT messages on the Device at the same time using the auth-token provided by the Watson IoT platform. When we try to publish to a topic when the device has already subscribed to some topics then the connection is lost. What would be the right approach to be followed in order to publish and subscribe at the same time? The details of the MQTT connection are as follows,
Client id- <d:orgId:deviceType:deviceId>
Username - use-token-auth
Password - <platform-generated-token>
Upvotes: 2
Views: 1048
Reputation: 5173
As per the documentation the devices in Watson IoT Platform can send events and subscribe to commands from the Platform. Note that the devices can only subscribe to commands and not events. Can you make sure that the topics used are correct?
Events
Events are the mechanism by which devices publish data to the Watson IoT Platform (and to the application). Devices control the content of their messages and assign a name for each event that is sent. The following MQTT topic to be used to publish the events,
iot-2/evt/event_id/fmt/format_string
where
Commands
Commands are the mechanism by which applications communicate with devices. Only applications can send commands, and the commands are sent to specific devices. The device must determine which action to take on receipt of any given command. 2 Devices can subscribe to command topics in the following format:
iot-2/cmd/command_id/fmt/format_string
Where
Refer to this section of the document for more information about the device connectivity to the Watson IoT Platform.
We have written a step by step guide to show how one can conect a device to Watson IoT Platform, publish events, subscribe to commands from application, subscribe to events in application, publish commands from the application to deivce using the Java client library for Watson IoT Platform and is availabe here - Java Client Library for IBM Watson IoT Platform.
Also, you can find samples in multiple languages. Refer this document for the list of available libraries and samples.
Upvotes: 2