| | |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "plc-recorder/util" |
| | | "time" |
| | | |
| | | "plc-recorder/config" |
| | | "plc-recorder/logger" |
| | | "plc-recorder/nsqclient" |
| | | "plc-recorder/util" |
| | | ) |
| | | |
| | | func SendDeviceLiveData(response *PLCResponse) { |
| | |
| | | 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) |
| | | } |
| | | } |