实现 GeneralDeviceService
This commit is contained in:
@@ -56,7 +56,7 @@ func NewChirpStackTransport(config ChirpStackConfig, logger *logs.Logger) *Chirp
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ChirpStackTransport) Send(deviceID string, payload []byte) error {
|
||||
func (c *ChirpStackTransport) Send(address string, payload []byte) error {
|
||||
// 1. 构建 API 请求体。
|
||||
// - Confirmed: true 表示确认消息, 设为false将不保证消息送达(但可以节约下行容量)。
|
||||
// - Data: 经过 Base64 编码的数据。
|
||||
@@ -75,17 +75,17 @@ func (c *ChirpStackTransport) Send(deviceID string, payload []byte) error {
|
||||
// - WithBody 设置请求体。
|
||||
params := device_service.NewDeviceServiceEnqueueParams().
|
||||
WithTimeout(10 * time.Second).
|
||||
WithQueueItemDevEui(deviceID).
|
||||
WithQueueItemDevEui(address).
|
||||
WithBody(body)
|
||||
|
||||
// 3. 调用生成的客户端方法来发送请求。
|
||||
// c.authInfo 是您在 NewChirpStackTransport 中创建的认证信息。
|
||||
_, err := c.client.DeviceService.DeviceServiceEnqueue(params, c.authInfo)
|
||||
if err != nil {
|
||||
c.logger.Errorf("设备 %s 调用ChirpStack Enqueue失败: %v", deviceID, err)
|
||||
c.logger.Errorf("设备 %s 调用ChirpStack Enqueue失败: %v", address, err)
|
||||
return err
|
||||
}
|
||||
|
||||
c.logger.Infof("设备 %s 调用ChirpStack Enqueue成功", deviceID)
|
||||
c.logger.Infof("设备 %s 调用ChirpStack Enqueue成功", address)
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ package transport
|
||||
// Communicator 用于其他设备通信
|
||||
type Communicator interface {
|
||||
// Send 用于发送一条单向数据(不等待回信)
|
||||
Send(deviceID string, payload []byte) error
|
||||
Send(address string, payload []byte) error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user