Commit a04d7a99 authored by Phat Nguyen's avatar Phat Nguyen

Add documentation

parent 1e8a0356
# Smart Locker API - Setup and Deployment
This comprehensive guide covers everything you need to set up, build, deploy, publish, and run the Smart Locker API project on localhost and IIS, including the necessary packages for .NET hosting and drivers for IoT machine interaction.
## Prerequisites
- [.NET 6 SDK](https://dotnet.microsoft.com/download/dotnet/6.0) installed on your machine
- Visual Studio 2022 or later (optional but recommended)
- SQLite installed for database management
- IIS (Internet Information Services) installed and configured on your machine for deployment
- [.NET Core Hosting Bundle](https://dotnet.microsoft.com/download/dotnet/thank-you/runtime-aspnetcore-6.0.0-windows-hosting-bundle-installer) for hosting .NET applications on IIS
- [Drivers](/assets/Win32-2.zip) for interacting with IoT machines (ensure you have the correct drivers for your specific IoT hardware)
## Project Structure
- **Logging**: Configuration for logging levels.
- **ConnectionStrings**: Database connection string.
- **AppSettings**: Application-specific settings such as JWT secret, email configuration, and COM port.
- **HostURLConfig**: Configuration for the host URL.
- **AccountConnects**: Client ID and secret key for account connections.
- **COMPort**: Configuration for the COM port used to communicate with IoT devices.
## Setup Instructions
### 1. Clone the Repository
```bash
git clone <repository-url>
cd <repository-directory>
```
### 2. Install .NET 6 SDK
Download and install the .NET 6 SDK from the official Microsoft .NET website.
### 3. Install SQLite
Follow the installation instructions on the SQLite website.
### 4. Restore NuGet Packages
Navigate to the project directory and restore the required NuGet packages.
bash
dotnet restore
### 5. Configure appsettings.json
Update the appsettings.json file with your specific settings, particularly the JWT secret, email configuration, database connection string, and COM port.
```json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"ConnectionStrings": {
"DefaultConnection": "Data source=smartLocker.db"
},
"AppSettings": {
"Secret": "YOUR_SECRET_KEY",
"JWTTime": "5",
"EnableSwagger": true,
"EmailFrom": "info@mandai-verification-api.com",
"SmtpHost": "smtp.gmail.com",
"SmtpPort": 587,
"SmtpUser": "your-email@gmail.com",
"SmtpPass": "your-email-password"
},
"AllowedHosts": "*",
"HostURLConfig": {
"HostURL": [
"http://*:1111"
]
},
"AccountConnects": [
{
"client_id": "your-client-id",
"secret_key": "your-secret-key"
}
],
"COMPort": "COM1"
}
```
## Install IoT Drivers
Ensure you have the correct drivers installed for your IoT hardware. Follow the manufacturer's instructions for installation.
- Download in [```bash assets/Win32-2.zip```](assets/Win32-2.zip)
- Copy the file ```Win32```to directory `C:\`
- Run script : ``install.bat``
## Build and Run Locally
### 1. Build the Project
Run the following command to build the project:
``dotnet build .\sl.NETAPIs_Hardware\``
### 2. Run the Project
Run the following command to start the project:
`` dotnet run --project .\sl.NETAPIs_Hardware\ ``
The API will be available at <http://localhost:1111> by default.
## Publish the Project
### 1. Publish for Localhost
Run the following command to publish the project:
`` dotnet publish -c Release -o ./publish ``
This will create a publish directory with all the necessary files to run the application.
### 2. Deploy to IIS
#### Install IIS and ASP.NET Core Hosting Bundle
Open Server Manager and select Add roles and features.
Select the Web Server (IIS) role.
Download and install the ASP.NET Core Hosting Bundle.
#### Configure IIS
Open IIS Manager.
Add a new website:
Site name: SmartLockerAPI
Physical path: <path-to-publish-folder>
Host name: localhost or any custom domain
Bind the website to the appropriate port (e.g., http://*:1111 as per HostURLConfig).
#### Set Application Pool
Select the application pool associated with your website.
Set the .NET CLR version to No Managed Code.
### 3. Set Up Database
Ensure the SQLite database is correctly set up and accessible. If the database file (smartLocker.db) doesn't exist, the application should create it on the first run.
Configure IoT Machine Interaction
Ensure your application can communicate with the IoT machines by properly configuring the COM port settings in appsettings.json.
```json
{
"COMPort": "COM1"
}
```
#### Run the API on IIS
- Start the IIS server.
- Navigate to the URL configured (e.g., <http://localhost:1111>).
## Email Configuration
Ensure the SMTP settings in appsettings.json are correctly configured for email functionality.
```json
"AppSettings": {
"EmailFrom": "<info@mandai-verification-api.com>",
"SmtpHost": "smtp.gmail.com",
"SmtpPort": 587,
"SmtpUser": "<your-email@gmail.com>",
"SmtpPass": "your-email-password"
}
```
## Enable Swagger
If EnableSwagger is set to true in appsettings.json, you can access the Swagger UI for API documentation at <http://localhost>:<port>/swagger.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment