Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

specify parameter positions for wind data parsing #5

Open
wehimwich opened this issue Oct 31, 2020 · 1 comment
Open

specify parameter positions for wind data parsing #5

wehimwich opened this issue Oct 31, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@wehimwich
Copy link
Member

Some wind sensors are configured to have the speed and direction data in different positions in the device response. There is not an urgent need to do this, but would it be easy to add (optionally?) specifying in gromet.yml which parameters are which?

For example, for the NMEA (0183 V2.20 :):) ) wind data format, the code had to be modified thusly:

diff --git a/main.go b/main.go
index 29bbb1d..9c1c88c 100644
--- a/main.go
+++ b/main.go
@@ -107,17 +107,17 @@ func openWindConn(addr string) <-chan windstate {
 
                                fields := strings.FieldsFunc(resp[1:], func(r rune) bool { return r == ',' })
 
-                               if len(fields) < 2 {
+                               if len(fields) < 3 {
                                        log.Printf("error reading from wind: unexpected response %q", resp)
                                        conn.Close()
                                        continue ConnLoop
                                }
 
                                s.t = time.Now()
-                               s.speed, err = strconv.ParseFloat(fields[0], 64)
+                               s.speed, err = strconv.ParseFloat(fields[3], 64)
                                if err != nil {
                                        s.speed = math.NaN()
-                                       log.Printf("error decoding message wind device: wind speed given as %q", fields[0])
+                                       log.Printf("error decoding message wind device: wind speed given as %q", fields[3])
                                }
 
                                s.direction, err = strconv.ParseFloat(fields[1], 64)

Of course in general the direction could be in a different field too. As the example shows, the number of required fields is also dependent.

This has not been an issue for the MET4 data so far.

@wehimwich wehimwich added the enhancement New feature or request label Oct 31, 2020
@wehimwich
Copy link
Member Author

Actually:

-                               if len(fields) < 2 {
+                               if len(fields) < 3 {

needs to be:

-                               if len(fields) < 2 {
+                               if len(fields) < 4 {

D'oh. Need to learn go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant