Commit 0a0b243c authored by sven's avatar sven

增加净化设施数据接收

parent 27d796be
...@@ -174,6 +174,11 @@ dtuServer: ...@@ -174,6 +174,11 @@ dtuServer:
addr: 0.0.0.0:9804 addr: 0.0.0.0:9804
enable: true enable: true
# 净化设备配置
mqttServer:
addr: 47.111.122.176:1883
enable: true
# 莹石云帐号 # 莹石云帐号
yinShiYun: yinShiYun:
13625717783: 13625717783:
......
...@@ -174,6 +174,11 @@ dtuServer: ...@@ -174,6 +174,11 @@ dtuServer:
addr: 0.0.0.0:9804 addr: 0.0.0.0:9804
enable: false enable: false
# 净化设备配置
mqttServer:
addr: 47.111.122.176:1883
enable: false
# 莹石云帐号 # 莹石云帐号
yinShiYun: yinShiYun:
13625717783: 13625717783:
......
...@@ -174,6 +174,11 @@ dtuServer: ...@@ -174,6 +174,11 @@ dtuServer:
addr: 0.0.0.0:9804 addr: 0.0.0.0:9804
enable: false enable: false
# 净化设备配置
mqttServer:
addr: 47.111.122.176:1883
enable: true
# 莹石云帐号 # 莹石云帐号
yinShiYun: yinShiYun:
13625717783: 13625717783:
......
...@@ -11,6 +11,7 @@ require ( ...@@ -11,6 +11,7 @@ require (
github.com/beego/beego/v2 v2.0.5 github.com/beego/beego/v2 v2.0.5
github.com/casbin/casbin/v2 v2.11.0 github.com/casbin/casbin/v2 v2.11.0
github.com/casbin/gorm-adapter/v3 v3.0.2 github.com/casbin/gorm-adapter/v3 v3.0.2
github.com/eclipse/paho.mqtt.golang v1.4.2 // indirect
github.com/flipped-aurora/ws v1.0.2 github.com/flipped-aurora/ws v1.0.2
github.com/fsnotify/fsnotify v1.4.9 github.com/fsnotify/fsnotify v1.4.9
github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6 github.com/fvbock/endless v0.0.0-20170109170031-447134032cb6
......
...@@ -147,6 +147,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn ...@@ -147,6 +147,8 @@ github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25Kn
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs= github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU= github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I= github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
github.com/eclipse/paho.mqtt.golang v1.4.2 h1:66wOzfUHSSI1zamx7jR6yMEI5EuHnT1G6rNA5PM12m4=
github.com/eclipse/paho.mqtt.golang v1.4.2/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA=
github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/edsrzf/mmap-go v0.0.0-20170320065105-0bce6a688712/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M= github.com/edsrzf/mmap-go v1.0.0/go.mod h1:YO35OhQPt3KJa3ryjFM5Bs14WD66h8eGKpfaBNrHW5M=
github.com/elastic/go-elasticsearch/v6 v6.8.10/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI= github.com/elastic/go-elasticsearch/v6 v6.8.10/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
...@@ -911,6 +913,7 @@ golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLL ...@@ -911,6 +913,7 @@ golang.org/x/net v0.0.0-20200222125558-5a598a2470a0/go.mod h1:z5CRVTTTmAJ677TzLL
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
......
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 10:35:22.357 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:37 register swagger handler
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 10:35:22.359 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:79 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 10:35:22.359 info /Users/honghuiliu/go/project/qsh-wc/server/core/server.go:36 server run success on {"address": ":8888"}
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 10:40:44.281 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:37 register swagger handler
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 10:40:44.283 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:79 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 10:40:44.283 info /Users/honghuiliu/go/project/qsh-wc/server/core/server.go:36 server run success on {"address": ":8888"}
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 11:10:36.843 info /Users/honghuiliu/go/project/qsh-wc/server/api/v1/system/sys_initdb.go:57 前往初始化数据库
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:33:21.225 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/gorm.go:61 register table success
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:33:21.243 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:37 register swagger handler
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:33:21.245 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:79 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:33:21.245 info /Users/honghuiliu/go/project/qsh-wc/server/core/server.go:36 server run success on {"address": ":8888"}
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:43:42.498 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/gorm.go:64 register table success
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:43:42.518 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:38 register swagger handler
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:43:42.520 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:82 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:43:42.520 info /Users/honghuiliu/go/project/qsh-wc/server/core/server.go:36 server run success on {"address": ":8888"}
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:49:02.795 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/gorm.go:64 register table success
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:49:02.812 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:38 register swagger handler
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:49:02.825 info /Users/honghuiliu/go/project/qsh-wc/server/initialize/router.go:82 router register success
[github.com/flipped-aurora/gin-vue-admin/server]2022/08/30 - 16:49:02.825 info /Users/honghuiliu/go/project/qsh-wc/server/core/server.go:36 server run success on {"address": ":8888"}
This diff is collapsed.
This diff is collapsed.
package main package main
import ( import (
"fmt"
"github.com/flipped-aurora/gin-vue-admin/server/core" "github.com/flipped-aurora/gin-vue-admin/server/core"
"github.com/flipped-aurora/gin-vue-admin/server/global" "github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/initialize" "github.com/flipped-aurora/gin-vue-admin/server/initialize"
...@@ -22,6 +24,7 @@ import ( ...@@ -22,6 +24,7 @@ import (
// @name x-token // @name x-token
// @BasePath / // @BasePath /
func main() { func main() {
global.GVA_VP = core.Viper() // 初始化Viper global.GVA_VP = core.Viper() // 初始化Viper
global.GVA_LOG = core.Zap() // 初始化zap日志库 global.GVA_LOG = core.Zap() // 初始化zap日志库
zap.ReplaceGlobals(global.GVA_LOG) zap.ReplaceGlobals(global.GVA_LOG)
...@@ -44,5 +47,14 @@ func main() { ...@@ -44,5 +47,14 @@ func main() {
}) })
go server.InitDtuServer(global.GVA_VP.GetString("dtuServer.addr")) go server.InitDtuServer(global.GVA_VP.GetString("dtuServer.addr"))
} }
// 净化设施服务
if global.GVA_VP.GetBool("mqttServer.enable") {
server.OnMqttMessage(func(data server.JingHuaData) error {
// {301022041237 {"MBR池溶氧值":0,"出水池PH值":4,"出水池流量值":0,"厌氧池PH值":4,"好氧池PH值":4.0,"好氧池溶氧值":0,"调节池流量值":0.1}}
fmt.Println(data)
return nil
})
go server.InitJinghuaServer(global.GVA_VP.GetString("mqttServer.addr"))
}
core.RunWindowsServer() core.RunWindowsServer()
} }
package server
import (
"log"
"os"
"strings"
"time"
MQTT "github.com/eclipse/paho.mqtt.golang"
"github.com/flipped-aurora/gin-vue-admin/server/global"
"github.com/flipped-aurora/gin-vue-admin/server/model/admin"
)
//define a function for the default message handler
var f MQTT.MessageHandler = func(client MQTT.Client, msg MQTT.Message) {
if jingHuaCb != nil {
jingHuaCb(JingHuaData{
strings.Replace(msg.Topic(), "Monitor/", "", 1),
string(msg.Payload()),
})
}
// fmt.Printf("TOPIC: %s\n", msg.Topic())
// fmt.Printf("MSG: %s\n", msg.Payload())
}
type JingHuaData struct {
JinghuaDeviceId string
Data string
}
type JingHuaCb func(data JingHuaData) error
var jingHuaCb JingHuaCb
func InitJinghuaServer(address string) {
opts := MQTT.NewClientOptions().AddBroker("tcp://" + address)
opts.SetClientID("dangliang")
opts.SetDefaultPublishHandler(f)
opts.SetPingTimeout(1 * time.Second)
opts.SetKeepAlive(60 * time.Second)
MQTT.ERROR = log.New(os.Stdout, "", 0)
c := MQTT.NewClient(opts)
if token := c.Connect(); token.Wait() && token.Error() != nil {
panic(token.Error())
}
// 从数据库中动态读取设备id,通过设备id订阅
var toilets []admin.QshToilet
err := global.GVA_DB.
Where("jinghua_device_id IS NOT NULL AND jinghua_device_id <> ''").
Where("type = 1").
Find(&toilets).Error
if err != nil {
global.GVA_LOG.Error(err.Error())
os.Exit(1)
}
for _, toilet := range toilets {
if token := c.Subscribe("Monitor/"+toilet.JinghuaDeviceId, 0, nil); token.Wait() && token.Error() != nil {
global.GVA_LOG.Error(token.Error().Error())
os.Exit(1)
}
}
defer c.Disconnect(250)
log.Println("Mqtt client is running!")
select {}
}
// OnMqttMessage 注册回调函数
func OnMqttMessage(cb JingHuaCb) {
jingHuaCb = cb
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment