# JT/T 808 Gateway

The JT/T 808 Gateway is a protocol adaptation component designed by EMQX for the Internet of Vehicles (IoV) scenario. It supports vehicle positioning, status monitoring, data exchange, and other functions, widely used for communication between vehicle-mounted terminals and monitoring platforms.

## Basic Settings

Click the **Settings** button in the **Actions** column of the JT/T 808 Gateway to configure its basic settings:

- **MountPoint**: Set a string as the prefix for all topics during publishing or subscribing, providing a method to achieve message routing isolation between different protocols. For example: `jt808/${clientid}/`. This topic prefix is managed by the gateway, so clients do not need to explicitly add this prefix when publishing or subscribing.
- **Max Length of Frame**: The maximum size of frames that the gateway can handle. The default value is `8192`, allowing the gateway to accommodate various packet sizes.
- **Parse Unknown Message IDs**: Whether to parse message IDs that are not defined in the standard protocol.
  - When set to `true`, the gateway processes messages with unknown message IDs and forwards their payload after Base64 encoding. The default value is `true`.
  - When set to `false`, the gateway will ignore the message or disconnect the client, depending on the **Ignore Unsupported Frames** setting.
- **String Encoding**: Specifies the character encoding used by the gateway when parsing strings reported by devices and when packaging and delivering strings to devices.
  - When set to `utf8`, the gateway parses string content using UTF-8 encoding. The default value is `utf8`.
  - When set to `gbk`, the gateway parses strings using GBK encoding and converts them to UTF-8 before publishing messages to EMQX.
- **Retry Interval**: The time interval between retries when message delivery fails. The default value is `8 seconds`.
- **Max Retry Times**: The maximum number of retry attempts the gateway will make when trying to send a message. After this value is exceeded, the message will be discarded if it cannot be sent. The default value is `3`.
- **Max Message Queue Length**: The maximum length of the message queue for downstream messages. The default value is `10`.
- **Idle Timeout**: The duration (in seconds) of client inactivity before it is considered disconnected. The default value is `30 seconds`.
- **Up Topic**: The MQTT topic pattern used for publishing messages from the gateway to the EMQX Cloud. This defines how JT/T 808 client messages are mapped to MQTT topics for uplink communication. The default topic is: `jt808/${clientid}/${phone}/up`.
- **Down Topic**: The MQTT topic pattern used for sending messages from the EMQX Cloud to the gateway and then to the JT/T 808 client. This defines how MQTT messages are routed to the JT/T 808 client for downlink communication. The default topic is: `jt808/${clientid}/${phone}/dn`.
- **Ignore Unsupported Frames**: Determines how the gateway handles JT/T 808 frames that do not conform to the standard protocol.
  - When set to `true`, the gateway logs unsupported frames but continues processing other valid messages, preventing disconnection due to custom or non-standard messages. The default value is `true`.
  - When set to `false`, the gateway disconnects the client when receiving unsupported frames.
- **Allow Anonymous**: This setting determines whether the gateway allows clients to connect without authentication. If set to `true`, clients can connect without providing authentication credentials.

## Clients

In the **Clients** tab of the JT/T 808 page, you can view the basic information of clients connected to the deployment. In the **Actions** column, you can choose to kick a client off.

### Test Connection Using Client Tool

You can use a simulated JT/T 808 protocol gateway client to test the connection by following these steps.

1. Access the JT/T 808 terminal simulator repository: [yedajiang44/GpsTerminalEmulator](https://gitee.com/yedajiang44/GpsTerminalEmulator/tree/master). Follow the instructions in the README file to install and run it using Docker.

   ```bash
   ## Install Docker Compose
   sudo curl -L "https://github.com/docker/compose/releases/download/$(curl -s https://api.github.com/repos/docker/compose/releases/latest | grep tag_name | cut -d '"' -f 4)/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
   sudo chmod +x /usr/local/bin/docker-compose
   
   ## Create directory
   mkdir jt808terminalemulator
   cd jt808terminalemulator
   mkdir data
   
   ## Copy and paste the following into docker-compose.yml
   nano docker-compose.yml
   
   ## Start the service
   sudo docker-compose up -d
   
   ## Check the service status. After startup, use the following command to check the service status:
   sudo docker-compose ps
   
   ## Check logs if any issues arise
   sudo docker-compose logs -f
   ```

   If the following content is returned, the service is running successfully:

   ![simulator_run_success](./_assets/simulator_run_success.png)

2. Access the terminal emulator management page via `server-ip:4000`.

   ![simulator_web_UI](./_assets/simulator_web_UI.png)

3. Follow the provided steps to add vehicle data and route data.

   ![simulator_steps](./_assets/simulator_steps.png)

   When adding task data, fill in the deployment connection address for the server and use port `8090`. Refer to the connection address displayed on the deployment overview page. Click **保存** to start the task by default.

   ![simulator_new_task](./_assets/simulator_new_task.png)

After completing these steps, you can see the connected client in the JT/T 808 gateway's client list.

![simulator_connected](./_assets/simulator_connected.png) You can click on the client ID in the client list to view more detailed information about the client. Clicking the **Kick Out** button will disconnect the client.

## Configure Access Authentication/Authorization

For detailed configuration, refer to [Configure Client Authentication/Authorization](https://docs.emqx.com/en/emqx/latest/gateway/jt808.html#configure-client-authentication-authorization). Users should complete the authentication configuration according to the requirements of the IoV terminal.

## Data Exchange Format

Refer to the EMQX documentation for [JT/T 808 2013 Data Exchange Format](https://docs.emqx.com/en/emqx/latest/gateway/jt808_data_exchange.html).
