# Connect the EG800K GPS to the ThingsBoard via MQTT

> Source: https://maker.tdlogy.com/wiki-doc/connect-the-eg800k-gps-to-the-thingsboard-via-mqtt/

This document instructs you to bring the GNSS/GPS location data read from the Quectel EG800K module to the ThingsBoard platform (using the cloud version) via the MQTT protocol, to be displayed directly on the map dashboard (Route Map/Map widget). The document follows the GNSS/GPS section presented earlier — if you don't already know how to read and parse NMEA data from, it's a good idea to read through that section first.quecgnss

## 1. Architectural overview

Module EG800K
   ├─ quecgnss  → đọc và parse tọa độ từ vệ tinh (NMEA)
   ├─ dataCall  → thiết lập kênh dữ liệu 4G để có Internet
   └─ umqtt     → đóng gói tọa độ thành JSON, publish lên broker MQTT của ThingsBoard
                          │
                          ▼
              ThingsBoard Cloud (MQTT Broker, port 1883/8883)
                          │
                          ▼
         Dashboard: widget Map/Route Map hiển thị vị trí theo thời gian thực

In essence, the module acts as an MQTT Client, while ThingsBoard acts as an MQTT Broker. The module only needs to publish (no need to subscribe) telemetry data to the specified topic, ThingsBoard will save itself to the time-series database and re-assign it to the widgets on the dashboard.

## 2. Prepare on ThingsBoard: create a Device and get an Access Token

## 3. MQTT protocol and related APIs

### 3.1. Connection Parameters to ThingsBoard MQTT Broker

ParametersValuesHostBy region, for example mqtt.eu.thingsboard.cloudPort1883 (plain, unencrypted) or (MQTT over TLS)8883UsernameDevice Access TokenPasswordLeave blankClient IDArbitrarily, as long as it does not coincide with other clients that are connecting at the same time (usually use the IMEI module to ensure uniqueness)

### 3.2. Modules on QuecPythonumqtt

MQTTClient(client_id, server, port=0, user=None, password=None, keepalive=0, ssl=False, ssl_params={})

Initialize the MQTT client object (not actually connected to the broker at this step).

ParameterDescriptionclient_idClient identifier, string formserverHost address of the brokerportConnection Port (0 = default according to ssl)user, passwordCredentials—with ThingsBoard Access Token: = token, userpassword = NonesslTrue if using MQTT over TLS (port 8883)

mqtt_client.connect(clean_session=True)

Establish a TCP connection and handshake the MQTT protocol to the declared broker. Return/depending on whether the previous session is saved (the parameter will always start a new session).TrueFalseclean_session=True

mqtt_client.publish(topic, msg, retain=False, qos=0)

Send a message (bytes or string) to the specifier.msgtopic

mqtt_client.disconnect()

Disconnect from the broker, freeing up resources.

### 3.3. Topic and Format of ThingsBoard Telemetry Payload

ThingsBoard prescribes a set of topics for devices connected via MQTT, the most common are:

OperationStandard TopicsShortened Topics (from version 3.5+)Publish telemetryv1/devices/me/telemetryv2/tPublish client attributesv1/devices/me/attributesv2/a

## 4. Processing sequence (logical flow)

## 5. Source code demo

Source: tb_gps.py

## 6. Notes on actual implementation

## References