123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package main
- import (
- "bufio"
- "flag"
- "fmt"
- "os"
- temperature "git.snppla.net/snppla/log_temperature"
- "git.snppla.net/snppla/log_temperature/array"
- )
- var db *string
- var username *string
- var password *string
- var host *string
- var locations = array.ArrayFlags{}
- func main() {
- db = flag.String("db", "temperature", "Influxdb database")
- username = flag.String("user", "", "Username")
- password = flag.String("password", "", "Password")
- host = flag.String("host", "http://localhost", "Host to connect to")
- flag.Var(&locations, "location", "Id and location of the sensor (5:conference-room")
- var reader *bufio.Reader
- flag.Parse()
- reader = bufio.NewReader(os.Stdin)
- parser := temperature.NewJSONParser(reader)
- writer, err := temperature.NewInfluxWriter(*db, *host, *username, *password, locations)
- if err != nil {
- fmt.Println(err.Error())
- return
- }
- for {
- measurement, err := parser.Measure()
- if measurement != nil {
- writer.Write(*measurement)
- }
- if err != nil {
- fmt.Println(err.Error())
- return
- }
- }
- }
- const (
- simpleTestString = `
- 2018-04-13 22:57:36 : Acurite 606TX Sensor : -5
- Battery: OK
- Temperature: 21.8 C
- 2018-04-13 22:58:01 : Acurite 606TX Sensor : 103
- Battery: OK
- Temperature: 24.3 C
- 2018-04-13 22:58:07 : Acurite 606TX Sensor : -5
- Battery: OK
- Temperature: 21.8 C
- 2018-04-13 22:58:32 : Acurite 606TX Sensor : 103
- Battery: OK
- Temperature: 24.6 C
- 2018-04-13 22:58:38 : Acurite 606TX Sensor : -5
- Battery: OK
- Temperature: 21.8 C
- 2018-04-13 22:59:03 : Acurite 606TX Sensor : 103
- Battery: OK
- Temperature: 24.8 C
- 2018-04-13 22:59:09 : Acurite 606TX Sensor : -5
- Battery: OK
- Temperature: 21.8 C
- `
- )
|