{"id":20279158,"url":"https://github.com/peterhellberg/ruuvitag","last_synced_at":"2025-04-11T06:15:12.744Z","repository":{"id":136623343,"uuid":"195578638","full_name":"peterhellberg/ruuvitag","owner":"peterhellberg","description":"This is a Go package for decoding RuuviTag sensor data","archived":false,"fork":false,"pushed_at":"2023-09-08T13:39:56.000Z","size":31,"stargazers_count":8,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-11T06:15:06.399Z","etag":null,"topics":["go","ruuvi","ruuvitag","ruuvitag-sensor"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterhellberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-07-06T20:03:20.000Z","updated_at":"2023-11-16T21:03:19.000Z","dependencies_parsed_at":null,"dependency_job_id":"fa607e0f-2168-4793-8e37-cba94a4bcad6","html_url":"https://github.com/peterhellberg/ruuvitag","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fruuvitag","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fruuvitag/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fruuvitag/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fruuvitag/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterhellberg","download_url":"https://codeload.github.com/peterhellberg/ruuvitag/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248351393,"owners_count":21089272,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","ruuvi","ruuvitag","ruuvitag-sensor"],"created_at":"2024-11-14T13:28:36.845Z","updated_at":"2025-04-11T06:15:12.722Z","avatar_url":"https://github.com/peterhellberg.png","language":"Go","readme":"# ruuvitag\n\n\u003cimg src=\"https://ruuvi.com/i/u/ruuvi-tag-interior-2048x704.jpg\" align=\"right\" width=\"320\"\u003e\n\n[![Build status](https://github.com/peterhellberg/ruuvitag/actions/workflows/test.yml/badge.svg)](https://github.com/peterhellberg/ruuvitag/actions/workflows/test.yml)\n[![Go Report Card](https://goreportcard.com/badge/github.com/peterhellberg/ruuvitag)](https://goreportcard.com/report/github.com/peterhellberg/ruuvitag)\n[![GoDoc](https://img.shields.io/badge/godoc-reference-blue.svg?style=flat)](https://pkg.go.dev/github.com/peterhellberg/ruuvitag)\n[![License MIT](https://img.shields.io/badge/license-MIT-lightgrey.svg?style=flat)](https://github.com/peterhellberg/ruuvitag#license-mit)\n\nThis is a Go package for decoding [RuuviTag](https://ruuvi.com/ruuvitag-specs/) sensor data.\n\nCurrently supports the\n[RAWv1](https://github.com/ruuvi/ruuvi-sensor-protocols/blob/master/dataformat_03.md) and\n[RAWv2](https://github.com/ruuvi/ruuvi-sensor-protocols/blob/master/dataformat_05.md) data formats.\n\n## Requirements\n\n - \u003chttps://ruuvi.com/ruuvitag-specs/\u003e - RuuviTag Environmental Sensor\n\n## Installation\n\n    go get -u github.com/peterhellberg/ruuvitag\n\n## Usage\n\n### Minimal example\n\n[embedmd]:# (examples/ruuvitag-minimal/ruuvitag-minimal.go)\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/peterhellberg/ruuvitag\"\n)\n\nfunc main() {\n\t// Manufacturer data in RAWv1 format\n\tdata := []byte{\n\t\t0x99, 0x04, 0x03, 0x49,\n\t\t0x82, 0x01, 0xc1, 0x82,\n\t\t0xff, 0xf9, 0xff, 0xd4,\n\t\t0x04, 0x24, 0x0c, 0x13,\n\t}\n\n\tif raw, err := ruuvitag.ParseRAWv1(data); err == nil {\n\t\tfmt.Printf(\"%+v\\n\", raw)\n\t}\n}\n```\n\n```sh\n{DataFormat:3 Humidity:36.5 Temperature:-2.01 Pressure:99538 Battery:3091 Acceleration:{X:-7 Y:-44 Z:1060}}\n```\n\n### Using `ruuvitag` with [github.com/go-ble/ble](https://github.com/go-ble/ble)\n\n[embedmd]:# (examples/ruuvitag-ble/ruuvitag-ble.go)\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/go-ble/ble\"\n\t\"github.com/go-ble/ble/examples/lib/dev\"\n\t\"github.com/peterhellberg/ruuvitag\"\n)\n\nfunc setup(ctx context.Context) context.Context {\n\td, err := dev.DefaultDevice()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tble.SetDefaultDevice(d)\n\n\treturn ble.WithSigHandler(context.WithCancel(ctx))\n}\n\nfunc main() {\n\tctx := setup(context.Background())\n\n\tble.Scan(ctx, true, handler, filter)\n}\n\nfunc handler(a ble.Advertisement) {\n\traw, err := ruuvitag.ParseRAWv1(a.ManufacturerData())\n\tif err == nil {\n\t\tfmt.Printf(\"[%s] RSSI: %3d: %+v\\n\", a.Addr(), a.RSSI(), raw)\n\t}\n}\n\nfunc filter(a ble.Advertisement) bool {\n\treturn ruuvitag.IsRAWv1(a.ManufacturerData())\n}\n```\n\n```sh\n[73cec0e0d7cf46a4b7cd90e847fd3564] RSSI: -80: {DataFormat:3 Humidity:45 Temperature:22.8 Pressure:99522 Battery:3097 Acceleration:{X:10 Y:-46 Z:1044}}\n[40c9d52c44974cc296fe2b443aef6850] RSSI: -76: {DataFormat:3 Humidity:42.5 Temperature:23.17 Pressure:99457 Battery:3103 Acceleration:{X:-24 Y:-40 Z:1009}}\n[40c9d52c44974cc296fe2b443aef6850] RSSI: -77: {DataFormat:3 Humidity:42.5 Temperature:23.17 Pressure:99457 Battery:3103 Acceleration:{X:-27 Y:-39 Z:1008}}\n[73cec0e0d7cf46a4b7cd90e847fd3564] RSSI: -79: {DataFormat:3 Humidity:45 Temperature:22.8 Pressure:99522 Battery:3097 Acceleration:{X:10 Y:-43 Z:1048}}\n[73cec0e0d7cf46a4b7cd90e847fd3564] RSSI: -79: {DataFormat:3 Humidity:45 Temperature:22.8 Pressure:99521 Battery:3103 Acceleration:{X:11 Y:-44 Z:1049}}\n[73cec0e0d7cf46a4b7cd90e847fd3564] RSSI: -79: {DataFormat:3 Humidity:45 Temperature:22.8 Pressure:99522 Battery:3097 Acceleration:{X:10 Y:-42 Z:1050}}\n[40c9d52c44974cc296fe2b443aef6850] RSSI: -77: {DataFormat:3 Humidity:42.5 Temperature:23.17 Pressure:99456 Battery:3103 Acceleration:{X:-30 Y:-42 Z:1012}}\n[649a163a6ad4462fa3b7dbedcbe47e25] RSSI: -99: {DataFormat:3 Humidity:64 Temperature:16.26 Pressure:99628 Battery:3103 Acceleration:{X:11 Y:118 Z:1033}}\n[73cec0e0d7cf46a4b7cd90e847fd3564] RSSI: -80: {DataFormat:3 Humidity:45 Temperature:22.8 Pressure:99523 Battery:3097 Acceleration:{X:7 Y:-45 Z:1049}}\n[649a163a6ad4462fa3b7dbedcbe47e25] RSSI: -99: {DataFormat:3 Humidity:64 Temperature:16.26 Pressure:99628 Battery:3103 Acceleration:{X:12 Y:119 Z:1038}}\n[40c9d52c44974cc296fe2b443aef6850] RSSI: -78: {DataFormat:3 Humidity:42.5 Temperature:23.17 Pressure:99457 Battery:3103 Acceleration:{X:-26 Y:-41 Z:1010}}\n[40c9d52c44974cc296fe2b443aef6850] RSSI: -77: {DataFormat:3 Humidity:42.5 Temperature:23.17 Pressure:99457 Battery:3103 Acceleration:{X:-27 Y:-40 Z:1013}}\n[649a163a6ad4462fa3b7dbedcbe47e25] RSSI: -99: {DataFormat:3 Humidity:64 Temperature:16.26 Pressure:99630 Battery:3109 Acceleration:{X:14 Y:116 Z:1035}}\n```\n\n### Using `ruuvitag` with [github.com/raff/goble](https://github.com/raff/goble) (compatible with macOS Mojave)\n\n[embedmd]:# (examples/ruuvitag-goble/ruuvitag-goble.go)\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/peterhellberg/ruuvitag\"\n\t\"github.com/raff/goble\"\n)\n\nfunc main() {\n\tvar quit chan bool\n\n\tble := goble.New()\n\n\tble.On(\"stateChange\", func(ev goble.Event) bool {\n\t\tswitch ev.State {\n\t\tcase \"poweredOn\":\n\t\t\tble.StartScanning(nil, true)\n\t\t\treturn false\n\t\tdefault:\n\t\t\tble.StopScanning()\n\t\t\tquit \u003c- true\n\n\t\t\treturn true\n\t\t}\n\t})\n\n\tble.On(\"discover\", func(ev goble.Event) bool {\n\t\tp := ev.Peripheral\n\t\ta := p.Advertisement\n\t\td := a.ManufacturerData\n\n\t\tswitch {\n\t\tcase ruuvitag.IsRAWv2(d):\n\t\t\tif raw, err := ruuvitag.ParseRAWv2(d); err == nil {\n\t\t\t\tfmt.Printf(\"[%s] RSSI: %d: %+v\\n\", p.Uuid, p.Rssi, raw)\n\t\t\t}\n\t\tcase ruuvitag.IsRAWv1(d):\n\t\t\tif raw, err := ruuvitag.ParseRAWv1(d); err == nil {\n\t\t\t\tfmt.Printf(\"[%s] RSSI: %d: %+v\\n\", p.Uuid, p.Rssi, raw)\n\t\t\t}\n\t\t}\n\n\t\treturn false\n\t})\n\n\tble.Init()\n\n\t\u003c-quit\n}\n```\n\n```sh\n[1592c47816f74834a98dbea4e54b9812] RSSI: 27: {DataFormat:3 Humidity:48 Temperature:24.24 Pressure:101009 Acceleration:{X:-701 Y:-463 Z:595} Battery:3091}\n[a7bd46a2cac146f580c61b2fda061bad] RSSI: -87: {DataFormat:3 Humidity:45 Temperature:25.48 Pressure:101092 Acceleration:{X:-123 Y:0 Z:1030} Battery:3097}\n[1592c47816f74834a98dbea4e54b9812] RSSI: 27: {DataFormat:3 Humidity:48 Temperature:24.24 Pressure:101009 Acceleration:{X:-700 Y:-464 Z:594} Battery:3085}\n[42078647994e4f999f556488ad8a21eb] RSSI: 27: {DataFormat:3 Humidity:46 Temperature:23.37 Pressure:100947 Acceleration:{X:-27 Y:-42 Z:1012} Battery:3079}\n[1592c47816f74834a98dbea4e54b9812] RSSI: 16: {DataFormat:3 Humidity:48 Temperature:24.24 Pressure:101008 Acceleration:{X:-701 Y:-462 Z:593} Battery:3079}\n[a7bd46a2cac146f580c61b2fda061bad] RSSI: -89: {DataFormat:3 Humidity:45.5 Temperature:25.36 Pressure:101091 Acceleration:{X:-126 Y:4 Z:1028} Battery:3103}\n[a7bd46a2cac146f580c61b2fda061bad] RSSI: -89: {DataFormat:3 Humidity:45.5 Temperature:25.35 Pressure:101092 Acceleration:{X:-123 Y:2 Z:1023} Battery:3091}\n```\n\n### Publishing to `NATS`\n\n[embedmd]:# (examples/ruuvitag-nats/ruuvitag-nats.go)\n```go\npackage main\n\nimport (\n\t\"context\"\n\t\"time\"\n\n\t\"github.com/go-ble/ble\"\n\t\"github.com/go-ble/ble/examples/lib/dev\"\n\t\"github.com/nats-io/nats.go\"\n\t\"github.com/peterhellberg/ruuvitag\"\n)\n\nfunc main() {\n\td, err := dev.DefaultDevice()\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tble.SetDefaultDevice(d)\n\n\tnc, err := nats.Connect(nats.DefaultURL)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tc, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tctx := ble.WithSigHandler(context.WithCancel(context.Background()))\n\n\tble.Scan(ctx, true, func(a ble.Advertisement) {\n\t\traw, err := ruuvitag.ParseRAWv1(a.ManufacturerData())\n\t\tif err == nil {\n\t\t\tc.Publish(\"ruuvitag.\"+a.Addr().String(), struct {\n\t\t\t\truuvitag.RAWv1\n\t\t\t\tRSSI int\n\t\t\t\tTime time.Time\n\t\t\t}{raw, a.RSSI(), time.Now()})\n\t\t}\n\t}, func(a ble.Advertisement) bool {\n\t\treturn ruuvitag.IsRAWv1(a.ManufacturerData())\n\t})\n\n\tc.Close()\n}\n```\n\n\u003cimg src=\"https://data.gopher.se/gopher/viking-gopher.svg\" align=\"right\" width=\"30%\" height=\"300\"\u003e\n\n## License (MIT)\n\nCopyright (c) 2019-2023 [Peter Hellberg](https://c7.se)\n\n\u003e Permission is hereby granted, free of charge, to any person obtaining\n\u003e a copy of this software and associated documentation files (the\n\u003e \"Software\"), to deal in the Software without restriction, including\n\u003e without limitation the rights to use, copy, modify, merge, publish,\n\u003e distribute, sublicense, and/or sell copies of the Software, and to\n\u003e permit persons to whom the Software is furnished to do so, subject to\n\u003e the following conditions:\n\u003e\n\u003e The above copyright notice and this permission notice shall be\n\u003e included in all copies or substantial portions of the Software.\n\u003e\n\u003e THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n\u003e EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n\u003e MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n\u003e NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n\u003e LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n\u003e OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n\u003e WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fruuvitag","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterhellberg%2Fruuvitag","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fruuvitag/lists"}