Skip to content

biyamuslim/decentralized-chat-iot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Decentralized Chat System for IoT

A decentralized chat system leveraging MQTT was built using Go and designed for IoT applications.

Table of Contents


Getting Started

Follow the steps below to set up and run the decentralized chat system.

Prerequisites

  • Latest version of Go installed on your system.
  • SQLite3 installed (for database support).

Installation

  1. Clone the Repository

    git clone https://github.com/yourusername/decentralized-chat-iot.git
    cd decentralized-chat-iot
  2. Initialize Go Modules

    go mod tidy

Configuration

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!"

Running the Application

  1. 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
  2. Build the Project

    go build -o main ./cmd/mqtt-client
  3. 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:

    1. Login
    2. Register
    • Use the Register option to create a client.
    • Repeat the process in other terminals to register more clients.
  4. Chat Across Terminals After registering, you can start writing messages in one terminal. The messages will be broadcast to all other connected terminals.

Usage

  • 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.

Test Cases

Run the following test cases to verify the functionality:

go test -v ./internal/config
go test -v ./internal/mqtt

Contributing

Contributions are welcome! Please fork the repository and submit a pull request for any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages