· 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.

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

  1. 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

image-20240805130404940

Note the following during this request process:

  1. The authentication method is Basic Auth
  2. 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.

  1. 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.

  1. 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.

image-20240805131006633

返回博客
Multi-protocol Support

Multi-protocol Support

This article introduces how to use WebSocket, MQTT, TCP/IP, COAP protocols for data transmission in the Go IoT development platform, and provides relevant port configuration and Nginx configuration examples to help developers better achieve multi-protocol support.

Device Access via COAP

Device Access via COAP

This article details how to use the COAP protocol to access devices on the Go IoT development platform, including access procedures, code examples, and precautions to help developers quickly get started and achieve efficient device access.

TCP/IP Access Device

TCP/IP Access Device

This article details how to use the TCP/IP protocol to access devices in the Go IoT development platform, including access processes, authentication methods, and data transmission examples, helping developers quickly get started and achieve efficient device access.

MQTT Client Management Solution

MQTT Client Management Solution

This article details the solution for designing and managing a large number of MQTT clients in IoT projects, including constraints, solution design, load balancing, and failover, helping developers optimize system performance and ensure stable operation.