V3MqttHandle.go 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979
  1. package MqttServer
  2. import (
  3. "Cold_mqtt/MqttServer/WarningNotice"
  4. "Cold_mqtt/Nats/NatsServer"
  5. "Cold_mqtt/lib"
  6. "Cold_mqtt/logs"
  7. "Cold_mqtt/models/Device"
  8. "Cold_mqtt/models/Product"
  9. "Cold_mqtt/models/Warning"
  10. "encoding/json"
  11. "fmt"
  12. "io/ioutil"
  13. "math"
  14. "net/http"
  15. "strconv"
  16. "strings"
  17. "time"
  18. )
  19. func AsyncFuncV3(r_Device *Device.Device, Ms_project Ms2m_Project, msg []byte) {
  20. ms2_Return := Ms2_Return{
  21. Type: Ms_project.Type,
  22. Msid: Ms_project.Msid,
  23. Status: 1,
  24. }
  25. switch Ms_project.Type {
  26. case 0: // 0:实时数据
  27. var ms2_Project_list Ms2_Project_list
  28. err := json.Unmarshal(msg, &ms2_Project_list)
  29. if err != nil {
  30. logs.Println("MqttServer", "JSON反序列化失败[Ms_project_0]", string(msg))
  31. logs.Println("JSON反序列化失败[Ms_project_0],err=", err)
  32. return
  33. }
  34. for _, v := range ms2_Project_list.Data {
  35. // 是否存在传感器 不存在 跳过
  36. DeviceSensor_r, is := Device.Read_DeviceSensor_ByT_sn(r_Device.T_sn, lib.To_int(v["id"]))
  37. if !is {
  38. logs.Println("MqttServer", "实时数据 传感器不存在 跳过处理", r_Device.T_sn+lib.To_string(v["id"]))
  39. continue
  40. }
  41. // lost 字段为传感器离线状态(1代表离线,在线不传此字段),如果离线 温湿度时间数据为空
  42. if _, lost_is := v["lost"]; lost_is {
  43. DeviceSensor_r.T_link = 0
  44. Device.Update_DeviceSensor(DeviceSensor_r, "T_link")
  45. Warning.Add_DeviceLogs(103, *r_Device, fmt.Sprintf("[%d]%s: 传感器异常断开!", DeviceSensor_r.T_id, DeviceSensor_r.T_name))
  46. // 发现 lost 此字段 代表 传感器异常!!!!!
  47. continue
  48. }
  49. int64_, _ := strconv.ParseInt(lib.To_string(v["ut"]), 10, 64)
  50. UT := time.Unix(int64_, 0)
  51. logs.Println(UT.Format("2006-01-02 15:04:05"))
  52. DeviceSensorParameter_r, is := Device.Read_DeviceSensorParameter(r_Device.T_sn, DeviceSensor_r.T_id)
  53. if !is {
  54. logs.Println("MqttServer", "记录数据 传感器参数不存在 跳过处理", r_Device.T_sn+lib.To_string(v["id"]))
  55. continue
  56. }
  57. //// 更新记录 - 缓存
  58. DeviceData_t := Device.DeviceData_R{
  59. T_t: float32(math.Ceil(float64(lib.To_float32(v["t"])*10)) / 10),
  60. T_rh: float32(math.Ceil(float64(lib.To_float32(v["h"])*10)) / 10),
  61. T_Site: lib.To_string(v["s"]),
  62. T_time: UT,
  63. T_sp: DeviceSensorParameter_r.Id,
  64. }
  65. Device.RedisDeviceData_Set(r_Device.T_sn, DeviceSensor_r.T_id, DeviceData_t)
  66. r_Device.T_Site = DeviceData_t.T_Site
  67. // 传感器属于 连接状态
  68. if DeviceSensor_r.T_link != 1 {
  69. DeviceSensor_r.T_link = 1
  70. Device.Update_DeviceSensor(DeviceSensor_r, "T_link")
  71. }
  72. }
  73. Device.Update_Device(*r_Device, "T_Site")
  74. // 反馈透传
  75. NatsServer.Mqtt_DeviceReal(r_Device.T_sn, msg)
  76. return
  77. case 1: // 1:记录数据
  78. var ms2_Project_list Ms2_Project_list
  79. err := json.Unmarshal(msg, &ms2_Project_list)
  80. if err != nil {
  81. logs.Println("MqttServer", "JSON反序列化失败[Ms_project_1]", string(msg))
  82. logs.Println("JSON反序列化失败[Ms_project_1],err=", err)
  83. return
  84. }
  85. // 监控状态 数据有效
  86. if math.Abs(float64(time.Now().Unix()-ms2_Project_list.Dut)) < 30 {
  87. r_Device.T_monitor = 1
  88. Device.Update_Device(*r_Device, "T_monitor")
  89. }
  90. // 回复
  91. ms2_Return.Status = 1
  92. for _, v := range ms2_Project_list.Data {
  93. int64_, _ := strconv.ParseInt(lib.To_string(v["ut"]), 10, 64)
  94. UT := time.Unix(int64_, 0)
  95. //时间异常 大于10s,直接丢掉数据
  96. if (UT.Unix() - time.Now().Unix()) > 60 {
  97. ms2_Return.Status = 3
  98. continue
  99. }
  100. // 是否存在传感器 不存在 跳过
  101. DeviceSensor_r, is := Device.Read_DeviceSensor_ByT_sn(r_Device.T_sn, lib.To_int(v["id"]))
  102. if !is {
  103. logs.Println("MqttServer", "记录数据 传感器不存在 跳过处理", r_Device.T_sn+lib.To_string(v["id"]))
  104. continue
  105. }
  106. // 获取传感器参数
  107. DeviceSensorParameter_r, is := Device.Read_DeviceSensorParameter(r_Device.T_sn, DeviceSensor_r.T_id)
  108. if !is {
  109. logs.Println("MqttServer", "记录数据 传感器参数不存在 跳过处理", r_Device.T_sn+lib.To_string(v["id"]))
  110. continue
  111. }
  112. //// 更新记录 - 缓存
  113. DeviceData_t := Device.DeviceData_R{
  114. T_t: float32(math.Ceil(float64(lib.To_float32(v["t"])*10)) / 10),
  115. T_rh: float32(math.Ceil(float64(lib.To_float32(v["h"])*10)) / 10),
  116. T_Site: lib.To_string(v["s"]),
  117. T_time: UT,
  118. T_sp: DeviceSensorParameter_r.Id,
  119. }
  120. // 验证 数据是否安装规定上传间隔
  121. //DeviceData_Previous_r, is := Device.RedisDeviceData_Get(r_Device.T_sn+"_Node", DeviceSensor_r.T_id)
  122. //if is {
  123. // //最新的时间 要大
  124. // if DeviceData_t.T_time.Unix() > DeviceData_Previous_r.T_time.Unix() {
  125. // DeviceParameter_r, is := Device.Read_DeviceParameter(r_Device.T_sn)
  126. // if is {
  127. // // 计算时间差
  128. // duration := DeviceData_Previous_r.T_time.Sub(DeviceData_t.T_time)
  129. // // 将时间差表示为秒
  130. // seconds := int(math.Abs(duration.Seconds()))
  131. // // 记录间隔 超过 保存间隔(+-10s)范围
  132. // //difference := int(math.Abs(float64(seconds - DeviceParameter_r.T_overA)))
  133. // if seconds < (DeviceParameter_r.T_saveT - 10) {
  134. // logs.Println(r_Device.T_sn, " 没有达到数据保存间隔,间隔:", seconds, " < ", DeviceParameter_r.T_saveT, "- 10", " 最新记录数据时间:", DeviceData_Previous_r.T_time)
  135. // if F_T_Exceeding(r_Device, DeviceData_t, DeviceSensorParameter_r) && F_H_Exceeding(r_Device, DeviceData_t, DeviceSensorParameter_r) {
  136. // logs.Println("!!! 跳过记录数据", "["+r_Device.T_sn+"]", string(msg))
  137. // continue
  138. // }
  139. // }
  140. // }
  141. // }
  142. //}
  143. DeviceParameter_r, is := Device.Read_DeviceParameter(r_Device.T_sn)
  144. if !is {
  145. DeviceParameter_r.T_saveT = 1
  146. }
  147. // 判断是否超标 fsfa
  148. //if F_T_Exceeding(r_Device, DeviceData_t, DeviceSensorParameter_r) && F_H_Exceeding(r_Device, DeviceData_t, DeviceSensorParameter_r) {
  149. // // 数据超标
  150. // logs.Println("数据超标")
  151. //
  152. //}else {
  153. //
  154. //}
  155. // 补丁, 判断 开机时间 ,根据 上电推送信息
  156. _, is = Device.RedisDeviceData_Get(r_Device.T_sn+"_Redis", DeviceSensor_r.T_id)
  157. Device.RedisDeviceData_Set(r_Device.T_sn+"_Redis", DeviceSensor_r.T_id, DeviceData_t) // 写缓存
  158. if is {
  159. // 计算周期时间
  160. DeviceData_t.T_time = lib.PeriodTime(DeviceData_t.T_time, DeviceParameter_r.T_saveT/60)
  161. logs.Println("计算周期时间:", UT.Format("2006-01-02 15:04:05"), "=>", DeviceData_t.T_time.Format("2006-01-02 15:04:05"), "保存间隔:", DeviceParameter_r.T_saveT)
  162. } else {
  163. logs.Println("直接保存数据,SN_Redis 获取失败!")
  164. }
  165. if r_, _ := Device.Add_DeviceData(r_Device.T_sn, DeviceSensor_r.T_id, DeviceData_t, true); r_ {
  166. // 被替换
  167. Device.Add_DeviceDataOld(Device.DeviceDataOld{
  168. T_sn: r_Device.T_sn,
  169. T_id: DeviceSensor_r.T_id,
  170. T_t: DeviceData_t.T_t,
  171. T_rh: DeviceData_t.T_rh,
  172. T_Site: DeviceData_t.T_Site,
  173. T_time: UT,
  174. T_operation: 4, // 4:忽略
  175. T_uuid: "",
  176. })
  177. }
  178. r_Device.T_Site = DeviceData_t.T_Site // GPS
  179. // 传感器属于 连接状态
  180. if DeviceSensor_r.T_link != 1 {
  181. DeviceSensor_r.T_link = 1
  182. Device.Update_DeviceSensor(DeviceSensor_r, "T_link")
  183. }
  184. }
  185. Device.Update_Device(*r_Device, "T_Site")
  186. NatsServer.Mqtt_DeviceReal(r_Device.T_sn, msg)
  187. break
  188. case 2: // 2:设备报警
  189. var ms2_Project Ms2_Project_list
  190. err := json.Unmarshal(msg, &ms2_Project)
  191. if err != nil {
  192. logs.PrintlnError("MqttServer", "设备报警", string(msg))
  193. break
  194. }
  195. // 缓存报警ID,防止重复发送
  196. if Warning.Redis_Warning_Repeat_T_sn_Msid(r_Device.T_sn + "|" + strconv.FormatInt(ms2_Project.Msid, 10)) {
  197. logs.Println("MqttServer", " 存在报警 跳过:", string(msg))
  198. break
  199. }
  200. for _, v := range ms2_Project.Data {
  201. var Warning_r Warning.Warning
  202. Warning_r.T_pid = r_Device.T_pid
  203. Warning_r.T_tp = lib.To_int(v["tp"]) // 报警类型
  204. Warning_r.T_sn = r_Device.T_sn
  205. Warning_r.T_id = lib.To_int(v["id"])
  206. Warning_r.T_Msid = Ms_project.Msid
  207. Warning_r.T_D_name = r_Device.T_devName
  208. Warning_r.T_State = 1
  209. // 获取 传感器 参数
  210. DeviceSensor_r, is := Device.Read_DeviceSensor_ByT_sn(r_Device.T_sn, Warning_r.T_id)
  211. if !is {
  212. logs.Println("MqttServer", " 传感器ID 不存在", string(msg))
  213. break
  214. }
  215. Warning_r.T_DS_name = DeviceSensor_r.T_name
  216. // 获取 传感器 配置参数
  217. DeviceSensorParameter_r, is := Device.Read_DeviceSensorParameter(Warning_r.T_sn, Warning_r.T_id)
  218. if !is {
  219. logs.Println("MqttServer", " 传感器ID 配置参数不存在", string(msg))
  220. break
  221. }
  222. // 温度湿度 封装
  223. T := float32(math.Ceil(float64(lib.To_float32(v["t"])*10)) / 10)
  224. RH := float32(math.Ceil(float64(lib.To_float32(v["h"])*10)) / 10)
  225. // 持续时间计算
  226. time_int64_, _ := strconv.ParseInt(lib.To_string(v["ut"]), 10, 64)
  227. time_int64_f, _ := strconv.ParseInt(lib.To_string(v["fut"]), 10, 64)
  228. if time_int64_f == 0 {
  229. time_int64_f = time_int64_
  230. }
  231. Warning_r.T_fUt = time.Unix(time_int64_f, 0)
  232. Warning_r.T_Ut = time.Unix(time_int64_, 0)
  233. // 如果记录时间大于当前时间
  234. //if time.Now().Unix() < time_int64_ {
  235. // Warning_r.T_Ut = time.Now()
  236. // Warning_r.T_Remark += "设备时间异常!"
  237. // // 推送同步 时间
  238. // go func() {
  239. // time.Sleep(time.Second * 3)
  240. // logs.Println(fmt.Sprintf("%s 时间相差:%d", r_Device.T_sn, int(math.Abs(float64(time_int64_-time.Now().Unix())))))
  241. // Warning.Add_DeviceLogs(103, *r_Device, fmt.Sprintf("时间相差:%d", int(math.Abs(float64(time_int64_-time.Now().Unix())))))
  242. // RTC_TimeStr(r_Device.T_sn, time.Now().Unix(), 99)
  243. // }()
  244. //}
  245. //时间异常 大于10s,直接丢掉数据
  246. //if (time_int64_ - time.Now().Unix()) > 10 {
  247. // ms2_Return.Status = 3
  248. // logs.Println("时间异常 大于10s,直接丢掉数据", Warning_r.T_sn)
  249. // continue
  250. //}
  251. // 查看 sn 是否有归属
  252. if Warning_r.T_pid == 0 { // 寻找报警归属
  253. if len(Warning_r.T_sn) > 10 {
  254. //r_Device, err := Device.Read_Device_ByT_sn(Warning_r.T_sn)
  255. //if err != nil {
  256. // logs.Println("MessageDisconnected 没有该设备:", Warning_r.T_sn)
  257. //}
  258. Warning_r.T_pid = r_Device.T_pid
  259. }
  260. }
  261. // 报警数据没有按照 设置间隔推送 (!!! 临时解决问题)
  262. //if Warning_r.T_tp == 1 || Warning_r.T_tp == 2 || Warning_r.T_tp == 4 || Warning_r.T_tp == 5 {
  263. // DeviceParameter_r, is := Device.Read_DeviceParameter(r_Device.T_sn)
  264. // if !is {
  265. // logs.Println(r_Device.T_sn + " 没有设备参数,跳过")
  266. // continue
  267. // }
  268. // Warningr := Warning.Read_T_snT_idT_tp(Warning_r.T_sn, Warning_r.T_id, Warning_r.T_tp)
  269. // if Warningr.Id != 0 {
  270. // // 计算时间差
  271. // duration := time.Now().Sub(Warningr.T_Ut)
  272. //
  273. // // 将时间差表示为秒
  274. // seconds := int(duration.Seconds())
  275. // if seconds < (DeviceParameter_r.T_overA - 3) {
  276. // logs.Println(r_Device.T_sn+" 没有达到设置报警间隔,跳过,间隔:", DeviceParameter_r.T_overA, " 时间差", seconds, " New Warningr.Id ", Warningr.Id)
  277. // logs.Println("!!! 跳过没有达到设置报警间隔", "["+r_Device.T_sn+"]", string(msg))
  278. // continue
  279. // }
  280. // }
  281. //
  282. //}
  283. // 时间周期补丁 --------------------
  284. //tp 报警类型
  285. // 1 温度超上限报警
  286. // 2 温度超下限报警
  287. // 3 温度恢复正常
  288. // 4 湿度超上限报警
  289. // 5 湿度超下限报警
  290. // 6 湿度恢复正常
  291. // 7 温度超上限预警
  292. // 8 温度超下限预警
  293. // 9 温度预警恢复正常
  294. // 10 湿度超上限预警
  295. // 11 湿度超下限预警
  296. // 12 湿度预警恢复正常
  297. // 首次时间缓存,防止乱传数据
  298. Warning_r.T_fUt = Warning.Redis_WarningStart(Warning_r)
  299. // 补丁
  300. if Warning_r.T_tp == 3 || Warning_r.T_tp == 6 || Warning_r.T_tp == 9 || Warning_r.T_tp == 12 { // 恢复
  301. Ws_time, Ws_is := Warning.Redis_WarningStart_DelK(Warning_r)
  302. if !Ws_is {
  303. logs.Println("之前没有报警信息,跳过保存报警!")
  304. continue
  305. } else {
  306. logs.Println("之前发送报警信息,首次报警时间:", Ws_time.Format("2006-01-02 15:04:05"))
  307. }
  308. } else {
  309. logs_s := "报警时间首次时间:" + Warning_r.T_fUt.Format("2006-01-02 15:04:05") + ",报警时间:" + Warning_r.T_Ut.Format("2006-01-02 15:04:05")
  310. Warning_r.T_Ut = lib.PeriodWTime(Warning_r.T_fUt, Warning_r.T_Ut, 2)
  311. logs.Println("报警时间计算处理:", logs_s, "=>", Warning_r.T_Ut.Format("2006-01-02 15:04:05"))
  312. if Warning.Redis_WarningTimeListIs(Warning_r) {
  313. logs.Println("报警时间已经存在,跳过!:", Warning_r.T_Ut.Format("2006-01-02 15:04:05"))
  314. continue
  315. }
  316. }
  317. //当期湿度:88.0%(↓23.0~↑73.0),已持续1小时33秒
  318. time_int64_f_x := (int(Warning_r.T_Ut.Unix()) - int(Warning_r.T_fUt.Unix()))
  319. logs.Println("持续时间:", time_int64_f_x)
  320. if time_int64_f_x > 0 {
  321. Warning_r.T_Remark += "已持续 " + lib.MinuteToDataTime(time_int64_f_x)
  322. }
  323. //// 报警处理
  324. WarningNotice.WarningCompanyNotice(&Warning_r, T, RH)
  325. //封装具体信息
  326. switch {
  327. case Warning_r.T_tp == 1, Warning_r.T_tp == 2, Warning_r.T_tp == 3:
  328. Warning_r.T_Remark = "当前温度:" + strconv.FormatFloat(float64(T), 'f', -1, 32) + " (↓" + strconv.FormatFloat(float64(DeviceSensorParameter_r.T_Tlower), 'f', -1, 32) + "~↑" + strconv.FormatFloat(float64(DeviceSensorParameter_r.T_Tupper), 'f', -1, 32) + ")," + Warning_r.T_Remark
  329. break
  330. case Warning_r.T_tp == 4, Warning_r.T_tp == 5, Warning_r.T_tp == 6:
  331. Warning_r.T_Remark = "当前湿度:" + strconv.FormatFloat(float64(RH), 'f', -1, 32) + " (↓" + strconv.FormatFloat(float64(DeviceSensorParameter_r.T_RHlower), 'f', -1, 32) + "~↑" + strconv.FormatFloat(float64(DeviceSensorParameter_r.T_RHupper), 'f', -1, 32) + ")," + Warning_r.T_Remark
  332. break
  333. case Warning_r.T_tp == 7, Warning_r.T_tp == 8, Warning_r.T_tp == 9:
  334. Warning_r.T_Remark = "当前温度:" + strconv.FormatFloat(float64(T), 'f', -1, 32) + " (↓" + strconv.FormatFloat(float64(DeviceSensorParameter_r.T_tprel), 'f', -1, 32) + "~↑" + strconv.FormatFloat(float64(DeviceSensorParameter_r.T_tpreu), 'f', -1, 32) + ")," + Warning_r.T_Remark
  335. break
  336. case Warning_r.T_tp == 10, Warning_r.T_tp == 11, Warning_r.T_tp == 12:
  337. Warning_r.T_Remark = "当前湿度:" + strconv.FormatFloat(float64(RH), 'f', -1, 32) + " (↓" + strconv.FormatFloat(float64(DeviceSensorParameter_r.T_hprel), 'f', -1, 32) + "~↑" + strconv.FormatFloat(float64(DeviceSensorParameter_r.T_hpreu), 'f', -1, 32) + ")," + Warning_r.T_Remark
  338. break
  339. }
  340. //记录温湿度
  341. Warning_r.T_t = T
  342. Warning_r.T_rh = RH
  343. Warning_r.T_sp = DeviceSensorParameter_r.Id
  344. // 添加报警
  345. _, err = Warning.Add_Warning(Warning_r)
  346. //// 不能 同时增加 记录数据,因为缺失GPS数据
  347. }
  348. NatsServer.Mqtt_DeviceReal(r_Device.T_sn, msg)
  349. break
  350. case 3: // 3:读取主机参数
  351. var ms2_Project Ms2_Project
  352. err := json.Unmarshal(msg, &ms2_Project)
  353. if err != nil {
  354. logs.PrintlnError("MqttServer", "JSON反序列化失败[Ms_Parameter]", string(msg))
  355. return
  356. }
  357. T_name := lib.To_string(ms2_Project.Data["name"])
  358. if len(T_name) == 0 {
  359. return
  360. }
  361. if T_name == "*" {
  362. T_name = r_Device.T_devName
  363. }
  364. if r_Device.T_devName == "未知类型" {
  365. T_name = Product.Read_ProductType_Get(r_Device.T_model)
  366. }
  367. if T_name == r_Device.T_sn {
  368. T_name = Product.Read_ProductType_Get(r_Device.T_model)
  369. }
  370. r_Device.T_devName = T_name
  371. Deviceparameter := Device.DeviceParameter{
  372. T_sn: r_Device.T_sn,
  373. T_name: T_name,
  374. T_saveT: lib.To_int(ms2_Project.Data["saveT"]), //数据保存间隔 (s)*最小值60
  375. T_overA: lib.To_int(ms2_Project.Data["overA"]), //超限报警触发间隔 (s)*最小值60
  376. T_outA: lib.To_int(ms2_Project.Data["outA"]), //断电报警触发间隔 (s)*最小值60
  377. T_lostA: lib.To_int(ms2_Project.Data["lostA"]), //传感器掉线报警触发间隔 (s)*最小值60
  378. T_warnD: lib.To_int(ms2_Project.Data["warnD"]), // 超限预警延时 (s)*
  379. T_scan: lib.To_int(ms2_Project.Data["scan"]), // 显示轮播间隔 s(1~240) 默认:5 *
  380. T_warn: lib.To_int(ms2_Project.Data["warn"]), // 超限预警触发间隔 (s)*为0时预警只触发一次 *最小值60
  381. T_bat: lib.To_int(ms2_Project.Data["bat"]), //电池电量下限 (%)*
  382. T_dormancy: lib.To_int(ms2_Project.Data["dormancy"]), //是否进入休眠 0:关闭 1:开启 默认:0
  383. T_snum: lib.To_int(ms2_Project.Data["snum"]), // 【管理主机】 - 传感器数量 (范围0~255)
  384. T_btname: lib.To_string(ms2_Project.Data["btname"]), //--蓝牙打印机名称 用于移动端连接蓝牙打印机
  385. T_btsid: lib.To_int(ms2_Project.Data["btsid"]), //--打印机服务号 用于移动端连接蓝牙打印机
  386. T_btchar: lib.To_int(ms2_Project.Data["btchar"]), //--蓝牙特征码 用于移动端连接蓝牙打印机
  387. //T_speed: lib.To_int(ms2_Project.Data["speed"]), //--蓝牙特征码 用于移动端连接蓝牙打印机
  388. T_State: 1,
  389. T_SendState: 1,
  390. }
  391. if Device.Add_DeviceParameter_fun(Deviceparameter) {
  392. Warning.Add_DeviceLogs(102, *r_Device, "修改主机参数")
  393. }
  394. Device.Update_Device(*r_Device, "T_devName")
  395. // 获取所有传感器
  396. //Read_DeviceSensorParameter(r_Device.T_sn)
  397. // 不用反馈
  398. return
  399. case 4: // 4:设置主机参数 - 反馈
  400. var ms2_Return_r Ms2_Return
  401. err := json.Unmarshal(msg, &ms2_Return_r)
  402. if err != nil {
  403. logs.PrintlnError("MqttServer", "JSON反序列化失败[4:设置主机参数]", string(msg), err.Error())
  404. return
  405. }
  406. DeviceParameter_r, err := Device.Read_DeviceParameter_SN_Msid(r_Device.T_sn, ms2_Return_r.Msid)
  407. if err != nil {
  408. logs.PrintlnError("MqttServer", " SN_Msid Err![4:设置主机参数]", string(msg), err.Error())
  409. return
  410. }
  411. DeviceParameter_r.T_SendState = 2
  412. // 判断参数 //1设置成功,0设置失败
  413. if ms2_Return_r.Status == 1 {
  414. DeviceParameter_r.T_SendState = 1
  415. r_Device.T_devName = DeviceParameter_r.T_name
  416. Device.Update_Device(*r_Device, "T_devName")
  417. }
  418. // 状态更新
  419. Device.Update_DeviceParameter_(DeviceParameter_r)
  420. // 同步参数
  421. DeviceParameter_r.T_State = 1
  422. Device.Add_DeviceParameter_fun(DeviceParameter_r)
  423. Warning.Add_DeviceLogs(102, *r_Device, "修改主机参数-反馈成功")
  424. // 取消掉 其他参数
  425. Device.UPDATE_DeviceParameter_SN_T_SendState_2_sql(r_Device.T_sn)
  426. return
  427. case 5: // 读取传感器参数
  428. var ms2_Project Ms2_Project_list
  429. err := json.Unmarshal(msg, &ms2_Project)
  430. if err != nil {
  431. logs.Println("MqttServer", "JSON反序列化失败[Ms_Parameter]", string(msg))
  432. logs.Println("JSON反序列化失败[Ms_Parameter],err=", err)
  433. return
  434. }
  435. for _, v := range ms2_Project.Data {
  436. DeviceSensor_r, is := Device.Read_DeviceSensor_ByT_sn(r_Device.T_sn, lib.To_int(v["id"]))
  437. T_name := lib.To_string(v["name"])
  438. if len(T_name) == 0 {
  439. continue
  440. }
  441. if T_name == "*" {
  442. T_name = r_Device.T_sn + "-" + lib.To_string(v["id"])
  443. if is {
  444. T_name = DeviceSensor_r.T_name
  445. }
  446. }
  447. // 不存在
  448. if !is {
  449. DeviceSensor_r.T_sn = r_Device.T_sn
  450. DeviceSensor_r.T_pid = r_Device.T_pid
  451. DeviceSensor_r.T_id = lib.To_int(v["id"])
  452. DeviceSensor_r.T_name = T_name
  453. DeviceSensor_r.T_datashow = 1
  454. DeviceSensor_r.T_sort = 1
  455. DeviceSensor_r.T_monitor = r_Device.T_monitor
  456. // 设备同步参数
  457. DeviceSensor_r.T_Dattery = r_Device.T_Dattery
  458. DeviceSensor_r.T_Site = r_Device.T_Site
  459. DeviceSensor_r.T_State = r_Device.T_State
  460. DeviceSensor_r.T_online = r_Device.T_online
  461. DeviceSensor_r.Id = Device.Add_DeviceSensor(*r_Device, DeviceSensor_r)
  462. }
  463. // 记录传感器
  464. Devicesensorparameter := Device.DeviceSensorParameter{
  465. T_sn: r_Device.T_sn,
  466. T_id: lib.To_int(v["id"]),
  467. T_name: T_name,
  468. // 报警
  469. T_Tlower: lib.To_float32(v["tl"]),
  470. T_Tupper: lib.To_float32(v["tu"]),
  471. T_RHlower: lib.To_float32(v["hl"]),
  472. T_RHupper: lib.To_float32(v["hu"]),
  473. // 预警
  474. T_enprel: lib.To_int(v["enprel"]),
  475. T_tprel: lib.To_float32(v["tprel"]),
  476. T_tpreu: lib.To_float32(v["tpreu"]),
  477. T_hprel: lib.To_float32(v["hprel"]),
  478. T_hpreu: lib.To_float32(v["hpreu"]),
  479. T_enprelnote: lib.To_int(v["enprelnote"]),
  480. //T_speed: lib.To_int(v["speed"]),
  481. //T_sense: lib.To_int(v["sense"]),
  482. T_en: lib.To_int(v["en"]),
  483. T_free: lib.To_int(v["free"]),
  484. T_Msid: ms2_Project.Msid, // 消息识别ID
  485. T_SendState: 1, // 发送状态 0 待发送 1 发送成功 2 失败 3 覆盖
  486. T_State: 1, // 1 系统获取 2 用户提交
  487. }
  488. // 强制修改 是否启用预警记录数据 1:启用 0:关闭 默认:1
  489. if Devicesensorparameter.T_enprelnote != 0 {
  490. Devicesensorparameter.T_enprelnote = 1
  491. }
  492. // 过滤参数 相同
  493. id := Device.Add_DeviceSensorParameter_fun(Devicesensorparameter)
  494. Warning.Add_DeviceLogs(102, *r_Device, "修改设备参数")
  495. logs.Println("DeviceSensorParameter ID:", id)
  496. // 对 传感器 的状态更新
  497. DeviceSensor_r.T_name = T_name
  498. DeviceSensor_r.T_sp = id
  499. Device.Update_DeviceSensor(DeviceSensor_r, "T_name", "T_sp")
  500. }
  501. go func() {
  502. time.Sleep(time.Second * 3)
  503. Get_Device_Realtime(r_Device.T_sn)
  504. }()
  505. // 不用反馈
  506. return
  507. case 6: // 设置传感器参数
  508. var ms2_Return_r Ms2_Return
  509. err := json.Unmarshal(msg, &ms2_Return_r)
  510. if err != nil {
  511. logs.Println("MqttServer", "JSON反序列化失败[Ms_Parameter]", string(msg))
  512. logs.Println("JSON反序列化失败[Ms_Parameter],err=", err)
  513. return
  514. }
  515. r, is := Device.Read_DeviceSensorParameter_SN_T_id_Msid(r_Device.T_sn, ms2_Return_r.Msid)
  516. if !is {
  517. logs.Println("设备配置", "设置设备参数 SN_Msid Err! [Ms_Parameter_r]", string(msg))
  518. return
  519. }
  520. r.T_SendState = 2
  521. // 判断参数 //1设置成功,0设置失败
  522. if ms2_Return_r.Status == 1 {
  523. r.T_SendState = 1
  524. DeviceSensor_r, is := Device.Read_DeviceSensor_ByT_sn(r.T_sn, r.T_id)
  525. if !is {
  526. logs.Println("设备配置", "设置传感器参数 r_DeviceSensor Err! [Ms_Parameter_r]", r.T_sn+"|"+strconv.Itoa(r.T_id))
  527. logs.Println("设置传感器参数 r_DeviceSensor Err![Ms_Parameter_r],err=", r.T_sn+"|"+strconv.Itoa(r.T_id))
  528. logs.Println("MqttServer", r_Device.T_sn+"["+lib.To_string(r.T_id)+"] 没有找到传感器:", string(msg))
  529. break
  530. }
  531. // 添加一份最新的
  532. r.T_State = 0
  533. id := Device.Add_DeviceSensorParameter_fun(r)
  534. Warning.Add_DeviceLogs(102, *r_Device, "修改设备参数")
  535. logs.Println("DeviceSensorParameter ID:", id)
  536. // 对 传感器 的状态更新
  537. DeviceSensor_r.T_name = r.T_name
  538. DeviceSensor_r.T_sp = id
  539. Device.Update_DeviceSensor(DeviceSensor_r, "T_name", "T_sp")
  540. }
  541. // 状态更新
  542. Device.Update_DeviceSensorParameter(r, "T_SendState")
  543. // 取消掉 其他参数
  544. Device.UPDATE_DeviceSensorParamete_SN_T_SendState_2_sql(r_Device.T_sn, strconv.Itoa(r.T_id))
  545. //// 更新主机参数
  546. //go func() {
  547. // time.Sleep(time.Second * 1)
  548. // Read_DeviceSensorParameter3(r_Device.T_sn)
  549. //}()
  550. return
  551. case 12:
  552. var ms2_Project Ms2_Project_list
  553. err := json.Unmarshal(msg, &ms2_Project)
  554. if err != nil {
  555. logs.PrintlnError("MqttServer", "JSON反序列化失败[Ms_project_2]", string(msg), err.Error())
  556. break
  557. }
  558. // 缓存报警ID,防止重复发送
  559. if Warning.Redis_Warning_Repeat_T_sn_Msid(r_Device.T_sn + "|" + strconv.FormatInt(ms2_Project.Msid, 10)) {
  560. logs.Println("MqttServer", " 存在报警 跳过:", string(msg))
  561. break
  562. }
  563. // {
  564. // "sn": "YD0123456789",
  565. // "type": 12,
  566. // "msid": 125456001,
  567. // "data": [
  568. // {
  569. // "tp":7, // 对照 报警类型对应表
  570. // "msg": "报警信息或故障信息", //如:1号传感器故障 (非必填,但是 要带字段)
  571. // "ut": 1626857518 //产生时间
  572. // },
  573. // ..........
  574. //]
  575. //}
  576. for _, v := range ms2_Project.Data {
  577. var Warning_r Warning.Warning
  578. Warning_r.T_tp = lib.To_int(v["tp"]) + 100 // 报警类型
  579. Warning_r.T_sn = r_Device.T_sn
  580. Warning_r.T_id = -1
  581. Warning_r.T_Msid = Ms_project.Msid
  582. Warning_r.T_D_name = r_Device.T_devName
  583. Warning_r.T_DS_name = r_Device.T_devName
  584. time_int64_, _ := strconv.ParseInt(lib.To_string(v["ut"]), 10, 64)
  585. Warning_r.T_Ut = time.Unix(time_int64_, 0)
  586. Warning_r.T_Remark = lib.To_string(v["msg"])
  587. Warning_r.T_State = 1
  588. //时间异常 大于10s,直接丢掉数据
  589. if (time_int64_ - time.Now().Unix()) > 10 {
  590. ms2_Return.Status = 3
  591. continue
  592. }
  593. // 持续时间计算
  594. time_int64_f, _ := strconv.ParseInt(lib.To_string(v["fut"]), 10, 64)
  595. if time_int64_f == 0 {
  596. time_int64_f = time_int64_
  597. }
  598. Warning_r.T_fUt = time.Unix(time_int64_f, 0)
  599. time_int64_f_x := (int(time_int64_) - int(time_int64_f))
  600. logs.Println(strconv.FormatInt(Warning_r.T_Msid, 10)+"持续时间:", time_int64_f_x)
  601. if time_int64_f_x > 0 {
  602. Warning_r.T_Remark += " 已持续" + lib.MinuteToDataTime(time_int64_f_x)
  603. }
  604. // 查看 sn 是否有归属
  605. if Warning_r.T_pid == 0 { // 寻找报警归属
  606. if len(Warning_r.T_sn) > 10 {
  607. r_Device, err := Device.Read_Device_ByT_sn(Warning_r.T_sn)
  608. if err != nil {
  609. logs.Println("MessageDisconnected 没有该设备:", Warning_r.T_sn)
  610. }
  611. Warning_r.T_pid = r_Device.T_pid
  612. }
  613. }
  614. switch Warning_r.T_tp {
  615. case 101: // 主机报警
  616. Warning_r.T_State = 3
  617. WarningNotice.WarningToAdminId(&Warning_r, []int{}) // 发送给 绑定公司管理员
  618. break
  619. case 115:
  620. Warning_r.T_Remark = "开始监测任务"
  621. // 1 start:开始监测任务,
  622. // 防止没有结束命令
  623. DeviceTask_r, ok := Device.Read_DeviceTask_All_Limit_1(r_Device.T_sn)
  624. logs.Println("DeviceTask_r.id:", DeviceTask_r.Id)
  625. if ok {
  626. if DeviceTask_r.T_Ut_end.IsZero() {
  627. logs.Println("没有结束 强制 更新上一条")
  628. DeviceTask_r.T_Ut_end = Warning_r.T_Ut
  629. Device.Update_DeviceTask(DeviceTask_r)
  630. }
  631. }
  632. logs.Println("插入新任务")
  633. // 插入开始 任务
  634. dt := Device.DeviceTask{
  635. T_sn: r_Device.T_sn,
  636. T_Ut_start: Warning_r.T_Ut,
  637. T_Ut: Warning_r.T_Ut,
  638. T_State: 1,
  639. }
  640. Device.Add_DeviceTask(dt)
  641. r_Device.T_monitor = 1
  642. break
  643. case 116:
  644. Warning_r.T_Remark = "中途打印任务"
  645. DeviceTask_r, ok := Device.Read_DeviceTask_All_Limit_1(r_Device.T_sn)
  646. if ok {
  647. if DeviceTask_r.T_Ut_end.IsZero() {
  648. DeviceTask_r.T_Ut_end = Warning_r.T_Ut
  649. DeviceTask_r.T_State = 3
  650. Device.Update_DeviceTask(DeviceTask_r)
  651. // 插入开始 任务
  652. dt := Device.DeviceTask{
  653. T_sn: r_Device.T_sn,
  654. T_Ut_start: DeviceTask_r.T_Ut_start,
  655. T_Ut: Warning_r.T_Ut,
  656. T_State: 1,
  657. }
  658. logs.Println("插入新任务")
  659. Device.Add_DeviceTask(dt)
  660. }
  661. }
  662. r_Device.T_monitor = 1
  663. break
  664. case 117:
  665. Warning_r.T_Remark = "结束监测任务"
  666. // 防止没有结束命令
  667. DeviceTask_r, ok := Device.Read_DeviceTask_All_Limit_1(r_Device.T_sn)
  668. if ok {
  669. if DeviceTask_r.T_Ut_end.IsZero() {
  670. DeviceTask_r.T_Ut_end = Warning_r.T_Ut
  671. DeviceTask_r.T_State = 2
  672. Device.Update_DeviceTask(DeviceTask_r)
  673. }
  674. }
  675. // 遍历所有探头,停止记录后 将最后一条数据写入关机数据
  676. DeviceSensorList := Device.Read_DeviceSensor_ByTsn(r_Device.T_sn)
  677. for _, vd := range DeviceSensorList {
  678. DeviceData_t, is := Device.RedisDeviceData_Get(r_Device.T_sn+"_Redis", vd.T_id)
  679. if is {
  680. Device.Add_DeviceData(r_Device.T_sn, vd.T_id, DeviceData_t, true)
  681. Device.RedisDeviceData_Del(r_Device.T_sn+"_Redis", vd.T_id) // 清除缓存标志
  682. }
  683. }
  684. r_Device.T_monitor = 0
  685. break
  686. }
  687. Device.Update_Device(*r_Device, "T_monitor")
  688. //// 推送运维信息
  689. WarningNotice.WarningCompanyNotice(&Warning_r, 0, 0)
  690. // 添加报警
  691. _, err = Warning.Add_Warning(Warning_r)
  692. }
  693. break
  694. case 13: // 上电推送信息
  695. var ms2_Project Ms2_Project
  696. err := json.Unmarshal(msg, &ms2_Project)
  697. if err != nil {
  698. logs.Println("MqttServer", "JSON反序列化失败[Ms_Parameter]", string(msg))
  699. logs.Println("JSON反序列化失败[Ms_Parameter],err=", err)
  700. return
  701. }
  702. var Warning_r Warning.Warning
  703. Warning_r.T_tp = 106 // 报警类型
  704. Warning_r.T_sn = r_Device.T_sn
  705. Warning_r.T_D_name = r_Device.T_devName
  706. Warning_r.T_id = 0
  707. Warning_r.T_DS_name = ""
  708. Warning_r.T_Msid = Ms_project.Msid
  709. r_Device.T_model = lib.To_string(ms2_Project.Data["model"])
  710. r_Device.T_sver = lib.To_string(ms2_Project.Data["sver"])
  711. r_Device.T_hver = lib.To_string(ms2_Project.Data["hver"])
  712. r_Device.T_imei = lib.To_string(ms2_Project.Data["imei"])
  713. r_Device.T_iccid = lib.To_string(ms2_Project.Data["iccid"])
  714. Device.Update_Device(*r_Device, "T_model", "T_sver", "T_hver", "T_imei", "T_iccid")
  715. // 加入日志
  716. // "rtc" : 1671173184,//设备时间
  717. // "rtl" : 3,//设备开机累计运行秒数
  718. // "st" : 1671173177,//设备开机时间
  719. // "lst" : 0//设备上次关机时间
  720. UT_rtc := time.Unix(int64(lib.To_int64(ms2_Project.Data["rtc"])), 0).Format("2006-01-02 15:04:05")
  721. UT_st := time.Unix(int64(lib.To_int64(ms2_Project.Data["st"])), 0).Format("2006-01-02 15:04:05")
  722. UT_lst := time.Unix(int64(lib.To_int64(ms2_Project.Data["lst"])), 0).Format("2006-01-02 15:04:05")
  723. UT_rtl := lib.To_string(ms2_Project.Data["rtl"])
  724. str := "----- 设备信息 -----\n"
  725. str += "设备型号:" + r_Device.T_model + " |\n"
  726. str += "软件版本:" + r_Device.T_sver + " |\n"
  727. str += "硬件版本:" + r_Device.T_hver + " |\n"
  728. str += "模组imei:" + r_Device.T_imei + " |\n"
  729. str += "sim卡号:" + r_Device.T_iccid + " |\n"
  730. str += "设备时间:" + UT_rtc + " |\n"
  731. str += "设备开机时间:" + UT_st + " |\n"
  732. str += "设备上次关机时间:" + UT_lst + " |\n"
  733. str += "设备开机累计运行秒数:" + UT_rtl + " |\n"
  734. Warning_r.T_Remark = str
  735. Warning_r.T_Ut = time.Now()
  736. Warning_r.T_State = 1
  737. // 添加报警
  738. _, err = Warning.Add_Warning(Warning_r)
  739. return
  740. case 15: // 网络延时测试
  741. Rt_Project_Data_r := Ms2_Project{
  742. Type: Ms_project.Type,
  743. Msid: Ms_project.Msid,
  744. }
  745. var Data map[string]interface{}
  746. Data = make(map[string]interface{})
  747. Data["ut"] = Ms_project.Dut
  748. Rt_Project_Data_r.Data = Data
  749. // 回复
  750. jsonStu, err := json.Marshal(Rt_Project_Data_r)
  751. if err != nil {
  752. return
  753. }
  754. Mqtt_publish(r_Device.T_sn, string(jsonStu))
  755. return
  756. case 88: // 临时授权
  757. var ms2_Project Ms2_Project
  758. err := json.Unmarshal(msg, &ms2_Project)
  759. if err != nil {
  760. logs.PrintlnError("MqttServer", "JSON反序列化失败[Ms_Parameter]", string(msg))
  761. return
  762. }
  763. url := "192.168.0.33:3991/CreateAuth"
  764. method := "POST"
  765. payload := strings.NewReader("model=" + lib.To_string(ms2_Project.Data["model"]) + "&sver=" + lib.To_string(ms2_Project.Data["sver"]) + "&hver=" + lib.To_string(ms2_Project.Data["hver"]) + "&imei=" + lib.To_string(ms2_Project.Data["imei"]) + "&iccid=" + lib.To_string(ms2_Project.Data["iccid"]) + "&sn=" + lib.To_string(ms2_Project.Data["sn"]))
  766. client := &http.Client{}
  767. req, err := http.NewRequest(method, url, payload)
  768. if err != nil {
  769. fmt.Println(err)
  770. return
  771. }
  772. req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
  773. res, err := client.Do(req)
  774. if err != nil {
  775. fmt.Println(err)
  776. return
  777. }
  778. defer res.Body.Close()
  779. body, err := ioutil.ReadAll(res.Body)
  780. if err != nil {
  781. fmt.Println(err)
  782. return
  783. }
  784. fmt.Println(string(body))
  785. // 实体类
  786. type Ms2_Projectccc struct {
  787. Pass string `json:"psaa"`
  788. Status string `json:"status"`
  789. }
  790. var ms2_Projectccc Ms2_Projectccc
  791. err = json.Unmarshal(body, &ms2_Projectccc)
  792. if err != nil {
  793. logs.PrintlnError("MqttServer", "JSON反序列化失败[Ms2_Projectccc]", string(msg))
  794. return
  795. }
  796. Rt_Project_Data_r := Ms2_Project{
  797. Type: Ms_project.Type,
  798. Msid: Ms_project.Msid,
  799. }
  800. var Data map[string]interface{}
  801. Data = make(map[string]interface{})
  802. Data["Pass"] = ms2_Projectccc.Pass
  803. Data["Status"] = ms2_Projectccc.Status
  804. Rt_Project_Data_r.Data = Data
  805. // 回复
  806. jsonStu, err := json.Marshal(Rt_Project_Data_r)
  807. if err != nil {
  808. return
  809. }
  810. Mqtt_publish(r_Device.T_sn, string(jsonStu))
  811. return
  812. case 98: // 时间同步
  813. RTC_TimeStr(r_Device.T_sn, Ms_project.Msid, 98)
  814. return
  815. case 100: // 设备实时状态推送
  816. var ms2_Project Ms2_Project
  817. err := json.Unmarshal(msg, &ms2_Project)
  818. if err != nil {
  819. logs.Println("MqttServer", "JSON反序列化失败[Ms_project_]", string(msg))
  820. logs.Println("JSON反序列化失败[Ms_project],err=", err)
  821. return
  822. }
  823. r_Device.T_Dattery = lib.To_int(ms2_Project.Data["power"]) //#设备剩余电量百分比
  824. r_Device.T_rssi = lib.To_string(ms2_Project.Data["rssi"]) //#信号强度
  825. Device.Update_Device(*r_Device, "T_Dattery", "T_rssi")
  826. // 反馈透传
  827. NatsServer.Mqtt_DeviceReal(r_Device.T_sn, msg)
  828. Device.Update_Device(*r_Device, "T_Dattery")
  829. return
  830. default:
  831. return
  832. }
  833. // 回复
  834. jsonStu, err := json.Marshal(ms2_Return)
  835. if err != nil {
  836. logs.PrintlnError("MqttServer", "json.Marshal ", string(msg))
  837. logs.Println("回复失败 [Ms_project_0],err=", err)
  838. return
  839. }
  840. Mqtt_publish(r_Device.T_sn, string(jsonStu))
  841. }
  842. func F_T_Exceeding(r_Device *Device.Device, DeviceData_t Device.DeviceData_R, DeviceSensorParameter_r Device.DeviceSensorParameter) bool {
  843. if r_Device.T_ist == 1 { // 温度 1开启 2关闭
  844. if !(DeviceSensorParameter_r.T_Tupper < DeviceData_t.T_t || DeviceData_t.T_t < DeviceSensorParameter_r.T_Tlower) {
  845. logs.Println(r_Device.T_sn+" 温度没有超标,且不在保存间隔范围 :", DeviceSensorParameter_r.T_Tupper, DeviceData_t.T_t, DeviceSensorParameter_r.T_Tlower)
  846. return true
  847. }
  848. }
  849. return false
  850. }
  851. func F_H_Exceeding(r_Device *Device.Device, DeviceData_t Device.DeviceData_R, DeviceSensorParameter_r Device.DeviceSensorParameter) bool {
  852. if r_Device.T_ish == 1 { // 湿度 1开启 2关闭
  853. if !(DeviceSensorParameter_r.T_RHupper < DeviceData_t.T_rh || DeviceData_t.T_rh < DeviceSensorParameter_r.T_RHlower) {
  854. logs.Println(r_Device.T_sn+" 湿度没有超标,且不在保存间隔范围 :", DeviceSensorParameter_r.T_RHupper, DeviceData_t.T_rh, DeviceSensorParameter_r.T_RHlower)
  855. return true
  856. }
  857. }
  858. return false
  859. }