· Zen HuiFer · Tutorial · 需要1 分钟阅读
WebSocket Access Device
This article details how to access devices through WebSocket in the Go IoT development platform, including login authentication and client creation steps, suitable for IoT developers.
Access Process
- Perform login authentication through HTTP Base Auth. Note: This account password information needs to be set through the front-end program.
Take Postman software as an example to send the following request
Note the following during this request process:
- The authentication method is Basic Auth
- Carry device_id in the request header
After sending the request, you will get data similar to the following structure
{
"message": "认证通过",
"uid": "123@5c1004d6-52e8-11ef-bba5-acde48001122"
}
This uid is used to create the WebSocket client.
- Create a WebSocket client, the link assembly format is
ws://127.0.0.1:13332/ws?id=${uid}
Note that once this link is actively disconnected, this uid will be permanently invalid. Please complete the HTTP Base Auth authentication again after it becomes invalid.
- Once the link is successfully established, the client can start uploading messages. Normally, after the message is uploaded, you will receive the text
Received websocket raw data successfully
.