123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package main
- import (
- "Yunlot/Handle/HttpServer"
- "Yunlot/Handle/MqttServer"
- "Yunlot/Handle/TcpServer"
- _ "Yunlot/Nats"
- "Yunlot/RunCode"
- "Yunlot/TimeTask"
- "Yunlot/conf"
- "Yunlot/logs"
- "Yunlot/models/Product"
- _ "Yunlot/routers"
- "fmt"
- "github.com/beego/beego/v2/adapter/orm"
- orm2 "github.com/beego/beego/v2/client/orm"
- beego "github.com/beego/beego/v2/server/web"
- _ "github.com/go-sql-driver/mysql"
- "strconv"
- )
- func init() {
- logs.Println("MysqlServer:" + conf.MysqlServer_Username + ":" + conf.MysqlServer_Password + "@tcp(" + conf.MysqlServer_UrlPort + ")/" + conf.MysqlServer_Database + "?charset=utf8mb4&loc=Local&parseTime=True")
- orm.RegisterDriver("mysql", orm.DRMySQL)
- orm.RegisterDataBase("default", "mysql",
- conf.MysqlServer_Username+":"+conf.MysqlServer_Password+"@tcp("+conf.MysqlServer_UrlPort+")/"+conf.MysqlServer_Database+"?charset=utf8mb4&loc=Local&parseTime=True",
- conf.MysqlServer_MaxIdleConnections, conf.MysqlServer_MaxOpenConnections)
- orm.RunSyncdb("default", false, true) // 创建数据库
- }
- func main() {
- beego.BConfig.AppName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) // 项目名
- beego.BConfig.ServerName = conf.AppName + "_" + strconv.Itoa(conf.HTTPPort) //server 名称
- beego.BConfig.RunMode = "dev" // 应用的运行模式
- beego.BConfig.Listen.HTTPPort = conf.HTTPPort //监听端口 本地:8518 线上:8528
- orm2.Debug = true
- logs.Println("MqttServer", " ======= 项目启动 ========")
- //go MqttServer2.Run_MqttServer() // MQTT 通讯
- //go MqttServer.MqttPolling() // MQTT 设备轮询
- //go MqttServer.DeviceMqttMap_go() //// 缓存数据发送-确保设备在休眠后 能收到数据
- // MQTT 通讯
- if conf.MqttServer_Open == 1 {
- mode := Product.ProductMode{
- Id: 1,
- T_name: "MQTT",
- T_address: fmt.Sprintf("mqtt://%s", conf.MqttServer_Url),
- T_describe: "MQTT 接入方式为设备和云平台提供双向连接,设备既可上报属性数据,也可接收云端的消息下发。",
- T_state: 1,
- }
- mode.Add()
- go MqttServer.Run_MqttServer()
- }
- // TCP 通讯
- if conf.TCPServer_Open == 1 {
- mode := Product.ProductMode{
- Id: 2,
- T_name: "TCP",
- T_address: fmt.Sprintf("TCP:%d", conf.TCPServer_Port),
- T_describe: "TCP 接入方式为设备和云平台提供双向连接,设备既可上报属性数据,也可接收云端的消息下发。",
- T_state: 1,
- }
- mode.Add()
- go TcpServer.TcpServer()
- }
- // HTTP 通讯
- if conf.HTTPServer_Open == 1 {
- mode := Product.ProductMode{
- Id: 6,
- T_name: "HTTP",
- T_address: fmt.Sprintf("http://:%d", conf.HTTPServer_Port),
- T_describe: "HTTP 接入方式为设备和云平台提供双向连接,设备既可上报属性数据,也可接收云端的消息下发。",
- T_state: 1,
- }
- mode.Add()
- go HttpServer.Run()
- }
- //go Nats.NatsInit() // Nats 通讯
- go TimeTask.Init() // 时间任务
- go RunCode.RunCode_Inte() // 代码编译
- beego.Run()
- }
|