← Back to all posts 235 words

Building an Isolated NMEA 2000 Gateway with ESP32

•
Habib Rahman
•
2 min read

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

PGNDescriptionDefault RateData Points
127250Vessel Heading10 HzHeading, Deviation, Variation
127488Engine Parameters, Rapid Update10 HzEngine Speed, Boost Pressure
127489Engine Parameters, Dynamic2 HzOil Pressure, Temperature, Hours
129025Position, Rapid Update10 HzLatitude, 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

@habibrahman

Firmware & Embedded Systems Engineer. Exploring bare-metal C, FreeRTOS, Linux kernel, and hardware telemetry.