https://github.com/qbituniverse/iot-trafficlights
IoT Traffic Lights module built with C# Core running in Docker on Raspberry Pi.
https://github.com/qbituniverse/iot-trafficlights
docker iot netcore raspberry-pi
Last synced: 5 months ago
JSON representation
IoT Traffic Lights module built with C# Core running in Docker on Raspberry Pi.
- Host: GitHub
- URL: https://github.com/qbituniverse/iot-trafficlights
- Owner: qbituniverse
- License: mit
- Created: 2024-09-04T06:22:44.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-10-09T13:55:14.000Z (over 1 year ago)
- Last Synced: 2025-04-12T14:22:27.059Z (about 1 year ago)
- Topics: docker, iot, netcore, raspberry-pi
- Language: C#
- Homepage:
- Size: 1.35 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# IoT Traffic Lights
Traffic Lights solution to control traffic lights, setup on the Raspberry Pi GPIO board.
## Application Design

## Raspberry Pi Breadboard Wiring
Master source for the breadboard wiring can be found in the [IoT.TrafficLights.Breadboard.fzz](/.docs/IoT.TrafficLights.Breadboard.fzz) file. The file also allows to simulate the solution in the [Fritzing](https://fritzing.org/) application.

## Hardware Specification
|Component|Description|
|-----|-----|
|Raspberry Pi|Raspberry Pi 4 Model B Rev 1.5, 4GB RAM
Linux 6.1.0-rpi4-rpi-v8
Debian GNU/Linux 12 (bookworm)
arm64 architecture|
|Breadboard and wiring|1x 830 hole breadboard and 10x standard wires|
|LEDs|2x Green LEDs
2x Red LEDs
1x Amber LED|
|Resistors|5x 330 Ohm|
|Motion Sensor|1x HC-SR501 type motion sensor|
## Projects
|Name|Description|
|-----|-----|
|[IoT.TrafficLights.Domain](/.docs/IoT.TrafficLights.Domain.md)|Domain project containing reusable models, modules and data repositories.|
|[IoT.TrafficLights.Api](/.docs/IoT.TrafficLights.Api.md)|Api (REST) project used to control the traffic lights module and access traffic lights execution logs.|
|[IoT.TrafficLights.Web](/.docs/IoT.TrafficLights.Web.md)|Web app project used to control the traffic lights module from a Razor UI HTTP web app client.|
|[IoT.TrafficLights.Console](/.docs/IoT.TrafficLights.Console.md)|Console app used to run traffic lights module or traffic sensor module.|
## Deployment
The easiest way to deploy the IoT Traffic Lights application is to run the [docker-compose.yaml](/.cicd/compose/docker-compose.yaml) Docker Compose file with the following command. This will deploy all the containers, volumes and networking on the Docker instance.
```bash
docker compose -f docker-compose.yaml --env-file vars.env up -d
```
To remove the IoT Traffic Lights application from Docker instance, use this command. This will remove all the containers, volumes and networking from Docker instance.
```bash
docker compose -f docker-compose.yaml --env-file vars.env down
```
The [vars.env](/.cicd/compose/vars.env) file provides all the environment specific configuration for the application. Use this table below as guide to configure the deployment.
|Key|Values|Description|
|-----|-----|-----|
|ENVIRONMENT|Development, Test, Production|Defines the release environment.|
|COMPOSE_PROJECT_NAME|dev-iot-trafficlights, test-iot-trafficlights, prod-iot-trafficlights|This is used to prefix resources and set environmental boundaries for the application components. It allows to run Dev, Test and Prod simultaneously on the same Docker instance at the same time and not clash with each other.|
|COMPOSE_PROFILES|Mock, SQLite, MySql, MongoDb|Defines which application components are created and used as backend data storage, i.e. SQLite, or MySql or MongoDb database or Mock in-memory only hard-coded data samples.|
|DB_DIR_SQLITE|C:\Path\SQLite or /home/path/sqlite|SQLite database folder location where the database artifacts are stored.|
|DB_PORT_SQLITE|30xx, ex. 3017|Port number to access SQLite database.|
|DB_DIR_MYSQL|C:\Path\MySql or /home/path/mysql|MySql database folder location where the database artifacts are stored.|
|DB_PORT_MYSQL|33xx, ex. 3317|Port number to access MySql database.|
|DB_DIR_MONGODB|C:\Path\MongoDb or /home/path/mongodb|MongoDb database folder location where the database artifacts are stored.|
|DB_PORT_MONGODB|270xx, ex. 27017|Port number to access MongoDb database.|
|DB_PWD|Password|Password to access the database, only applicable to MySql _root_ user.|
|API_PORT|80xx, ex. 8011|Port to access the Api.|
|WEB_PORT|80xx, ex. 8014|Port to access the Web app.|
|LOGLEVEL_CONSOLE|Verbose, Debug, Information, Warning, Error, Fatal|Log levels for the console output.|
|LOGLEVEL_DATABASE|Verbose, Debug, Information, Warning, Error, Fatal|Log levels to log in the Database.|
|GPIO|Mock, Pi|Define if the application is wired to Raspberry Pi or just in a Mock mode.|
|RUN|RunMock, RunTrafficSensor, RunTrafficTimer|Program to run in the Console app.|
## Modules
### TrafficControl
Use to control the traffic and pedestrian lights pattern, turning different light modes through GPIO pins.
|LED Light|GPIO Pin|
|-----|-----|
|Traffic Red|26|
|Traffic Amber|19|
|Traffic Green|13|
|Pedestrian Red|27|
|Pedestrian Green|17|
|Type|Description|
|-----|-----|
|Mock|Module is controlled through mock calls, no Pi required.|
|Pi|Module is executing GPIO commands on the Pi. Raspberry Pi is required for this.|
|Api|Module calls through HTTP layer to the _IoT.TrafficLights.Api_.
Refer to _IoT.TrafficLights.Api_ configuration and ports below.
Sample URL: _http://localhost:8011_|
### TrafficSensor
Use to control the motion detection sensor, turning on or off sensor mode through GPIO pins.
|Sensor|GPIO Pin|
|-----|-----|
|Sensor On|21|
|Type|Description|
|-----|-----|
|Mock|Module is controlled through mock calls, no Pi required.|
|Pi|Module is executing GPIO commands on the Pi. Raspberry Pi is required for this.|
## Repository
Backend database details, used across all projects in the IoT TrafficLights solution.
|Object|Name|Description|
|-----|-----|-----|
|**Database**|IotTrafficLights|Main database name for the IoT TrafficLights solution.|
|**Tables**|ApiLogs|Store the API execution logs.|
||WebLogs|Store the Web App execution logs.|
||ConsoleLogs|Store the Console execution logs.|
||TrafficLogs|Store Traffic Lights execution logs.|
### Configuration
|Name|Description|
|-----|-----|
|Mock|Defaults to *empty string ("")*. Hard coded in-memory, stateless, mock calls to sample data set, no data persistance.
Connection string is not required.|
|SQLite|SQLite backed database that is stored on a host machine file system as _.db_ file.
Communication with the database through a file system.
Default SQLite deployment doesn't configure any user credentials and can be accessed without such permissions.
_NOTE: Works on AMD and ARM architectures_.|
|SQLite.Url|PATH_TO_DATABASE\DATABASE_NAME.db|
|MySql|MySql backed database that can run either in Docker container or as standalone installation on the machine.
Communication with the database is on port _33xx_ over the network (IP Address) or localhost (127.0.0.1).
Use the default _root_ account and password of your choice that is configured during MySql database deployment.
_NOTE: Works on AMD and ARM architectures_.|
|MySql.Url|Server=127.0.0.1;Port=33xx;User ID=root;Password=YOUR_PASSWORD;Database=DATABASE_NAME|
|MongoDb|MongoDb backed database that can run either in Docker container or as standalone installation on the machine.
Communication with the database is on port _270xx_ over the network (IP Address) or localhost (127.0.0.1).
Default MongoDb deployment doesn't configure any user credentials and can be accessed without such permissions.
_NOTE: Works on AMD and ARM architectures (Pi 5 or higher)_.|
|MongoDb.Url|mongodb://localhost:270xx|