数据上报
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

package testUnit
import (
"encoding/hex"
"goUpload/consumers/CQZG/protoFiles"
"goUpload/dbHelper"
"google.golang.org/protobuf/proto"
"log"
"testing"
"time"
)
func TestMqttUpload(t *testing.T) {
//测试上报-实时的温湿度 数据
a09Request := &protoFiles.ComplexData{
SensorData: make([]*protoFiles.SensorData, 1),
}
sensorData := &protoFiles.SensorData{
MonitorType: 0, //监测类型
SensorID: 5000100001,
EventTime: time.Now().Unix(),
ChannelCode: "",
DataBody: &protoFiles.SensorData_Gnss{
Gnss: &protoFiles.GNSSRealTime{
X: []float32{-0.030051423, -0.030051423},
Y: []float32{-0.041311406, -0.041311406},
Z: []float32{-0.05905144, -0.05905144},
},
},
}
a09Request.SensorData = append(a09Request.SensorData, sensorData)
dataStr, err := proto.Marshal(a09Request)
hexStr := hex.EncodeToString(dataStr)
log.Println(err, hexStr)
mqHelpers := dbHelper.MqttHelper{
Host: "mqtt.datahub.anxinyun.cn",
Port: 1883,
ClientId: "lzwjdq500101-lk",
UserName: "lzwjdq500101",
Password: "lzwjdq500101p",
}
mqHelpers.Initial()
topic := "t/500101" //荔枝乌江大桥
//topic = "t/500103" //龙河桥
time.Sleep(time.Second * 1)
mqHelpers.Publish(topic, dataStr)
log.Println("=====推送完毕=====")
}