{"id":22691276,"url":"https://github.com/wisq/ex_co2_mini","last_synced_at":"2025-03-29T16:41:34.692Z","repository":{"id":57500026,"uuid":"170256368","full_name":"wisq/ex_co2_mini","owner":"wisq","description":"Elixir library for reading data from the CO₂Mini USB carbon dioxide sensor","archived":false,"fork":false,"pushed_at":"2019-02-13T03:02:58.000Z","size":48,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-04T23:04:11.810Z","etag":null,"topics":["elixir","monitoring","sensors"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wisq.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}},"created_at":"2019-02-12T05:14:24.000Z","updated_at":"2019-02-13T04:07:52.000Z","dependencies_parsed_at":"2022-08-28T20:01:02.830Z","dependency_job_id":null,"html_url":"https://github.com/wisq/ex_co2_mini","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wisq%2Fex_co2_mini","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wisq%2Fex_co2_mini/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wisq%2Fex_co2_mini/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wisq%2Fex_co2_mini/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wisq","download_url":"https://codeload.github.com/wisq/ex_co2_mini/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246215820,"owners_count":20741894,"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":["elixir","monitoring","sensors"],"created_at":"2024-12-10T01:10:02.009Z","updated_at":"2025-03-29T16:41:34.671Z","avatar_url":"https://github.com/wisq.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ExCO₂Mini\n\nExCO₂Mini is a library to read carbon dioxide and temperature data from the CO₂Mini USB sensor, also known as the RAD-0301.\n\nThis library only reads data from the device.  If you want to record that data somewhere, see e.g. [ddco2](https://github.com/wisq/ddco2) for recording to StatsD.\n\n[![Build Status](https://travis-ci.org/wisq/ex_co2_mini.svg?branch=master)](https://travis-ci.org/wisq/ex_co2_mini)\n[![Hex.pm Version](http://img.shields.io/hexpm/v/ex_co2_mini.svg?style=flat)](https://hex.pm/packages/ex_co2_mini)\n\n## Device setup\n\n**ExCO₂Mini currently only supports Linux.**  Your device needs to show up as a `/dev/hidraw*` device, and it needs to be able to compile a small C utility that uses Linux-specific HID ioctls.\n\nTo allow a regular user to access the device, you can set up a `udev` rule, such as the following:\n\n```udev\nKERNEL==\"hidraw*\", ATTRS{idVendor}==\"04d9\", ATTRS{idProduct}==\"a052\", GROUP=\"co2meter\", MODE=\"0640\", SYMLINK+=\"co2mini\"\n```\n\n(Don't forget to `udevadm control --reload-rules`.)\n\nWhen the device is plugged in, this will set the device's group to `co2meter`, set group read (`g+r`) permissions on it, and create a `/dev/co2mini` symlink to it.  (Write permissions are not required.)\n\nNote that the device will often report abnormally high readings immediately after being plugged in, then settle down to a more reasonable number.\n\n## Installation\n\nExCO₂Mini is [available in Hex](https://hex.pm/packages/ex_co2_mini).\n\nIf you haven't already, start a project with `mix new`.\n\nThen, add `ex_co2_mini` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [\n    {:ex_co2_mini, \"~\u003e 0.1.3\"}\n  ]\nend\n```\n\nRun `mix deps.get` to pull ExCO₂Mini into your project, and you're good to go.\n\n## Usage\n\n```elixir\n# Connect to the device and start reading data:\n{:ok, reader} = ExCO2Mini.Reader.start_link(device: \"/dev/co2mini\")\n# Subscribe to the Reader to start receiving raw data:\nExCO2Mini.Reader.subscribe(reader)\n# Receive messages (do this repeatedly):\nreceive do\n  {^reader, {key, value}} -\u003e Logger.debug(\"received #{key}=#{value}\")\nend\n\n# Attach a Collector to the Reader to get data on demand:\n{:ok, collector} = ExCO2Mini.Collector.start_link(reader: reader)\n# Give it a few seconds to collect data:\nProcess.sleep(5_000)\n# Now you should be able to retrieve CO₂ (parts per million)\n# and temperature (degrees Celsius) data:\nco2 = ExCo2Mini.Collector.co2_ppm(collector)\ntemp = ExCO2Mini.Collector.temperature(collector)\nLogger.info(\"CO₂ = #{co2} ppm, temperature = #{temp} °C\")\n```\n\n### Supervised Usage\n\nIf you want to set up a Reader and a Collector in a Supervisor, you can give them names and tell each to connect to the other.  This will ensure that they continue to communicate even if one or the other is restarted:\n\n```elixir\nchildren = [\n  {ExCO2Mini.Reader,\n   [\n     name: MyApp.Reader,\n     subscribers: [MyApp.Collector],\n     send_from_name: true,\n     device: \"/dev/co2mini\"\n   ]},\n  {ExCO2Mini.Collector,\n   [\n     name: MyApp.Collector,\n     reader: MyApp.Reader,\n     subscribe_as_name: true\n   ]}\n]\n\nSupervisor.start_link(\n  children,\n  strategy: :one_for_one,\n  name: MyApp.Supervisor\n)\n```\n\nUsing `send_from_name` will ensure that the Reader sends messages using its `name` option — i.e. messages will look like `{MyApp.Reader, {key, value}}` — and `subscribe_as_name` will ensure that the Collector subscribes using its own `name` value (so the Reader can track it if it restarts).\n\nSee [ddco2](https://github.com/wisq/ddco2) for an example of this usage.\n\n## Documentation\n\nFull documentation can be found at [https://hexdocs.pm/ex_co2_mini](https://hexdocs.pm/ex_co2_mini).\n\n## Legal stuff\n\nCopyright © 2019, Adrian Irving-Beer.\n\nParts of this code are based on code and data from the [\"Reverse-Engineering a low-cost USB CO₂ monitor\" project](https://hackaday.io/project/5301-reverse-engineering-a-low-cost-usb-co-monitor).  My thanks go out to Henryk Plötz, whose reverse engineering made this project possible.\n\nExCO₂Mini is released under the [Apache 2 License](https://github.com/wisq/ex_co2_mini/blob/master/LICENSE) and is provided with **no warranty**.  This library is aimed at hobbyists and home enthusiasts, and should be used in **non-life-critical situations only**.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwisq%2Fex_co2_mini","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwisq%2Fex_co2_mini","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwisq%2Fex_co2_mini/lists"}