Skip to content

File network.h

Location: include/network.h

Includes

graph LR
1["include/network.h"]
click 1 "network_8h.md#network_8h"
1 --> 2

2["platform.h"]
click 2 "platform_8h.md#platform_8h"
2 --> 3
2 --> 4
2 --> 5
2 --> 6
2 --> 7
2 --> 8
2 --> 9

7["Adafruit_ADT7410.h"]

3["Arduino.h"]

8["ArduinoJson.h"]

9["ArduinoMqttClient.h"]

6["RTClib.h"]

5["SdFat.h"]

4["Wire.h"]

Included by

graph RL
1["include/network.h"]
click 1 "network_8h.md#network_8h"
2 --> 1
3 --> 1

2["src/core.cpp"]
click 2 "core_8cpp.md#core_8cpp"

3["src/network.cpp"]
click 3 "network_8cpp.md#network_8cpp"

Functions

Function ConnectToWiFi

bool ConnectToWiFi(unsigned long timeoutMs=10000)

Establishes a WiFi connection with the configured network.

Attempts to connect to the WiFi network using credentials from the secrets file. Provides visual feedback via serial output and enforces a connection timeout.

Parameters:

  • timeoutMs: Maximum time in milliseconds to wait for connection (default: 10000ms).

Returns:

true if WiFi connection is successful, false if timeout occurs.

Parameters:

  • unsigned long timeoutMs = 10000

Return type: bool

Function ConnectToMQTT

bool ConnectToMQTT(MqttClient &mqttClient, unsigned long timeoutMs=10000)

Establishes an authenticated MQTT connection to the broker.

Sets up MQTT client credentials using values from the secrets file and attempts to connect to the configured MQTT broker. Provides visual feedback and enforces a connection timeout.

Parameters:

  • mqttClient: Reference to the MQTT client instance to connect.
  • timeoutMs: Maximum time in milliseconds to wait for connection (default: 10000ms).

Returns:

true if MQTT connection is successful, false if timeout occurs.

Parameters:

  • MqttClient & mqttClient
  • unsigned long timeoutMs = 10000

Return type: bool

Function IsConnectedToServer

bool IsConnectedToServer(MqttClient &mqttClient)

Parameters:

  • MqttClient & mqttClient

Return type: bool

Source

#pragma once

#include "platform.h"

bool ConnectToWiFi(unsigned long timeoutMs = 10000);
bool ConnectToMQTT(MqttClient& mqttClient, unsigned long timeoutMs = 10000);

inline bool IsConnectedToServer(MqttClient& mqttClient) {
  return WiFi.status() == WL_CONNECTED && mqttClient.connected();
}