Consentium IoT
HomeTutorialsMain siteBlog
  • Getting Started
    • Consentium IoT Platform usage
    • Sensor Data API Documentation
    • Steps for Using Consentium IoT's OTA Service
    • Consentium Edge Machine Learning
    • ConsentiumNow Library Documentation
    • EdgeModelKit: Sensor Data Acquisition and Logging Library
  • Code usage
    • ConsentiumThings Python API
    • ConsentiumThings Arduino API
    • ConsentiumThings Arduino API with OTA Updates
    • WiFi auto connect API
    • ConsentiumThings Arduino Data Receiver API
    • ConsentiumNow Library API
  • Edge boards
    • Consentium Edge Dalton board
  • Tutorials
    • Receiving sensor data
      • Receiving Sensor Data from Consentium IoT Cloud and Controlling LED
    • Sending sensor data
      • Sending LM35 Sensor Data to Consentium IoT Cloud
      • Sending DHT11 Sensor Data to Consentium IoT Cloud
    • Edge machine learning
      • Sine wave predictor
      • Sine wave predictor with IoT
      • TinyML Occupancy Classification Example with Consentium IoT
  • Board support
    • Adding NodeMCU support to Arduino IDE
    • Adding ESP32 Support to Arduino IDE
    • Programming Raspberry Pi Pico with Arduino IDE (Pico W Compatible)
Powered by GitBook
On this page
  • Function Prototype
  • Description
  • Key Features
  • How to Use
  • 1. Integrate the API in Your Code
  • Behavior of the API
  • 1. Connection to a Saved Network
  • 2. Automatic Access Point (AP) Mode
  • 3. Web-Based Setup Interface
  • 4. Persistent WiFi Credentials
  • 5. Auto-Restart on Connection Failure
  • Best Practices
  • Conclusion

Was this helpful?

  1. Code usage

WiFi auto connect API

Function Prototype

void initWiFiAutoConnect();

Description

The initWiFiAutoConnect() function is designed to provide seamless and intelligent WiFi connectivity for Consentium IoT edge devices, such as the ESP8266, ESP32, and Raspberry Pi Pico W. It eliminates the need for manually entering WiFi credentials in the code, making the deployment process more user-friendly, scalable, and secure.

This function first attempts to connect to a previously stored WiFi network. If the device cannot establish a connection, it automatically switches to Access Point (AP) mode, allowing users to configure the network settings via a web-based interface. Once configured, the credentials are saved for future use, ensuring the device connects automatically in subsequent reboots.

This approach makes it ideal for remote deployments, dynamic environments, and non-technical users who need to set up IoT devices without accessing or modifying the firmware.


Key Features

Zero Hardcoded Credentials – Eliminates security risks by not storing SSID and passwords in firmware. Automatic WiFi Connection – Connects to known networks without user intervention. Fallback AP Mode – Creates a temporary WiFi network if no saved network is available. Web-Based Setup Portal – Users can configure WiFi settings using a simple browser interface. Persistent Network Configuration – Credentials are stored and automatically used for future connections. Auto-Restart on Failure – If the connection fails, the device restarts and retries until successful.


How to Use

1. Integrate the API in Your Code

Call initWiFiAutoConnect() in the setup() function to ensure the device establishes a network connection before proceeding with other tasks.

Example Usage

#include <ConsentiumThings.h>

ConsentiumThingsDalton board;

void setup() {
    Serial.begin(115200);

    // Establish WiFi connection automatically
    board.initWiFiAutoConnect();

    Serial.println("WiFi connected. Device is online!");
}

void loop() {
    // Your application logic goes here
}

Behavior of the API

1. Connection to a Saved Network

  • The device first attempts to connect to a previously stored WiFi network.

  • If successful, it prints the assigned IP address to the Serial Monitor.

2. Automatic Access Point (AP) Mode

  • If no known WiFi network is found, the device creates a temporary WiFi Access Point (e.g., ConsentiumIoT_AP_ABC).

  • A randomly generated password is displayed in the Serial Monitor.

  • Users can connect to this AP using a smartphone or computer and configure WiFi settings via a web interface.

3. Web-Based Setup Interface

  • After connecting to the AP, users can open a browser and navigate to the configuration page (typically at 192.168.4.1).

  • The interface allows users to select a network and enter a password.

4. Persistent WiFi Credentials

  • Once a WiFi network is selected, the credentials are stored in the device’s memory.

  • The device reboots and connects automatically in future sessions.

5. Auto-Restart on Connection Failure

  • If the connection attempt fails, the device waits for a few seconds and automatically restarts to retry the process.


Best Practices

Call this function in setup() before executing any WiFi-dependent tasks. Monitor the Serial Output during the first setup to obtain AP credentials if needed. Ensure the device has access to a stable WiFi network to minimize reconnection delays. Use this feature for remote deployments where manual reconfiguration is not feasible.


Conclusion

The initWiFiAutoConnect() API is an essential tool for Consentium IoT edge devices, making network setup effortless and reliable. By combining automatic WiFi connection, fallback AP mode, and a web-based configuration interface, this API ensures a smooth, scalable, and secure networking experience for IoT applications. Whether used in smart homes, industrial IoT, or edge computing, it provides a robust and fail-proof mechanism to keep devices connected with minimal user intervention.

PreviousConsentiumThings Arduino API with OTA UpdatesNextConsentiumThings Arduino Data Receiver API

Last updated 2 months ago

Was this helpful?