@Chen, Bo Welcome to Microsoft Q&A forum!
-what's the topics that I can publish to or subscribe from device twin? and what's the payload like?
When you connect with MQTT, You will be able to send telemetry to the devices/{deviceId}/messages/events/ topic and receive cloud-to-device messages by subscribing to the devices/{deviceId}/messages/devicebound/# topic.
With MQTT, you can also update a reported property in the Device Twin. You can do that as follows:
The following sequence describes how a device updates the reported properties in the device twin in IoT Hub:
- A device must first subscribe to the $iothub/twin/res/# topic to receive the operation's responses from IoT Hub.
- A device sends a message that contains the device twin update to the $iothub/twin/PATCH/properties/reported/?$rid={request-id} topic. This message includes a request ID value.
- The service then sends a response message that contains the new ETag value for the reported properties collection on topic $iothub/twin/res/{status}/?$rid={request-id}. This response message uses the same request ID as the request.
The request message body contains a JSON document that contains new values for reported properties. Each member in the JSON document updates or add the corresponding member in the device twin's document. A member set to null deletes the member from the containing object. For example:
{
"telemetrySendFrequency": "35m",
"batteryLevel": 60
}
You will get a 204 status code if Success (no content is returned)
Please refer the documentation Using the MQTT protocol directly (as a module) for more details.
Do let us know if that helps or have any further queries.
If the response is helpful, please click "Accept Answer" and upvote it.