Пример #1
0
func etotal(sid string, client *http.Client,
	initiateData *dataproviders.InitiateData, pv *dataproviders.PvData, resp *[]byte) error {

	reg, err := regexp.Compile(etotalRegEx)
	if err != nil {
		log.Fail(err.Error())
		return err
	}
	foundPart1 := reg.Find(*resp)
	if len(foundPart1) < 6 {
		err := fmt.Errorf("Could not find etotal in response from inverter")
		return err
	}

	reg, err = regexp.Compile(numberRegEx)
	if err != nil {
		log.Fail(err.Error())
	}
	foundPart2 := reg.Find(foundPart1)
	if len(foundPart2) < 2 {
		err = fmt.Errorf("Could not find etotal in response from inverter")
		return err
	}

	etotal := string(foundPart2[1:])
	log.Debugf("Current etotal is %s", etotal)
	etotalfloat, err := strconv.ParseFloat(etotal, 64)

	pv.EnergyTotal = float32(etotalfloat)
	return nil
}
Пример #2
0
// Update PvData
func updatePvData(client *http.Client,
	initiateData *dataproviders.InitiateData,
	pv *dataproviders.PvData) error {

	log.Debug("Fetching update ...")
	url := fmt.Sprintf(MonthUrl, initiateData.PlantNo, time.Now().Format(requestDateFormat))
	resp, err := client.Get(url)
	if err != nil {
		log.Infof("Error in fetching from %s:%s", url, err.Error())
		return err
	}
	defer resp.Body.Close()
	if resp.StatusCode != 200 {
		err = fmt.Errorf("Dataprovider suntrol fail. Received http status %d from server", resp.StatusCode)
		log.Infof("%s", err.Error())
		return err
	}
	b, _ := ioutil.ReadAll(resp.Body)
	log.Tracef("Received body from server: %s", b)

	chartData := chartData{}
	err = json.Unmarshal(b, &chartData)
	if err != nil {
		log.Infof("Error in umashalling json %s", err.Error())
		return err
	}

	log.Tracef("Unmashaled charData is %s", chartData)

	pv.EnergyToday = uint16(chartData.DataPart[time.Now().Day()-1].Value * 1000)

	log.Tracef("pv is now %s", pv)

	return nil
}
Пример #3
0
func pac(sid string, client *http.Client,
	initiateData *dataproviders.InitiateData, pv *dataproviders.PvData, resp *[]byte) error {

	reg, err := regexp.Compile(curPwr1RegEx)
	if err != nil {
		log.Fail(err.Error())
	}
	foundPart1 := reg.Find(*resp)
	if len(foundPart1) < 6 {
		err = fmt.Errorf("Could not find curpower in response from inverter")
		return err
	}
	log.Debugf("Found part 1 to be '%s'", foundPart1)

	reg, err = regexp.Compile(numberRegEx)
	if err != nil {
		log.Fail(err.Error())
	}
	foundPart2 := reg.Find(foundPart1)
	if len(foundPart2) < 2 {
		err = fmt.Errorf("Could not find curpower in response from inverter")
		return err
	}

	pac := string(foundPart2[1:])
	log.Debugf("Current Pac is %s", pac)
	pacfloat, err := strconv.ParseFloat(pac, 64)

	// Are the value in kW or W?
	factor := 1.0
	if string(foundPart1[len(foundPart1)-1:len(foundPart1)]) == "k" {
		factor = 1000.0
	}
	pv.PowerAc = uint16(pacfloat * factor)

	return nil
}
Пример #4
0
func etoday(sid string, client *http.Client,
	initiateData *dataproviders.InitiateData, pv *dataproviders.PvData, resp *[]byte) error {

	reg, err := regexp.Compile(etodayRegEx)
	if err != nil {
		log.Fail(err.Error())
		return err
	}
	foundPart1 := reg.Find(*resp)
	if len(foundPart1) < 6 {
		err := fmt.Errorf("Could not find etoday in response from inverter")
		return err
	}

	reg, err = regexp.Compile(numberRegEx)
	if err != nil {
		log.Fail(err.Error())
	}
	foundPart2 := reg.Find(foundPart1)
	if len(foundPart2) < 2 {
		err = fmt.Errorf("Could not find etoday in response from inverter")
		return err
	}

	etoday := string(foundPart2[1:])
	log.Debugf("Current etoday is %s", etoday)
	etodayfloat, err := strconv.ParseFloat(etoday, 64)

	// Are the value in kW or W?
	factor := 1.0
	if string(foundPart1[len(foundPart1)-1:len(foundPart1)]) == "k" {
		factor = 1000.0
	}
	pv.EnergyToday = uint16(etodayfloat * factor)
	return nil
}