{"id":39509964,"url":"https://github.com/codingforentrepreneurs/django-iot-with-timescaledb","last_synced_at":"2026-01-18T06:01:07.384Z","repository":{"id":247462459,"uuid":"825915245","full_name":"codingforentrepreneurs/django-iot-with-timescaledb","owner":"codingforentrepreneurs","description":"Learn how to distribute Django across IoT Devices (Raspberry PI) to collect Time Series data from sensors using TimescaleDB.","archived":false,"fork":false,"pushed_at":"2024-07-09T22:51:09.000Z","size":46,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-07-11T00:24:57.714Z","etag":null,"topics":["ansible","django","docker-compose","iot","raspberry-pi","sensors","timescaledb"],"latest_commit_sha":null,"homepage":"","language":"Python","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/codingforentrepreneurs.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-07-08T18:43:12.000Z","updated_at":"2024-07-10T14:42:20.000Z","dependencies_parsed_at":"2024-07-08T23:34:41.878Z","dependency_job_id":"483f09ba-87ac-4c2b-b02b-940a3037e885","html_url":"https://github.com/codingforentrepreneurs/django-iot-with-timescaledb","commit_stats":null,"previous_names":["codingforentrepreneurs/django-iot-with-timescaledb"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/codingforentrepreneurs/django-iot-with-timescaledb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingforentrepreneurs%2Fdjango-iot-with-timescaledb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingforentrepreneurs%2Fdjango-iot-with-timescaledb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingforentrepreneurs%2Fdjango-iot-with-timescaledb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingforentrepreneurs%2Fdjango-iot-with-timescaledb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/codingforentrepreneurs","download_url":"https://codeload.github.com/codingforentrepreneurs/django-iot-with-timescaledb/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/codingforentrepreneurs%2Fdjango-iot-with-timescaledb/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28531991,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-18T00:39:45.795Z","status":"online","status_checked_at":"2026-01-18T02:00:07.578Z","response_time":98,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["ansible","django","docker-compose","iot","raspberry-pi","sensors","timescaledb"],"created_at":"2026-01-18T06:01:06.835Z","updated_at":"2026-01-18T06:01:07.353Z","avatar_url":"https://github.com/codingforentrepreneurs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Django IoT with TimescaleDB\n\nLearn how to distribute Django across IoT Devices (Raspberry PI) to collect Time Series data from sensors using TimescaleDB.\n\n\n\n## Getting Started with Ansible, Raspberry Pis, Django, and TimescaleDB\n\nAnsible will help automate the configuration for however many Raspberry Pis you have.\n\nGoing forward, each Raspberry Pi will be configured with the root user as `cfe` and each Pi will have a unique hostname with the pattern:\n\n- `djangopi`\n- `djangopi-2`\n- `djangopi-3`\n- etc\n\nTo access these pis on your local network, you can use:\n\n```bash\nssh cfe@djangopi.local\n```\n\nThis configuration is done when you flash (aka install) the Raspberry Pi on a new MicroSD card with the [Raspberry Pi Imager](https://www.raspberrypi.com/software/). The OS used will be dependant on your Raspberry Pi version. For this guide, sed the headless os called _Raspberry Pi Lite (64-bit)_ with custom settings to automatically:\n\n- set hostname (`djangopi`, etc)\n- set root user (`cfe`)\n- connect to my local wifi\n- install my SSH public key (`~/.ssh/id_rsa.pub`) for passwordless SSH sessions (very useful for Ansible)\n\n### 1. Clone this repo\n\n```bash\nmkdir -p django-iot\ncd django-iot\ngit clone https://github.com/codingforentrepreneurs/django-iot-with-timescaledb .\n```\n\n### 2. Create virtual environment and install dev packages\n\n_mac/linux/wsl_\n```bash\npython3 -m venv venv\nsource venv/bin/activate\n```\n\n_windows powershell_ \n```powershell\nc:\\path\\to\\python.exe -m venv venv\n.\\venv\\Scripts\\activate\n```\n\nWith virtual environment activated:\n```bash\npip install --upgrade pip\npip install -r requirements.dev.txt\npip install -r requirements.txt\n```\n\n\n### 3. Create `.env.prod` for encrypted environment variables\n\n```bash\ncp .env.web-sample .env.prod\n```\n\nEnsure `.env.prod` resembles:\n```bash\nDJANGO_SECRET_KEY=\"django-insecure-ajq-plfh\u00264uh6rea1zliteu+bszy57v*g%t0t^j2i^6)w%t\"\nDATABASE_URL=\"postgresql://local_username:local_password@localhost:5555/local_database\"\nCELERY_BROKER_REDIS_URL=\"redis://localhost:6555/0\"\n```\n\n### 4. Create a new TimescaleDB Cloud service:\n\n1. Sign up on [timescaledb](https://www.timescale.com/?utm_source=cfe-github\u0026utm_medium=cfe-repo) to get your production-ready `DATABASE_URL`\n\n2. Under \"Services\" click \"+ Create Service\"\n3. Select `Time Series and Analytics` as your service type\n4. For the configuration:\n    - the `Region` so it's near you (e.g. `us-east-1` if you are in New York)\n    - `Service name` set it to `django-iot` \n    - all other defaults are fine.\n5. Copy the connection string (also known as `Service URL`); this will show the password once in the format: `postgres://tsdbadmin:your-password@yourunique.host-val.tsdb.cloud.timescale.com:37802/tsdb?sslmode=require`\n \n### 5. Encrypt `.env.prod`\nNext, run:\n```bash\nansible-vault encrypt .env.prod\n```\nCreate a password you will remember. To decrypt, you can run `ansible-vault decrypt .env.prod`.\n\nThis will ensure your `.env` file does not leak any secrets or passwords.\n\n### 6. Create or update `inventory.ini` in `ansible/`\n\nCheck the current inventory file:\n```bash\ncat ansible/inventory.ini\n```\n\nIn the repo, it yields:\n```ini\n[main]\ndjangopi.local node_id=1\n\n[nodes]\ndjangopi-2.local node_id=2\ndjangopi-3.local node_id=3\n# djangopi-4.local node_id=4\n# djangopi-5.local node_id=5\n\n[all:vars]\nansible_user=cfe\n```\nUpdate the amount of nodes as needed.\n\n### 7. Run Connect Hosts \n\n```bash\ncd ansible\nansible-playbook playbooks/connect_hosts.yaml\n```\nThis will make pi-to-pi communication possible. Run this each time you add a new node to the cluster (e.g. a new pi to collect data)\n\n### 8. Push to Prod\n\nFrom within the `ansible/` directory, run:\n\n```bash\nansible-playbook playbooks/deploy_django.yaml\n```\nBy default, this will install the code from [this repo](https://github.com/codingforentrepreneurs/django-iot-with-timescaledb). If you want to use your own repo, open up `playbooks/deploy_django.yaml` and replace `https://github.com/codingforentrepreneurs/django-iot-with-timescaledb` in the `vars.github_repo:` configuration with your value.\n\nAfter you push run:\n\n```bash\nansible-playbook playbooks/restart_services.yaml\n```\n\n\n## 9. Refresh Services\n\n\n```bash\nansible-playbook playbooks/connect_hosts.yaml\n\n\nansible-playbook playbooks/deploy_django.yaml\n\n\nansible-playbook playbooks/restart_services.yaml\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingforentrepreneurs%2Fdjango-iot-with-timescaledb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodingforentrepreneurs%2Fdjango-iot-with-timescaledb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodingforentrepreneurs%2Fdjango-iot-with-timescaledb/lists"}