airrohr.go (1193B)
1 package airrohr 2 3 import ( 4 "encoding/json" 5 "io" 6 ) 7 8 // Value is a reading from a sensor. Values have a type, which specifies the 9 // type of reading and the value of the reading itself. 10 // 11 // Known value types are: 12 // SDS_P1: 10 μm particulate matter 13 // SDS_P2: 2.5 μm particulate matter 14 // BME280_temperature: temperature in degrees Celsius 15 // BME280_pression: pressure in Pascals 16 // BME280_humidity: percent humidity 17 // samples: the count of loops the main() function ran 18 // min_micro: the minimum time for a loop through main() in μs 19 // max_micro: the maximum time for a loop through main() in μs 20 // signal: WiFi signal strength in dBm 21 type Value struct { 22 Type string `json:"value_type"` 23 Value string `json:"value"` 24 } 25 26 // Sensor report from an ESP8266 NodeMCU running AirRohr firmware. 27 type Report struct { 28 SensorId string `json:"esp8266id"` 29 SoftwareVersion string `json:"software_version"` 30 Values []Value `json:"sensordatavalues"` 31 } 32 33 // Parse reads a JSON-encoded value and stores it in the value pointed to by v. 34 func Parse(r io.Reader, v *Report) error { 35 decoder := json.NewDecoder(r) 36 decoder.DisallowUnknownFields() 37 err := decoder.Decode(&v) 38 return err 39 }