Skip to content

IoT Traffic Lights module built with C# Core running in Docker on Raspberry Pi.

License

Notifications You must be signed in to change notification settings

qbituniverse/iot-trafficlights

Repository files navigation

IoT Traffic Lights

Traffic Lights solution to control traffic lights, setup on the Raspberry Pi GPIO board.

Application Design

IoT Traffic Lights Application

Raspberry Pi Breadboard Wiring

Master source for the breadboard wiring can be found in the IoT.TrafficLights.Breadboard.fzz file. The file also allows to simulate the solution in the Fritzing application.

IoT Traffic Lights Breadboard

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 Domain project containing reusable models, modules and data repositories.
IoT.TrafficLights.Api Api (REST) project used to control the traffic lights module and access traffic lights execution logs.
IoT.TrafficLights.Web Web app project used to control the traffic lights module from a Razor UI HTTP web app client.
IoT.TrafficLights.Console 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 Docker Compose file with the following command. This will deploy all the containers, volumes and networking on the Docker instance.

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.

docker compose -f docker-compose.yaml --env-file vars.env down

The 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

About

IoT Traffic Lights module built with C# Core running in Docker on Raspberry Pi.

Topics

Resources

License

Stars

Watchers

Forks