JT/T808 Protocol Gateway

Protocol Introduction

emqx-jt808 As emqx’s access gateway, according to its functional logic and the relationship between the entire system, the entire message exchange process can be divided into three parts: terminal side, platform side and other sides:

  1. |<-- Terminal -->|<---------- Broker Side ---------->|<--- Others --->|
  2. |<- Side ->| |<-- Side -->|
  3. +---+ PUB +-----------+
  4. | D | INCOMING +------------+ PUB +---------+ -->| subscriber|
  5. | E |----------->| |----------->| |--/ +-----------+
  6. | V | | emqx-jt808 | | EMQX |
  7. | I |<-----------| |<-----------| |<-- +-----------+
  8. | C | OUTGOING +------------+ PUB +---------+ \--| publisher |
  9. | E | PUB +-----------+
  10. +---+
  1. Terminal side: exchange data through the JT/T 808 protocol to report different types of data, or send downlink messages to the terminal.
  2. Platform side: emqx-jt808 decodes the message and performs registration/authentication, or PUBLISH the data message to a specific topic; the agent subscribes to the downstream topic, and converts the downstream PUBLISH message into a JT/T 808 protocol message The text structure is delivered to the terminal.
  3. The other side can subscribe to the topic of the upstream PUBLISH message appearing in 2 to receive the upstream message. Or to publish a message to a specific downlink topic to send data to the terminal side.

Create module

Open EMQX DashboardJT/T808 gateway - 图1 (opens new window), click the “Modules” tab on the left, and choose to add:

image-20200927213049265

Select JT/T808 protocol to access the gateway:

image-20200927213049265

Configure related basic parameters:

image-20200927213049265

Add listening port:

image-20200927213049265

Configure monitoring parameters:

image-20200927213049265

Click to confirm to the configuration parameter page:

image-20200927213049265

After clicking Add, the module is added: image-20200927213049265

emqx-jt808 implementation regulations:

-In the system, the mobile phone number is used as the unique identification of a connection, namely ClientId

Configuration parameters

The implementation of emqx-jt808 supports anonymous access authentication:

ConfigurationDescription
Allow anonymousWhether to allow anonymous user login
Registray URLJT/T808 terminal registered HTTP interface address
Authentication URLJT/T808 terminal access authentication HTTP interface address
Downlink Message TopicUpstream topic. Uplink message to the message topic in the EMQX system%c: ClientId of the connected client, %p: Phone
Uplink Message TopicDownstream topic. Uplink message to the message topic in the EMQX system%c: ClientId of the connected client, %p: Phone
Max Frame LengthMaximum processing size of a single JT/T808 protocol message

Registration and authentication

The detailed format of the registration request is as follows:

Registration request:

  1. URL: http://127.0.0.1:8991/jt808/registry
  2. Method: POST
  3. Body:
  4. {"province": 58,
  5. "city": 59,
  6. "manufacturer": "Infinity",
  7. "model": "Q2",
  8. "license_number": "ZA334455",
  9. "dev_id": "xx11344",
  10. "color": 3,
  11. "phone", "00123456789"
  12. }

Registration Response:

  1. {
  2. "code": 0,
  3. "authcode": "132456789"
  4. }
  5. or:
  6. {
  7. "code": 1
  8. }
  9. The return code can be:
  10. 0: success
  11. 1: The vehicle has been registered
  12. 2: The vehicle is not in the database
  13. 3: The terminal has been registered
  14. 4: There is no such terminal in the database

Authentication request:

  1. URL: http://127.0.0.1:8991/jt808/auth
  2. Method: POST
  3. Body:
  4. {"code": "authcode",
  5. "phone", "00123456789"
  6. }

Authentication response:

  1. HTTP status code 200: authentication succeeded
  2. Other: Authentication failed

Tip

The authentication request is only called when the system does not save the authentication code (that is, the terminal directly sends an authentication message to log in to the system)

In emqx-jt808, you can send and receive terminal messages by configuring uplink and downlink topics:

Upward

For example: Manufacturer Id is ʻabcdeand **Terminal Id** is1234567`.

First use the MQTT client to subscribe to the topic jt808/abcde1234567/up:

  1. $ mosquitto_sub -t jt808/abcde1234567/up

For example, after the terminal reports a message of type Data Uplink Transparent Transmission (0x0900), the subscriber will receive:

  1. {"body":
  2. {"data":"MTIzNDU2",
  3. "type":240
  4. },
  5. "header":
  6. {"encrypt":0,
  7. "len":7,
  8. "msg_id":2304,
  9. "msg_sn":4,
  10. "phone":"011111111111"
  11. }
  12. }

Tip

For transparent transmission, the content of the data field will be base64 encoded and reported once

Similarly, take the ID in the above row as an example; after the terminal is successfully authenticated, use the MQTT client to send a message of the type’data downlink transparent transmission (0x8900)’ to the terminal:

  1. $ mosquitto_pub -t jt808/abcde1234567/dn -m'{"body":{"data":"MTIzNDU2","type":240},"header":{"msg_id":35072}}'

Tip

In the downstream JSON, the content in the header only needs to have msg_id; the content in the body has different structures according to different msg_id