浏览代码

去除led screen中打印

terry 4 月之前
父节点
当前提交
ab5bca3eb8

+ 0 - 3
cloud/mqttforward/build.bat

@@ -1,3 +0,0 @@
-set GOARCH=amd64
-set GOOS=linux
-go build -o ../../build/cloud/mqttforward ./

+ 0 - 33
cloud/mqttforward/conf/log.conf

@@ -1,33 +0,0 @@
-debug {
-        level = "debug"
-        formatter.name = "text"
-        formatter.options  {
-                            force-colors      = true
-                            disable-colors    = false
-                            disable-timestamp = false
-                            full-timestamp    = false
-                            timestamp-format  = "2006-01-02 15:04:05"
-                            disable-sorting   = false
-        }
-}
-release {
-        level = "debug"
-        out.name = "rotatelogs"
-        out.options {
-                    path =  ./log/%Y%m%d.log
-                    #clock=
-                    #location=
-                    #link-name= logs/release/current.log
-                    #rotation-time=   #default 24hour
-                    #max-age=         #default 24hour * 7
-        }
-        formatter.name = "json"
-        formatter.options  {
-                            force-colors      = false
-                            disable-colors    = false
-                            disable-timestamp = false
-                            full-timestamp    = false
-                            timestamp-format  = "2006-01-02 15:04:05"
-                            disable-sorting   = false
-        }
-}

+ 0 - 33
cloud/mqttforward/main.go

@@ -1,33 +0,0 @@
-package main
-
-import (
-	"lc/common/mqtt"
-	"lc/common/util"
-	"os"
-	"path/filepath"
-	"runtime"
-)
-
-var FromMQTTConfig util.MQTTConfig
-var ToMQTTConfig util.MQTTConfig
-
-func ReadConfig() bool {
-	dir, _ := os.Getwd() //filepath.Abs(filepath.Dir(os.Args[0]))
-	fpath := dir + string(filepath.Separator) + "conf" + string(filepath.Separator)
-	//fmt.Printf("fpath = %v \n", fpath)
-	errA := FromMQTTConfig.ReadConfig(fpath, "FromBroker")
-	errB := ToMQTTConfig.ReadConfig(fpath, "ToBroker")
-	return errA && errB
-}
-
-func main() {
-	runtime.GOMAXPROCS(runtime.NumCPU())
-	util.InitLogrus("release")
-	if !ReadConfig() {
-		println("config err")
-		return
-	}
-	println("mqttforward runing ... ")
-	GetMQTTMgr().Subscribe("000000/its/#", mqtt.AtMostOnce, GetMQTTMgr().HandlerData)
-	select {}
-}

+ 0 - 128
cloud/mqttforward/mqttclient.go

@@ -1,128 +0,0 @@
-package main
-
-import (
-	"context"
-	"fmt"
-	"sync"
-	"time"
-
-	"lc/common/mqtt"
-
-	"github.com/sirupsen/logrus"
-)
-
-type BaseMqttOnline interface {
-	GetOnlineMsg() (string, string)
-	GetWillMsg() (string, string)
-}
-
-type EmptyMqttOnline struct {
-}
-
-func (o *EmptyMqttOnline) GetOnlineMsg() (string, string) {
-	return "", ""
-}
-func (o *EmptyMqttOnline) GetWillMsg() (string, string) {
-	return "", ""
-}
-
-type MqttClient struct {
-	mqtt       *mqtt.Client        //
-	mu         sync.Mutex          //保护mapTopics
-	mapTopics  map[string]mqtt.QOS //订阅的主题
-	timeout    uint                //超时时间,毫秒为单位
-	MqttOnline BaseMqttOnline      //是否发布上线消息&遗嘱消息
-}
-
-func NewMqttClient(server, clientid, user, password string, timeout uint, mqttOnline BaseMqttOnline) *MqttClient {
-	o := MqttClient{
-		mapTopics:  make(map[string]mqtt.QOS),
-		timeout:    timeout,
-		MqttOnline: mqttOnline,
-	}
-	client, err := mqtt.NewClient(mqtt.ClientOptions{
-		Servers:       []string{server},
-		ClientID:      clientid,
-		Username:      user,
-		Password:      password,
-		AutoReconnect: true,
-	}, &o)
-	if err != nil {
-		panic(fmt.Sprintf("MQTT错误:", err.Error()))
-		return nil
-	}
-	o.mqtt = client
-	err = client.Connect(o.Ctx())
-	return &o
-}
-
-func (o *MqttClient) ConnectionLostHandler(err error) {
-	logrus.Errorln("MqttClient.ConnectionLostHandler:MQTT连接已经断开,原因:", err)
-}
-
-func (o *MqttClient) OnConnectHandler() {
-	logrus.Infoln("MqttClient.OnConnectHandler:MQTT连接成功")
-	//连接成功则订阅主题
-	for k, v := range o.mapTopics {
-		err := o.Subscribe(k, v)
-		if err != nil {
-			return
-		}
-	}
-	topic, str := o.MqttOnline.GetOnlineMsg()
-	if topic != "" {
-		err := o.PublishString(topic, str, 0)
-		if err != nil {
-			return
-		}
-	}
-}
-
-func (o *MqttClient) GetWill() (topic string, payload string) {
-	return o.MqttOnline.GetWillMsg()
-}
-
-func (o *MqttClient) Connect() error {
-	return o.mqtt.Connect(o.Ctx())
-}
-
-func (o *MqttClient) IsConnected() bool {
-	return o.mqtt.IsConnected()
-}
-
-func (o *MqttClient) Publish(topic string, payload []byte, qos mqtt.QOS) error {
-	return o.mqtt.Publish(o.Ctx(), topic, payload, qos)
-}
-func (o *MqttClient) PublishString(topic string, payload string, qos mqtt.QOS) error {
-	return o.mqtt.PublishString(o.Ctx(), topic, payload, qos)
-}
-func (o *MqttClient) PublishJSON(topic string, payload interface{}, qos mqtt.QOS) error {
-	return o.mqtt.PublishJSON(o.Ctx(), topic, payload, qos)
-}
-
-func (o *MqttClient) Subscribe(topic string, qos mqtt.QOS) error {
-	o.mu.Lock()
-	defer o.mu.Unlock()
-	if _, ok := o.mapTopics[topic]; !ok {
-		o.mapTopics[topic] = qos
-	}
-	return o.mqtt.Subscribe(o.Ctx(), topic, qos)
-}
-
-func (o *MqttClient) Unsubscribe(topic string) error {
-	o.mu.Lock()
-	defer o.mu.Unlock()
-	if _, ok := o.mapTopics[topic]; ok {
-		delete(o.mapTopics, topic)
-	}
-	return o.mqtt.Unsubscribe(o.Ctx(), topic)
-}
-
-func (o *MqttClient) Handle(topic string, handler mqtt.MessageHandler) mqtt.Route {
-	return o.mqtt.Handle(topic, handler)
-}
-
-func (o *MqttClient) Ctx() context.Context {
-	ctx, _ := context.WithTimeout(context.Background(), time.Millisecond*time.Duration(o.timeout))
-	return ctx
-}

+ 0 - 64
cloud/mqttforward/mqttmgr.go

@@ -1,64 +0,0 @@
-package main
-
-import (
-	"lc/common/mqtt"
-	"sync"
-)
-
-var _mqttMgronce sync.Once
-var _mqttMgrsingle *MQTTMgr
-
-func GetMQTTMgr() *MQTTMgr {
-	_mqttMgronce.Do(func() {
-		_mqttMgrsingle = _newMQTTMgr()
-	})
-	return _mqttMgrsingle
-}
-
-type MQTTMgr struct {
-	FromCloud *MqttClient
-	ToCloud   *MqttClient
-}
-
-func _newMQTTMgr() *MQTTMgr {
-	return &MQTTMgr{
-		FromCloud: NewMqttClient(FromMQTTConfig.Mqtt_Server,
-			FromMQTTConfig.Mqtt_Id,
-			FromMQTTConfig.Mqtt_User,
-			FromMQTTConfig.Mqtt_Password,
-			3000, &EmptyMqttOnline{}),
-		ToCloud: NewMqttClient(ToMQTTConfig.Mqtt_Server,
-			ToMQTTConfig.Mqtt_Id,
-			ToMQTTConfig.Mqtt_User,
-			ToMQTTConfig.Mqtt_Password,
-			3000, &EmptyMqttOnline{}),
-	}
-}
-
-func (o *MQTTMgr) Subscribe(topic string, qos mqtt.QOS, handler mqtt.MessageHandler) {
-	o.FromCloud.Handle(topic, handler)
-	err := o.FromCloud.Subscribe(topic, qos)
-	if err != nil {
-		return
-	}
-}
-func (o *MQTTMgr) UnSubscribe(topic string) {
-	err := o.FromCloud.Unsubscribe(topic)
-	if err != nil {
-		return
-	}
-}
-
-func (o *MQTTMgr) Publish(topic string, payload string, qos mqtt.QOS) error {
-	return o.ToCloud.PublishString(topic, payload, qos)
-}
-
-func (o *MQTTMgr) HandlerData(m mqtt.Message) {
-	topic := m.Topic()
-	//newTopic := strings.ReplaceAll(topic, "000000", "100000")
-	newTopic := topic
-	err := o.Publish(newTopic, m.PayloadString(), m.QOS())
-	if err != nil {
-		return
-	}
-}

+ 3 - 3
edge/led_screen/clt_client/delete.go

@@ -7,8 +7,8 @@ import (
 	"net/http"
 )
 
-func (c cltclient) DelPrograms(m mqtt.Message, baseurl string) {
-	var ps []Programm
+func (c cltClient) DelPrograms(m mqtt.Message, baseurl string) {
+	var ps []ProgramInfo
 	m.PayloadJSON(&ps)
 	for _, v := range ps {
 		url := baseurl + "vsns/sources/lan/vsns/" + v.Name + ".vsn"
@@ -27,7 +27,7 @@ func (c cltclient) DelPrograms(m mqtt.Message, baseurl string) {
 	}
 }
 
-func (c cltclient) CleanAll(baseurl string) {
+func (c cltClient) CleanAll(baseurl string) {
 	url := baseurl + "clrprgms"
 	request, err := http.NewRequest("DELETE", url, nil)
 	if err != nil {

+ 2 - 2
edge/led_screen/clt_client/get.go

@@ -6,7 +6,7 @@ import (
 	"net/http"
 )
 
-func (c cltclient) SnapShot(url string) []byte {
+func (c cltClient) SnapShot(url string) []byte {
 	request, _ := http.NewRequest("get", url, nil)
 	request.Header.Add("Accrpt", "image/png")
 	resp, err := c.HttpClient.Do(request)
@@ -23,7 +23,7 @@ func (c cltclient) SnapShot(url string) []byte {
 	return body
 }
 
-func (c cltclient) CommonGet(url string) ([]byte, error) {
+func (c cltClient) CommonGet(url string) ([]byte, error) {
 	req, err := http.NewRequest("GET", url, nil)
 	req.Header.Add("Accept", "application/json")
 	resp, err := c.HttpClient.Do(req)

+ 4 - 4
edge/led_screen/clt_client/httpclient_led.go

@@ -6,11 +6,11 @@ import (
 )
 
 var once sync.Once
-var CltClient cltclient
+var CltClient cltClient
 
-func GetClient() cltclient {
+func GetClient() cltClient {
 	once.Do(func() {
-		CltClient = cltclient{
+		CltClient = cltClient{
 			http.Client{},
 		}
 		CltClient.LoadVsn()
@@ -18,6 +18,6 @@ func GetClient() cltclient {
 	return CltClient
 }
 
-type cltclient struct {
+type cltClient struct {
 	HttpClient http.Client
 }

+ 11 - 23
edge/led_screen/clt_client/post.go

@@ -3,7 +3,6 @@ package clt_client
 import (
 	"bytes"
 	"errors"
-	"github.com/sirupsen/logrus"
 	"io"
 	"io/ioutil"
 	"lc/common/mqtt"
@@ -15,19 +14,16 @@ import (
 )
 
 // PublishProgram 发布节目
-func (c cltclient) PublishProgram(m mqtt.Message, baseurl string) {
-	var pro Programm
+func (c cltClient) PublishProgram(m mqtt.Message, baseurl string) {
+	var pro ProgramInfo
 	m.PayloadJSON(&pro)
 	if pro.Type == "" || pro.Name == "" {
-		logrus.Errorf("mqtt message格式错误,topic:%v", m.Topic())
-		logrus.Errorf("PayloadString:%v", m.PayloadString())
 		return
 	}
 	//准备节目文件和vsn文件
 	payload, writer, err := prepareFiles(pro)
 	defer writer.Close()
 	if err != nil {
-		logrus.Errorf("error: %v, 消息内容: %+v", err, pro)
 		return
 	}
 	req, _ := http.NewRequest("POST", baseurl+"program/"+pro.Name+".vsn", payload)
@@ -39,7 +35,6 @@ DoReq:
 	defer resp.Body.Close()
 	ioutil.ReadAll(resp.Body)
 	if err != nil && n < 3 {
-		logrus.Errorf("节目发布http错误:%v, 消息内容: %+v", err, pro)
 		n++
 		time.Sleep(1500 * time.Millisecond)
 		goto DoReq
@@ -47,7 +42,7 @@ DoReq:
 }
 
 // 准备文件
-func prepareFiles(pro Programm) (*bytes.Buffer, *multipart.Writer, error) {
+func prepareFiles(pro ProgramInfo) (*bytes.Buffer, *multipart.Writer, error) {
 	payload := &bytes.Buffer{}
 	writer := multipart.NewWriter(payload)
 	defer writer.Close()
@@ -64,39 +59,32 @@ func prepareFiles(pro Programm) (*bytes.Buffer, *multipart.Writer, error) {
 		if err != nil {
 			return nil, nil, err
 		}
-		//
 		_, err = io.Copy(part, resp.Body)
 		if err != nil {
 			return nil, nil, err
 		}
 	}
 	//准备vsn文件
-	vsnfile := NewPVsn(pro)
-	if vsnfile == nil {
+	pVsn := NewPVsn(pro)
+	if pVsn == nil {
 		return nil, nil, errors.New("发布节目准备文件出错!")
 	}
 	part0, _ := writer.CreateFormFile(pro.Name+"-vsn", pro.Name+".vsn")
-	_, errFile3 := io.Copy(part0, bytes.NewReader(vsnfile))
+	_, errFile3 := io.Copy(part0, bytes.NewReader(pVsn))
 	if errFile3 != nil {
-		logrus.Errorf("打开vsn文件错误:%s", errFile3)
 		return nil, nil, errFile3
 	}
 	return payload, writer, nil
 }
 
-func (c cltclient) CommonPost(payload []byte, url string) error {
+func (c cltClient) CommonPost(payload []byte, url string) {
 	var r io.Reader
 	if payload == nil {
-		return errors.New("func CommonPost error POST操作消息体不能为空!")
+		return
 	} else {
 		r = bytes.NewReader(payload)
 	}
-	req, err := http.NewRequest("POST", url, r)
-	resp, err := c.HttpClient.Do(req)
-	if err != nil {
-		return err
-	}
-	defer resp.Body.Close()
-	ioutil.ReadAll(resp.Body)
-	return nil
+	req, _ := http.NewRequest("POST", url, r)
+	c.HttpClient.Do(req)
+	return
 }

+ 8 - 11
edge/led_screen/clt_client/protocol.go

@@ -8,16 +8,15 @@ import (
 	"path"
 )
 
-var Pvsn Vsn
-var Tvsn TextVsn
+var textVsn TextVsn
 
-type Programm struct {
+type ProgramInfo struct {
 	Type      string    `json:"type"`      //节目类型
 	Name      string    `json:"name"`      //节目名
 	ImageInfo ImageInfo `json:"imageinfo"` //图片,视频资源url
-	TextInfo  Textinfo  `json:"textinfo"`  //文本内容
+	TextInfo  TextInfo  `json:"textinfo"`  //文本内容
 }
-type Textinfo struct {
+type TextInfo struct {
 	Content    string `json:"content"`
 	LfFaceName string `json:"lfFaceName"`
 	BackColor  string `json:"backcolor"`
@@ -43,14 +42,12 @@ type playing struct {
 }
 
 // LoadVsn 加载  vsn文件->结构体
-func (c cltclient) LoadVsn() {
-	//open, _ := os.ReadFile(util.GetPath(0) + "picturevideo.vsn")
-	//json.Unmarshal(open, &Pvsn)
+func (c cltClient) LoadVsn() {
 	text, _ := os.ReadFile(util.GetPath(0) + "text.vsn")
-	json.Unmarshal(text, &Tvsn)
+	json.Unmarshal(text, &textVsn)
 }
 
-func NewPVsn(pro Programm) []byte {
+func NewPVsn(pro ProgramInfo) []byte {
 	var marshal []byte
 	switch pro.Type {
 	case "2":
@@ -92,7 +89,7 @@ func NewPVsn(pro Programm) []byte {
 	case "4":
 		fallthrough
 	case "5":
-		v := Tvsn
+		v := textVsn
 		v.Programs.Program.Pages[0].Regions[0].Items[0].Type = "5"
 		if pro.TextInfo.BackColor != "" {
 			v.Programs.Program.Pages[0].Regions[0].Items[0].BackColor = pro.TextInfo.BackColor

文件差异内容过多而无法显示
+ 0 - 38
edge/led_screen/clt_client/protocol_test.go


+ 6 - 17
edge/led_screen/clt_client/put.go

@@ -3,48 +3,37 @@ package clt_client
 import (
 	"bytes"
 	"errors"
-	"github.com/sirupsen/logrus"
 	"io"
-	"io/ioutil"
 	"lc/common/mqtt"
 	"net/http"
 )
 
 // SwitchProgram 切换节目
-func (c cltclient) SwitchProgram(m mqtt.Message, baseurl string) {
-	var p Programm
+func (c cltClient) SwitchProgram(m mqtt.Message, baseurl string) {
+	var p ProgramInfo
 	m.PayloadJSON(&p)
 	url := baseurl + "vsns/sources/lan/vsns/" + p.Name + ".vsn/activated"
 	request, err := http.NewRequest("PUT", url, nil)
 	if err != nil {
-		logrus.Errorf("Newrequest出错:%v", err)
 		return
 	}
 	request.Header.Set("Accept", "application/json")
-	resp, err := c.HttpClient.Do(request)
+	_, err = c.HttpClient.Do(request)
 	if err != nil {
-		logrus.Errorf("http错误%v", err)
 		return
 	}
-	defer resp.Body.Close()
-	ioutil.ReadAll(resp.Body)
 }
 
 // brightness
-func (c cltclient) CommonPut(payload []byte, url string) error {
+func (c cltClient) CommonPut(payload []byte, url string) error {
 	var r io.Reader
 	if payload == nil {
 		return errors.New("func CommonPut error PUT操作消息体不能为空!")
 	} else {
 		r = bytes.NewReader(payload)
 	}
-	req, err := http.NewRequest("PUT", url, r)
+	req, _ := http.NewRequest("PUT", url, r)
 	req.Header.Add("Content-Type", "application/json")
-	resp, err := c.HttpClient.Do(req)
-	if err != nil {
-		return err
-	}
-	defer resp.Body.Close()
-	ioutil.ReadAll(resp.Body)
+	c.HttpClient.Do(req)
 	return nil
 }

+ 3 - 7
edge/led_screen/config.go

@@ -49,14 +49,10 @@ func loadAppConfig() error {
 	return err
 }
 
-func loadDevInfos() error {
-	var devconfig = DevConfig{
+func loadDevInfos() {
+	var devConfig = DevConfig{
 		&ledInfos,
 	}
 	path := util.GetPath(0) + "led.json"
-	err := configor.Load(&devconfig, path)
-	if err == nil {
-		return nil
-	}
-	return err
+	configor.Load(&devConfig, path)
 }

+ 14 - 38
edge/led_screen/led_device.go

@@ -4,7 +4,6 @@ package main
 import (
 	"context"
 	"encoding/json"
-	"github.com/sirupsen/logrus"
 	"lc/common/mqtt"
 	"lc/common/protocol"
 	"lc/common/util"
@@ -79,14 +78,12 @@ func (l *LedDevice) Handle() {
 	for {
 		select {
 		case <-l.ctx.Done():
-			logrus.Errorf("设备[%s]的LedDevice.Handle退出,原因:%v", l.LedInfo.SN, l.ctx.Err())
 			return
 		case <-timer.C: //心跳,检查在线状态, 每隔1分钟执行一次
 			url := l.GetCltUrl(clt_client.POWERS_TATUS)
 			_, err := clt_client.GetClient().CommonGet(url)
 			if err != nil {
 				l.CheckOnline(l, uint8(1))
-				logrus.Errorf(" error: %v", err)
 				continue
 			}
 			l.CheckOnline(l, uint8(0))
@@ -97,8 +94,6 @@ func (l *LedDevice) Handle() {
 					action := strings.Split(mm.Topic(), "/")[4]
 					if fn, ok := l.mapTopicHandle[action]; ok {
 						fn(mm)
-					} else {
-						logrus.Errorf("LcDevice.Handle:不支持的主题:%s", mm.Topic())
 					}
 				}
 			} else {
@@ -108,7 +103,7 @@ func (l *LedDevice) Handle() {
 	}
 }
 
-func (o *LedDevice) CheckOnline(dev *LedDevice, online uint8) {
+func (l *LedDevice) CheckOnline(dev *LedDevice, online uint8) {
 	var obj protocol.Pack_LedState
 	if str, err := obj.EnCode(dev.SN, appConfig.GID, GetNextUint64(), util.MlNow(), online); err == nil {
 		topic := appConfig.Tenant + "/cltled/" + dev.SN + "/up/" + protocol.TP_LED_STATE + "/" + strconv.Itoa(int(GetNextUint64()))
@@ -118,26 +113,26 @@ func (o *LedDevice) CheckOnline(dev *LedDevice, online uint8) {
 }
 
 // LedData 上报信息屏详细信息
-func (o *LedDevice) LedData(dev *LedDevice) {
+func (l *LedDevice) LedData(dev *LedDevice) {
 	var data protocol.CltledData
 	//电源状态
-	res, _ := clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.POWERS_TATUS))
+	res, _ := clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.POWERS_TATUS))
 	json.Unmarshal(res, &data)
 	//音量
-	res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.GET_VOLUME))
+	res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.GET_VOLUME))
 	json.Unmarshal(res, &data)
 	//亮度色温
-	res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.GET_BRIGHTCOLOR))
+	res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.GET_BRIGHTCOLOR))
 	json.Unmarshal(res, &data)
 	//开关机时间
-	res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.GET_SCHEDULE))
+	res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.GET_SCHEDULE))
 	json.Unmarshal(res, &data)
 	//分辨率
-	res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.RESOLUTION))
+	res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.RESOLUTION))
 	json.Unmarshal(res, &data)
 
 	//当前节目
-	res, _ = clt_client.GetClient().CommonGet(o.GetCltUrl(clt_client.LIST_PROGRAMS))
+	res, _ = clt_client.GetClient().CommonGet(l.GetCltUrl(clt_client.LIST_PROGRAMS))
 	resMap := make(map[string]map[string]interface{})
 	json.Unmarshal(res, &resMap)
 	payingName, ok := resMap["playing"]["name"]
@@ -166,13 +161,6 @@ func (l *LedDevice) PublishProgram(m mqtt.Message) {
 	clt_client.GetClient().PublishProgram(m, l.BaseURL)
 	//获取结果 并 响应云端
 	l.ListPrograms(m)
-	//发布成功
-	//if resp.Playing.Name == pro.Name+".vsn" {
-	//	l.playing = resp.Playing.Name
-	//	logrus.Infof("%s发布成功!耗时:%v", pro.Name, (later - now))
-	//} else {
-	//	logrus.Infof("%s发布失败!耗时:%v", pro.Name, (later - now))
-	//}
 }
 
 func (l *LedDevice) SetSchedule(m mqtt.Message) {
@@ -188,11 +176,8 @@ func (l *LedDevice) ControlPower(m mqtt.Message) {
 	l.PowerStatus(m)
 }
 
-func (l *LedDevice) DoCommonPost(url, funcname string, m mqtt.Message) {
-	err := clt_client.GetClient().CommonPost(m.Payload(), url)
-	if err != nil {
-		logrus.Errorf(funcname+" error: %v", err)
-	}
+func (l *LedDevice) DoCommonPost(url, funcName string, m mqtt.Message) {
+	clt_client.GetClient().CommonPost(m.Payload(), url)
 }
 
 //==========================GET==================================GET
@@ -246,11 +231,8 @@ func (l *LedDevice) SnapShot(m mqtt.Message) {
 	GetMQTTMgr().Publish(getUpTopic(m.Topic()), shot, mqtt.AtMostOnce, ToCloud)
 }
 
-func (l *LedDevice) DoCommonGet(url, funcname string, m mqtt.Message) {
-	resp, err := clt_client.GetClient().CommonGet(url)
-	if err != nil {
-		logrus.Errorf(funcname+" error: %v", err)
-	}
+func (l *LedDevice) DoCommonGet(url, funcName string, m mqtt.Message) {
+	resp, _ := clt_client.GetClient().CommonGet(url)
 	GetMQTTMgr().Publish(getUpTopic(m.Topic()), resp, mqtt.AtMostOnce, ToCloud)
 }
 
@@ -265,20 +247,14 @@ func (l *LedDevice) SwitchProgram(m mqtt.Message) {
 // SetBright 调节屏幕亮度
 func (l *LedDevice) SetBright(m mqtt.Message) {
 	url := l.GetCltUrl(clt_client.SET_BRIGHT)
-	err := clt_client.GetClient().CommonPut(m.Payload(), url)
-	if err != nil {
-		logrus.Errorf("set bright error: %v", err)
-	}
+	clt_client.GetClient().CommonPut(m.Payload(), url)
 	l.GetBrightColor(m)
 }
 
 // SetVolume 设置音量
 func (l *LedDevice) SetVolume(m mqtt.Message) {
 	url := l.GetCltUrl(clt_client.SET_VOLUME)
-	err := clt_client.GetClient().CommonPut(m.Payload(), url)
-	if err != nil {
-		logrus.Errorf("set volume error: %v", err)
-	}
+	clt_client.GetClient().CommonPut(m.Payload(), url)
 	l.GetVolume(m)
 }
 

+ 2 - 6
edge/led_screen/ledmgr.go

@@ -3,7 +3,6 @@ package main
 //屏幕管理
 import (
 	"context"
-	"github.com/sirupsen/logrus"
 	"lc/common/mqtt"
 	"lc/common/util"
 	"sync"
@@ -17,7 +16,7 @@ type LedMgr struct {
 	cancel         context.CancelFunc
 	downQueue      *util.MlQueue
 	mapTopicHandle map[string]func(m mqtt.Message)
-	wrlock         sync.RWMutex
+	rwMutex        sync.RWMutex
 	mapLedDevice   map[string]*LedDevice
 }
 
@@ -35,10 +34,7 @@ func GetLedMgr() *LedMgr {
 }
 
 func (l *LedMgr) initAll() error {
-	if err := loadDevInfos(); err != nil {
-		logrus.Errorf("加载配置文件失败:%s", err.Error())
-		return err
-	}
+	loadDevInfos()
 	CreateLedDevs()
 	return nil
 }

+ 8 - 8
edge/led_screen/main.go

@@ -6,11 +6,11 @@ import (
 	"lc/edge/led_screen/clt_client"
 )
 
-var gopool *util.Pool
+var pool *util.Pool
 var IDGen util.IdWorker
 
-var appname = "led_screen"
-var appversion = "1.3.0"
+var appName = "led_screen"
+var appVersion = "1.3.0"
 
 func main() {
 	util.InitLogrus("release")
@@ -27,9 +27,9 @@ func main() {
 		logrus.Errorf("调用initAllLcDevice失败:%s", err.Error())
 		return
 	}
-	gopool = util.NewPool(5)
-	gopool.Add(GetMQTTMgr().MQTTMessageHandle, 1)
-	gopool.Add(GetMQTTMgr().MQTTConnectMgr, 2)
-	gopool.Run()
-	gopool.Wait()
+	pool = util.NewPool(5)
+	pool.Add(GetMQTTMgr().MQTTMessageHandle, 1)
+	pool.Add(GetMQTTMgr().MQTTConnectMgr, 2)
+	pool.Run()
+	pool.Wait()
 }

+ 1 - 6
edge/led_screen/mqttclient.go

@@ -3,12 +3,9 @@ package main
 import (
 	"context"
 	"fmt"
+	"lc/common/mqtt"
 	"sync"
 	"time"
-
-	"github.com/sirupsen/logrus"
-
-	"lc/common/mqtt"
 )
 
 type BaseMqttOnline interface {
@@ -57,11 +54,9 @@ func NewMqttClient(server, clientid, user, password string, timeout uint, mqttOn
 }
 
 func (o *MqttClient) ConnectionLostHandler(err error) {
-	logrus.Errorln("MqttClient.ConnectionLostHandler:MQTT连接已经断开,原因:", err)
 }
 
 func (o *MqttClient) OnConnectHandler() {
-	logrus.Infoln("MqttClient.OnConnectHandler:MQTT连接成功")
 	//连接成功则订阅主题
 	for k, v := range o.mapTopics {
 		o.Subscribe(k, v)

+ 9 - 16
edge/led_screen/mqttmgr.go

@@ -1,12 +1,9 @@
 package main
 
 import (
-	"runtime/debug"
 	"sync"
 	"time"
 
-	"github.com/sirupsen/logrus"
-
 	"lc/common/mqtt"
 	"lc/common/util"
 )
@@ -19,15 +16,15 @@ const (
 	ToEdge  OptType = 2 //发布和订阅边缘端的消息
 )
 
-var _mqttMgronce sync.Once
-var _mqttMgrsingle *MQTTMgr
+var mqttMgrOnce sync.Once
+var mqttMgrSingle *MQTTMgr
 
 // GetMQTTMgr 单态
 func GetMQTTMgr() *MQTTMgr {
-	_mqttMgronce.Do(func() {
-		_mqttMgrsingle = _newMQTTMgr()
+	mqttMgrOnce.Do(func() {
+		mqttMgrSingle = _newMQTTMgr()
 	})
-	return _mqttMgrsingle
+	return mqttMgrSingle
 }
 
 type MQTTMgr struct {
@@ -43,7 +40,7 @@ func _newMQTTMgr() *MQTTMgr {
 	}
 	if appConfig.Edge.Mqtt.Server != "" {
 		mgr.Edge = NewMqttClient(appConfig.Edge.Mqtt.Server,
-			appConfig.GID+"@"+appname+appversion,
+			appConfig.GID+"@"+appName+appVersion,
 			appConfig.Edge.Mqtt.User,
 			appConfig.Edge.Mqtt.Password,
 			appConfig.Edge.Mqtt.Timeout,
@@ -51,7 +48,7 @@ func _newMQTTMgr() *MQTTMgr {
 	}
 	if appConfig.Cloud.Mqtt.Server != "" {
 		mgr.Cloud = NewMqttClient(appConfig.Cloud.Mqtt.Server,
-			appConfig.GID+"@"+appname+appversion,
+			appConfig.GID+"@"+appName+appVersion,
 			appConfig.Cloud.Mqtt.User,
 			appConfig.Cloud.Mqtt.Password,
 			appConfig.Cloud.Mqtt.Timeout,
@@ -155,11 +152,8 @@ func (o *MQTTMgr) MQTTConnectMgr(args ...interface{}) interface{} {
 
 func (o *MQTTMgr) MQTTMessageHandle(args ...interface{}) interface{} {
 	defer func() {
-		if err := recover(); err != nil {
-			logrus.Errorf("MQTTMgr.MQTTMessageHandle发生异常:%v", err)
-			logrus.Errorf("MQTTMgr.MQTTMessageHandle发生异常,堆栈信息:%s", string(debug.Stack()))
-			gopool.Add(o.MQTTMessageHandle, args)
-		}
+		recover()
+		pool.Add(o.MQTTMessageHandle, args)
 	}()
 	var err error
 	for { //队列中所有发布
@@ -168,7 +162,6 @@ func (o *MQTTMgr) MQTTMessageHandle(args ...interface{}) interface{} {
 			RETRY:
 				err = o._publish(msg)
 				if err != nil {
-					logrus.Errorf("发布主题为%s的消息失败,原因:%s", msg.topic, err.Error())
 					time.Sleep(time.Second)
 					goto RETRY
 				}