|
|
@@ -1,4 +1,67 @@
|
|
|
-package mqttreporter
|
|
|
+package mqtt_reporter
|
|
|
+
|
|
|
+import mcu "hnyfkj.com.cn/rtu/linux/rtu/cbd/mcu_ctrl_board"
|
|
|
+
|
|
|
+const (
|
|
|
+ dataSavFile = "backfill.json" // 上传失败时, 暂时保存到本地文件存储, 等待下次补录
|
|
|
+ dataMaxNums = 1000 // 最大保存的历史环境数据条数, 超过后删除最早的一条
|
|
|
+)
|
|
|
+
|
|
|
+type MCUData struct {
|
|
|
+ Dver string `json:"dver"` // 固件版本
|
|
|
+ Proj string `json:"proj"` // 项目标识
|
|
|
+ Dtype string `json:"dtype"` // 设备类型 : 3-测报灯
|
|
|
+ Vtype string `json:"vtype"` // 细分类型
|
|
|
+ TT string `json:"tt"` // 光控定时
|
|
|
+ TS string `json:"ts"` // 定时模式 : 0-光控, 1-时控
|
|
|
+ TPS string `json:"tps"` // 温控状态 : 0-正常, 1-温控
|
|
|
+ LPS string `json:"lps"` // 光控状态 : 0-正常, 1-光控
|
|
|
+ RPS string `json:"rps"` // 雨控状态 : 0-正常, 1-欠压
|
|
|
+ BatStatus string `json:"batStatus"` // 电池状态 : 0-正常, 1-欠压
|
|
|
+ Lamp string `json:"lamp"` // 灯管状态 : 0-正常, 1-异常
|
|
|
+ Upds string `json:"upds"` // 上仓门状态: 0-停止, 1-打开, 2-关闭
|
|
|
+ Dnds string `json:"dnds"` // 下仓门状态: 0-停止, 1-打开, 2-关闭
|
|
|
+ Hrt string `json:"hrt"` // 加热仓的温度
|
|
|
+ Hs string `json:"hs"` // 加热状态 : 0-关闭, 1-开启
|
|
|
+ Collt string `json:"collt"` // 收集时间参数
|
|
|
+ Htim string `json:"htim"` // 加热时间参数
|
|
|
+ Hst string `json:"hst"` // 加热设定温度
|
|
|
+ Tph string `json:"tph"` // 高温保护阈值
|
|
|
+ Tpl string `json:"tpl"` // 低温保护阈值
|
|
|
+ Shake string `json:"shake"` // 震动开关 : 0-关闭, 1-开启
|
|
|
+ ShakeSec string `json:"shake_sec"` // 震动持续时间
|
|
|
+ GPS string `json:"gps"` // 定位状态
|
|
|
+ Ds string `json:"ds"` // 设备开关机: 0-关机, 1-开机
|
|
|
+ Ah string `json:"ah"` // 环境湿度
|
|
|
+ At string `json:"at"` // 环境温度
|
|
|
+ Imei string `json:"imei"` // 4G模组IMEI
|
|
|
+ Iccid string `json:"iccid"` // SIM卡ICCID
|
|
|
+ Stamp string `json:"stamp"` // 数据时间, 格式为YYYYMMDDhhmmss
|
|
|
+ Lng string `json:"lng"` // 定位经度
|
|
|
+ Lat string `json:"lat"` // 定位纬度
|
|
|
+ Rcnt int `json:"rcnt"` // 设备启动次数
|
|
|
+ Current string `json:"current"` // 当前电流值
|
|
|
+ Vbat string `json:"vbat"` // 设备电压值
|
|
|
+ FuseVoltage string `json:"fuse_voltage"` // 保险丝电压
|
|
|
+ DatF string `json:"dat_f"` // 数据上传间隔
|
|
|
+ St string `json:"st"` // 工作开始时间
|
|
|
+ Et string `json:"et"` // 工作结束时间
|
|
|
+ Csq string `json:"csq"` // 蜂窝信号强度
|
|
|
+ Ws string `json:"ws"` //工作运行状态:0-待机, 1-工作
|
|
|
+}
|
|
|
|
|
|
func (r *MQTTReporter) StartDataWorker() {
|
|
|
+ go func() {
|
|
|
+ for { //////////////// 循环的处理控制板发来的数据上发请求 ////
|
|
|
+ select {
|
|
|
+ case data := <-mcu.Board.DataToMqttCh:
|
|
|
+ r.forwardDataToMqttServers(data)
|
|
|
+ case <-r.ctx.Done():
|
|
|
+ return
|
|
|
+ } // end select
|
|
|
+ } // end for
|
|
|
+ }()
|
|
|
+}
|
|
|
+
|
|
|
+func (r *MQTTReporter) forwardDataToMqttServers(data []byte) {
|
|
|
}
|