{"id":21838570,"url":"https://github.com/lilanga/rainbow-hat-sensor-service","last_synced_at":"2026-04-12T21:40:57.730Z","repository":{"id":244049349,"uuid":"814148437","full_name":"Lilanga/rainbow-hat-sensor-service","owner":"Lilanga","description":"Use Raspberry Pi with Balena to read weather sensor readings from a Rainbow Hat.","archived":false,"fork":false,"pushed_at":"2024-06-14T11:56:02.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-21T15:18:57.865Z","etag":null,"topics":["balenacloud","balenaos","iot","rainbowhat","raspberry-pi"],"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/Lilanga.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":"2024-06-12T12:37:32.000Z","updated_at":"2024-06-12T12:53:25.000Z","dependencies_parsed_at":"2024-06-12T16:53:19.095Z","dependency_job_id":"093f252d-f19d-40bd-97cd-8e9d8faaf2a0","html_url":"https://github.com/Lilanga/rainbow-hat-sensor-service","commit_stats":null,"previous_names":["lilanga/rainbow-hat-sensor-service"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Lilanga/rainbow-hat-sensor-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lilanga%2Frainbow-hat-sensor-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lilanga%2Frainbow-hat-sensor-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lilanga%2Frainbow-hat-sensor-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lilanga%2Frainbow-hat-sensor-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Lilanga","download_url":"https://codeload.github.com/Lilanga/rainbow-hat-sensor-service/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Lilanga%2Frainbow-hat-sensor-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31731413,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-12T13:21:33.774Z","status":"ssl_error","status_checked_at":"2026-04-12T13:21:29.265Z","response_time":58,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["balenacloud","balenaos","iot","rainbowhat","raspberry-pi"],"created_at":"2024-11-27T21:12:21.702Z","updated_at":"2026-04-12T21:40:57.715Z","avatar_url":"https://github.com/Lilanga.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rainbow HAT with Raspberry Pi on BalenaOS\r\n\r\nThis repository contains a Go application for reading sensor data from the Rainbow HAT on a Raspberry Pi running BalenaOS. The application reads temperature, humidity, and pressure data, and publishes it via MQTT while also serving a simple web page to display the current sensor data.\r\n\r\n## Table of Contents\r\n\r\n- [Requirements](#requirements)\r\n- [Installation](#installation)\r\n- [Configuration](#configuration)\r\n- [Running the Application](#running-the-application)\r\n- [Accessing the Web Server via Balena Public URL](#accessing-the-web-server-via-balena-public-url)\r\n- [Endpoints](#endpoints)\r\n- [Shutdown](#shutdown)\r\n- [License](#license)\r\n\r\n## Requirements\r\n\r\n- Raspberry Pi with BalenaOS\r\n- Rainbow HAT\r\n- Go 1.18+\r\n- MQTT broker\r\n- `.env` file with necessary configurations\r\n- Docker\r\n\r\n## Installation\r\n\r\n1. **Clone the repository:**\r\n\r\n    ```sh\r\n    git clone https://github.com/yourusername/rainbowhat-sensor-reader.git\r\n    cd rainbowhat-sensor-reader\r\n    ```\r\n\r\n2. **Ensure you have Go installed:**\r\n\r\n    Follow the instructions on the [official Go website](https://golang.org/doc/install) to install Go.\r\n\r\n3. **Install dependencies:**\r\n\r\n    This project uses a `go.mod` file to manage dependencies. Ensure you are in the project directory and run:\r\n\r\n    ```sh\r\n    go mod tidy\r\n    ```\r\n\r\n4. **Create a `.env` file:**\r\n\r\n    ```sh\r\n    touch .env\r\n    ```\r\n\r\n    Populate the `.env` file with the following variables:\r\n\r\n    ```env\r\n    ID=RBH01\r\n    MQTT_HOST=tls://[xyz......tyu].s1.eu.hivemq.cloud\r\n    MQTT_PORT=8883\r\n    MQTT_USER=test\r\n    MQTT_PASS=test\r\n    MQTT_CLIENT_ID=test\r\n    MQTT_TOPIC=rainbowhat/weather\r\n    PORT=:80\r\n    REFRESH_INTERVAL=60\r\n    ```\r\n\r\n## Configuration\r\n\r\n- `ID`: A unique ID for your sensor.\r\n- `MQTT_HOST`: The host URL of your MQTT broker.\r\n- `MQTT_PORT`: The port number for your MQTT broker.\r\n- `MQTT_USER`: The username for your MQTT broker.\r\n- `MQTT_PASS`: The password for your MQTT broker.\r\n- `MQTT_CLIENT_ID`: Your MQTT client ID (can be left empty if not needed).\r\n- `MQTT_TOPIC`: The MQTT topic to publish sensor data to.\r\n- `PORT`: The port on which the web server will run (e.g., `:80`).\r\n- `REFRESH_INTERVAL`: The interval (in seconds) at which sensor data is read and published.\r\n\r\n## Running the Application\r\n\r\n### Using Balena to Run on Raspberry Pi\r\n\r\n1. **Install Balena CLI:**\r\n\r\n    Follow the instructions on the [official Balena CLI documentation](https://www.balena.io/docs/reference/cli/#installation) to install the Balena CLI.\r\n\r\n2. **Log in to Balena:**\r\n\r\n    ```sh\r\n    balena login\r\n    ```\r\n\r\n3. **Initialize the project:**\r\n\r\n    ```sh\r\n    balena push \u003cyour-app-name\u003e\r\n    ```\r\n\r\n    Replace `\u003cyour-app-name\u003e` with the name of your Balena application. This command will build and deploy the application to your Raspberry Pi.\r\n    You need to have a Balena application set up with a Raspberry Pi device before running this command to deploy the application.\r\n\r\n### Running Locally\r\n\r\n1. **Build and run the application using Docker:**\r\n\r\n    Make sure Docker is installed and running on your machine. Then, from the project directory, run:\r\n\r\n    ```sh\r\n    docker build -t rainbow-hat-sensor-service .\r\n    docker run --env-file .env -p 8080:8080 rainbow-hat-sensor-service\r\n    ```\r\n\r\n## Accessing the Web Server via Balena Public URL\r\n\r\n1. **Enable Public URL:**\r\n\r\n    Go to the Balena dashboard, select your application, and enable the Public Device URL for your device. This will provide you with a URL through which you can access your web server.\r\n\r\n2. **Configure Environment Variables:**\r\n\r\n    Set the `PORT` environment variable to `80` in your Balena application configuration. This ensures that the web server listens on the correct port for the Balena public URL.\r\n\r\n    ```env\r\n    PORT=:80\r\n    ```\r\n\r\n3. **Access the Web Server:**\r\n\r\n    Once the application is running, you can access the web server using the public URL provided by Balena.\r\n\r\n## Endpoints\r\n\r\n- **Root Endpoint (`/`)**: Serves an HTML page displaying the current sensor data.\r\n- **Data Endpoint (`/data`)**: Serves the current sensor data in JSON format.\r\n\r\n## Shutdown\r\n\r\nThe application is designed to handle graceful shutdown upon receiving an interrupt signal (e.g., `Ctrl+C` or a termination signal).\r\n\r\n## License\r\n\r\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flilanga%2Frainbow-hat-sensor-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flilanga%2Frainbow-hat-sensor-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flilanga%2Frainbow-hat-sensor-service/lists"}