package modbus import ( "server/model" "server/utils" "time" ) // GetSunPowerInfo 获取太阳能信息 func GetSunPowerInfo() error { for id, conn := range model.ConnectionMap { _, dev, err := utils.GetDataByDeviceId(id) if dev.IsSun && dev.State == 1 { //打开 并且在线 err = utils.WriteDevice(SolarEnergyData(), conn) if err != nil { return err } } } return nil } // DealWithOffline 处理离线 func DealWithOffline() { regions, _ := utils.LoadData() for i, region := range regions { for i2, device := range region.Devices { if time.Now().After(device.OnlineTime.Add(4 * time.Minute)) { regions[i].Devices[i2].State = 0 } } } utils.SaveData("static/data.json", regions) }