Back to engineering archive

Record 083 / Connected systems

Cellular and Wi-Fi MQTT gateway

A gateway linking local data with MQTT over cellular or Wi-Fi communication. Documented routines include connection management and state of charge publication.

Firmware development
MQTTWi-FiCellular communicationESP32

Firmware flow

How state-of-charge data falls back to cellular

Complete state-of-charge publication selector.

Use Wi-Fi when it is enabled and connected. If that publication succeeds, stop; otherwise call the cellular publication routine.

The excerpt attempts cellular publication after unavailable or unsuccessful Wi-Fi. It does not show cellular success checking, retries or guaranteed delivery.

Read the implementation

publication fallback excerpt · selected source lines 297–307. Source inspection is not a hardware test.

void sendSOC(int soc) {
  bool sent=false;

  if (wifiEnabled && wifiConnected) {
    sent = publishSOC_WLAN(soc);
    if (sent) return;
    Serial.println("⚠️ WLAN failed → LTE fallback");
  }

  mqttPublishSOC_LTE(soc);
}
Open the exact source-level diagram
Action · YesTry publishing over Wi-Fi
Result · YesFinish this publication request
Result · NoAttempt publication over cellular

Technical notes

State-of-charge input

readSOC() identifies state of charge as a data input for the gateway’s reporting task.

Wi-Fi and MQTT connections

wifiConnectOnce() and wifiMqttEnsureConnected() separate the Wi-Fi connection from the MQTT connection. These are distinct stages between having local data and making it available to a remote subscriber.

MQTT publication

wifiPublishSOC() names the publication step explicitly. The overall gateway scope considers cellular and Wi-Fi connectivity, while the Wi-Fi routines show the progression from network access to application-level reporting.

Engineering archiveArchive record

Project enquiries

Discuss your project.

Tell us what you’re developing and where you need engineering support.

Discuss your project