|
|
|
@ -13,6 +13,7 @@ import (
|
|
|
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
|
|
|
mqtt "github.com/eclipse/paho.mqtt.golang"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/google/uuid"
|
|
|
|
|
|
|
|
"github.com/shopspring/decimal"
|
|
|
|
"go_mqtt/models"
|
|
|
|
"go_mqtt/models"
|
|
|
|
_ "go_mqtt/models"
|
|
|
|
_ "go_mqtt/models"
|
|
|
|
"go_mqtt/mydb"
|
|
|
|
"go_mqtt/mydb"
|
|
|
|
@ -20,7 +21,6 @@ import (
|
|
|
|
"io/ioutil"
|
|
|
|
"io/ioutil"
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
"os"
|
|
|
|
"os"
|
|
|
|
"strconv"
|
|
|
|
|
|
|
|
"strings"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
@ -570,13 +570,13 @@ MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQCYwvInDUICXbmWcOAR5hm86mz7WlKL
|
|
|
|
temperature.DataMinute = now.Format("2006-01-02 15:04")
|
|
|
|
temperature.DataMinute = now.Format("2006-01-02 15:04")
|
|
|
|
//temperature.Humidity = result[0]
|
|
|
|
//temperature.Humidity = result[0]
|
|
|
|
//temperature.Temperature = result[1]
|
|
|
|
//temperature.Temperature = result[1]
|
|
|
|
// ParseFloat 返回 float64,需要显式转换为 float32
|
|
|
|
//字符串转decimal.Decimal
|
|
|
|
f1, err1 := strconv.ParseFloat(result[0], 32)
|
|
|
|
humidityValue, err1 := decimal.NewFromString(result[0])
|
|
|
|
f2, err2 := strconv.ParseFloat(result[1], 32)
|
|
|
|
temperatureValue, err2 := decimal.NewFromString(result[1])
|
|
|
|
if err1 == nil && err2 == nil {
|
|
|
|
if err1 == nil && err2 == nil {
|
|
|
|
// 转换为 float32
|
|
|
|
// decimal.Decimal
|
|
|
|
temperature.Humidity = float32(f1)
|
|
|
|
temperature.Humidity = humidityValue
|
|
|
|
temperature.Temperature = float32(f2)
|
|
|
|
temperature.Temperature = temperatureValue
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temperature.Topic = topic
|
|
|
|
temperature.Topic = topic
|
|
|
|
if topic == "WifiSHT/7C87CE9CA4E6/SHT20" {
|
|
|
|
if topic == "WifiSHT/7C87CE9CA4E6/SHT20" {
|
|
|
|
|