From 742923a5512707bdfd4c0e2e9adfcb86b453be28 Mon Sep 17 00:00:00 2001
From: zhangzengfei <zhangzengfei@smartai.com>
Date: 星期日, 13 八月 2023 17:33:18 +0800
Subject: [PATCH] 修复长度大于1的读取结果

---
 msg/send.go |   34 +++++++++++++++++++++++++++++++---
 1 files changed, 31 insertions(+), 3 deletions(-)

diff --git a/msg/send.go b/msg/send.go
index 334d112..8290dda 100644
--- a/msg/send.go
+++ b/msg/send.go
@@ -2,11 +2,12 @@
 
 import (
 	"encoding/json"
-	"plc-recorder/util"
+	"time"
 
 	"plc-recorder/config"
 	"plc-recorder/logger"
 	"plc-recorder/nsqclient"
+	"plc-recorder/util"
 )
 
 func SendDeviceLiveData(response *PLCResponse) {
@@ -17,10 +18,37 @@
 	nsqclient.Produce(config.Options.PubPLCDataTopic, b)
 
 	// aps 鍙戝竷
-	if config.Options.ApsPLCDataWebApi != "" {
-		_, err := util.HttpPost(config.Options.ApsPLCDataWebApi, b)
+	if config.Options.PostPLCDataWebApi != "" {
+		token, _ := util.CreateToken()
+		_, err := util.HttpPost(config.Options.PostPLCDataWebApi, b, token)
 		if err != nil {
 			logger.Warn(err.Error())
 		}
 	}
 }
+
+func TestSendDeviceLiveData() {
+	for i := 1; i > 0; i++ {
+
+		countData := util.IntToBytes(123)
+
+		response := PLCResponse{
+			DeviceID:   "0000",
+			DeviceName: "test",
+			DeviceIP:   "0.0.0.0",
+			Online:     true,
+			PLCData: []PLCData{{
+				StartAddress: 100,
+				Length:       1,
+				Type:         "int",
+				FieldName:    "鐢熶骇璁℃暟",
+				RawData:      countData,
+			},
+			},
+		}
+
+		SendDeviceLiveData(&response)
+
+		time.Sleep(3 * time.Second)
+	}
+}

--
Gitblit v1.8.0