A decentralized chat system leveraging MQTT was built using Go and designed for IoT applications.
- Getting Started
- Prerequisites
- Installation
- Configuration
- Running the Application
- Usage
- Test Cases
- Contributing
- License
Follow the steps below to set up and run the decentralized chat system.
- Latest version of Go installed on your system.
- SQLite3 installed (for database support).
-
Clone the Repository
git clone https://github.com/yourusername/decentralized-chat-iot.git cd decentralized-chat-iot
-
Initialize Go Modules
go mod tidy
Create a .env
file in the root directory and add the following keys:
DATABASE_PATH=./YourDBName.db
MIGRATION_PATH=./migrations
ENCRYPTION_KEY="your-32-byte-secret-key-for-aes!"
-
Run Migrations
Install
goose
for database migrations:go install github.com/pressly/goose/v3/cmd/goose@latest
Run migrations using the following command:
goose -dir=migrations sqlite3 ./app.db up
-
Build the Project
go build -o main ./cmd/mqtt-client
-
Run the Application
Open multiple terminal instances and run the following command in each terminal:
go run ./cmd/mqtt-client
Upon running, you will see two options:
- Login
- Register
- Use the Register option to create a client.
- Repeat the process in other terminals to register more clients.
-
Chat Across Terminals After registering, you can start writing messages in one terminal. The messages will be broadcast to all other connected terminals.
- Register a Client: Each terminal represents a client. Register using the "Register" option.
- Login: Use the login option to reconnect an existing client.
- Broadcast Messages: Any message sent from one terminal will appear in all other terminals.
Run the following test cases to verify the functionality:
go test -v ./internal/config
go test -v ./internal/mqtt
Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.
This project is licensed under the MIT License. See the LICENSE file for details.