func writeState(timeC chan time.Time, c client.Client, conn opc.Connection, conf *Conf, exprMap map[string]*govaluate.EvaluableExpression) {

	batchconfig := client.BatchPointsConfig{
		Database:  conf.Influx.Database,
		Precision: conf.Influx.Precision, // "s"
	}

	for t := range timeC {

		// read data
		data := adapter(conn.Read())

		// create a new point batch
		bp, err := client.NewBatchPoints(batchconfig)
		if err != nil {
			fmt.Println(err)
			return
		}

		// define measurement and create data points
		for measurement, group := range conf.Measurements {
			//t := time.Now().Local()
			//data := conn.Read()
			for _, m := range group {
				tagMap := m.Tags
				fieldMap := make(map[string]interface{})

				for fieldKey, f := range m.Fields {
					ist, err := exprMap[f].Evaluate(data)
					if err != nil {
						fmt.Println(err)
						continue
					}
					fieldMap[fieldKey] = ist
				}

				// create influx data points
				pt, err := client.NewPoint(measurement, tagMap, fieldMap, t)
				if err != nil {
					fmt.Println("Error: ", err.Error())
				}

				// add data point to batch
				bp.AddPoint(pt)
			}
		}

		// write to database
		if err := c.Write(bp); err != nil {
			fmt.Println(err)
		}
	}
}
// writeState collects data and writes it to the influx database
writeState collects data and writes it to the influx database
// writeState collects data and writes it to the influx database
func writeState(timeC chan time.Time, c client.Client, conn opc.Connection, conf *Conf, exprMap map[string]*govaluate.EvaluableExpression) {
	batchconfig := client.BatchPointsConfig{
		Database:  conf.Influx.Database,
		Precision: conf.Influx.Precision, 
	}
	for t := range timeC {
		data := adapter(conn.Read())
		bp, err := client.NewBatchPoints(batchconfig)
		if err != nil {
			fmt.Println(err)
			return
		}
		for measurement, group := range conf.Measurements {
			for _, m := range group {
				tagMap := m.Tags
				fieldMap := make(map[string]interface{})
				for fieldKey, f := range m.Fields {
					ist, err := exprMap[f].Evaluate(data)
					if err != nil {
						fmt.Println(err)
						continue
					}
					fieldMap[fieldKey] = ist
				}
				pt, err := client.NewPoint(measurement, tagMap, fieldMap, t)
				if err != nil {
					fmt.Println("Error: ", err.Error())
				}
				bp.AddPoint(pt)
			}
		}
		if err := c.Write(bp); err != nil {
			fmt.Println(err)
		}
	}
}
func writeState ( timeC chan time . Time , c client . Client , conn opc . Connection , conf * Conf , exprMap map [ string ] * govaluate . EvaluableExpression ) { batchconfig := client . BatchPointsConfig { Database : conf . Influx . Database , Precision : conf . Influx . Precision , } for t := range timeC { data := adapter ( conn . Read ( ) ) bp , err := client . NewBatchPoints ( batchconfig ) if err != nil { fmt . Println ( err ) return } for measurement , group := range conf . Measurements { for _ , m := range group { tagMap := m . Tags fieldMap := make ( map [ string ] interface { } ) for fieldKey , f := range m . Fields { ist , err := exprMap [ f ] . Evaluate ( data ) if err != nil { fmt . Println ( err ) continue } fieldMap [ fieldKey ] = ist } pt , err := client . NewPoint ( measurement , tagMap , fieldMap , t ) if err != nil { fmt . Println ( " " , err . Error ( ) ) } bp . AddPoint ( pt ) } } if err := c . Write ( bp ) ; err != nil { fmt . Println ( err ) } } }
writeState collects data and writes it to the influx database
writeState collects data and writes it to the influx database
// "s" // read data // create a new point batch // define measurement and create data points //t := time.Now().Local() //data := conn.Read() // create influx data points // add data point to batch // write to database