Building an Isolated NMEA 2000 Gateway with ESP32
Marine electronics rely on NMEA 2000 (N2K), a standardized protocol built on top of Bosch CAN 2.0B (Controller Area Network) operating at 250 kbps with J1939-based 29-bit identifiers.
In this project, we design an isolated hardware gateway that bridges N2K PGN messages directly into an MQTT stream for vessel dashboards.
Hardware Architecture & Galvanic Isolation
Boats often have multiple battery banks with distinct ground references. Directly connecting an ESP32 to the CAN bus without isolation risks ground loops, alternator noise, and damaged silicon.
[NMEA 2000 Micro-C Bus]
│
[CAN Transceiver: ISO1050] (Galvanic Isolation 5kV)
│
[ESP32-S3 TWAI Controller] (Two-Wire Automotive Interface)
│
[Wi-Fi 802.11 / MQTT Broker]
Parsing Engine Parameters (PGN 127488)
PGN 127488 transmits Rapid Engine Data including engine speed and boost pressure.
#include <Arduino.h>
#include <NMEA2000_CAN.h>
#include <N2kMessages.h>
void HandleEngineData(const tN2kMsg &N2kMsg) {
unsigned char engineInstance;
double engineSpeed;
double engineBoost;
int8_t engineTilt;
if (ParseN2kEngineParamRapid(N2kMsg, engineInstance, engineSpeed, engineBoost, engineTilt)) {
Serial.printf("[Engine #%d] RPM: %.1f | Boost: %.2f kPa\n",
engineInstance,
engineSpeed,
engineBoost / 1000.0);
}
}
Key PGN Reference Table
| PGN | Description | Default Rate | Data Points |
|---|---|---|---|
127250 | Vessel Heading | 10 Hz | Heading, Deviation, Variation |
127488 | Engine Parameters, Rapid Update | 10 Hz | Engine Speed, Boost Pressure |
127489 | Engine Parameters, Dynamic | 2 Hz | Oil Pressure, Temperature, Hours |
129025 | Position, Rapid Update | 10 Hz | Latitude, Longitude |
By packaging these telemetry frames into lightweight JSON payloads over MQTT, we achieve sub-100ms latency on tablet charts and remote vessel telemetry.
Habib Rahman
@habibrahmanFirmware & Embedded Systems Engineer. Exploring bare-metal C, FreeRTOS, Linux kernel, and hardware telemetry.