Overview
The WiFi module provides comprehensive cloud connectivity including WiFi management, MQTT messaging, Firebase integration, and Google Sheets API for ESP32/ESP8266 platforms.
WiFi Connection
WiFiHandler
Basic WiFi connection management with auto-reconnect.
#define ENABLE_MODULE_WIFI_HANDLER
#include "Kinematrix.h"
WiFiHandler wifi;
void reconnectCallback () {
Serial . println ( "Reconnecting to WiFi..." );
}
void setup () {
if ( wifi . connectToWiFi ( "MySSID" , "MyPassword" , reconnectCallback)) {
Serial . println ( "Connected!" );
Serial . println ( WiFi . localIP ());
}
}
void loop () {
if ( ! wifi . isConnect ()) {
wifi . connectToWiFi ( "MySSID" , "MyPassword" , reconnectCallback);
}
}
Connect to WiFi network reconnectCallback
void (*)()
default: "nullptr"
Callback during reconnection attempts
Returns true if connected successfully
Check WiFi connection status Returns true if connected
MQTT Messaging
MQTTManager
Comprehensive MQTT client with auto-reconnect and JSON support.
#define ENABLE_MODULE_MQTT_MANAGER
#include "Kinematrix.h"
MQTTManager mqtt;
void messageReceived ( char* topic , byte * payload , unsigned int length ) {
Serial . printf ( "Message on %s : " , topic);
for ( int i = 0 ; i < length; i ++ ) {
Serial . print (( char ) payload [i]);
}
Serial . println ();
}
void setup () {
mqtt . beginWiFi ( "MySSID" , "MyPassword" );
mqtt . beginMQTT ( "mqtt.server.com" , 1883 , "user" , "pass" );
mqtt . setCallback (messageReceived);
if ( mqtt . connect ()) {
mqtt . subscribe ( "sensor/temperature" );
mqtt . publish ( "device/status" , "online" );
}
}
void loop () {
mqtt . loop ();
}
Initialize WiFi connection
Initialize MQTT connection username
const char*
default: "NULL"
MQTT username
password
const char*
default: "NULL"
MQTT password
Set message callback Callback function(char* topic, byte* payload, unsigned int length)
Connect to MQTT broker Returns true if connected
Subscribe to topic Topic name (wildcards supported: # and +)
Attempt reconnection interval
unsigned long
default: "5000"
Retry interval in ms
Process MQTT messages (call in loop)
Enable automatic reconnection
Firebase Integration
FirebaseV3Application
Modern Firebase SDK integration with multiple authentication methods.
#define ENABLE_MODULE_FIREBASE_V3
#include "Kinematrix.h"
FirebaseV3Application * firebase = FirebaseV3Application :: getInstance ();
void authCallback ( AsyncResult & result ) {
if ( result . isEvent ()) {
Serial . println ( "Authentication event" );
}
}
void setup () {
// Email/password authentication
firebase -> begin ( "API_KEY" , "[email protected] " , "password" ,
"project-id" , authCallback);
// Wait for ready
while ( ! firebase -> isReady ()) {
firebase -> loop ();
delay ( 100 );
}
Serial . println ( "Firebase ready!" );
}
void loop () {
firebase -> loop ();
}
Get singleton instance Returns Firebase application instance
Initialize Firebase with authentication Email/Password
apiKey, userEmail, userPassword, projectId, callback
User authentication
Service Account
clientEmail, projectId, privateKey, callback
Service account authentication
Process Firebase events (call in loop)
Check if Firebase is ready Returns true when authenticated and ready
Get FirebaseApp reference for services
Google Sheets API
GoogleSheetClient
Google Sheets integration for data logging and retrieval.
#define ENABLE_MODULE_GOOGLE_SHEETS
#include "Kinematrix.h"
GoogleSheetClient sheets;
void setup () {
sheets . addAP ( "MySSID" , "MyPassword" );
// Service account credentials
sheets . begin ( "[email protected] " ,
"project-id" ,
"-----BEGIN PRIVATE KEY----- \n ..." );
while ( ! sheets . ready ()) {
sheets . process ();
delay ( 100 );
}
// Append data
FirebaseJson valueRange;
valueRange . set ( "values/[0]/[0]" , "Temperature" );
valueRange . set ( "values/[0]/[1]" , 25.5 );
sheets . appendValues ( "SPREADSHEET_ID" , "Sheet1!A1" , & valueRange);
}
void loop () {
sheets . process ();
}
Initialize Google Sheets client Service account private key (PEM format)
Process API requests (call in loop)
Check if client is ready Returns true when authenticated
Update cell values A1 notation range (e.g., “Sheet1!A1:B2”)
Get cell values Returns JSON string with values
Create new spreadsheet Returns spreadsheet ID
Example: Complete IoT Logger
#define ENABLE_MODULE_MQTT_MANAGER
#define ENABLE_MODULE_GOOGLE_SHEETS
#include "Kinematrix.h"
MQTTManager mqtt;
GoogleSheetClient sheets;
float temperature = 0 ;
void messageReceived ( char* topic , byte * payload , unsigned int length ) {
String msg = String (( char * )payload). substring ( 0 , length);
temperature = msg . toFloat ();
// Log to Google Sheets
FirebaseJson values;
values . set ( "values/[0]/[0]" , millis ());
values . set ( "values/[0]/[1]" , temperature);
sheets . appendValues ( "SPREADSHEET_ID" , "Sheet1!A1" , & values);
}
void setup () {
mqtt . beginWiFi ( "SSID" , "Password" );
mqtt . beginMQTT ( "mqtt.server.com" );
mqtt . setCallback (messageReceived);
mqtt . connect ();
mqtt . subscribe ( "sensor/temp" );
sheets . addAP ( "SSID" , "Password" );
sheets . begin ( "[email protected] " ,
"project-id" , "private-key" );
}
void loop () {
mqtt . loop ();
sheets . process ();
}
WiFi modules are only available on ESP32 and ESP8266 platforms. Code is conditionally compiled with #if defined(ESP32) || defined(ESP8266).
ESP32 Full support - recommended platform
ESP8266 Full support with memory optimization