WiFi.config(...) parameter order


I'm new to Arduino development. I'm working on an ESP32 and trying to connect it to WiFi using a static ip. I'm able to connect using DHCP just fine using WiFi.begin(...).

I'm using this piece of documentation to base my code off of. I'm currently using this method to verify the WiFi was set up correctly:

  void printWiFiStatus() {
    // print your WiFi IP address
    IPAddress ip = WiFi.localIP();
    Serial.print(F("Module IP address:             "));
    // print your WiFi gateway
    IPAddress gw = WiFi.gatewayIP();
    Serial.print(F("Module gateway IP address:     "));
    // print your WiFi subnet mask
    IPAddress sm = WiFi.subnetMask();
    Serial.print(F("Module subnet mask:            "));
    // print the received signal strength
    long rssi = WiFi.RSSI();
    Serial.print(F("Module signal strength (RSSI): "));
    Serial.println(F(" dBm"));

The values that were being printed were definitely wrong and it took a little bit of trial and error to fix it:


This was the resulting output from Serial:

Module IP address:   
Module gateway IP address:
Module subnet mask:  
Module signal strength (RSSI): -61 dBm

My question is whether the order of the parameters depends on the board I'm deploying to or whether the documentation is incorrect. It's not enough that this is working just for this particular board. I'm trying to develop for a codebase that could potentially be deployed to several kinds of boards. Having to swap params around based on boards will get a little tidious...

I've also been told that setting the pin modes for the wifi module is a good best practice when writing board-agnostic code. I'm wonder if the pin modes affect the order of these parameters or if I were to screw up the pin modes whether that would also affect the order of the parameters. My current code doesn't bother with the pin modes, but that may be changing as my project progresses. Any advice or tips to that point would also be appreciated.

You're not using the right documentation, the documentation you linked to is for the Arduino WiFi library that comes with WiFi-enabled official Arduino boards. You need the documentation for ESP32:

Thanks for the clarification! Looks like this project is going to be a little more complicated than I initially thought...

It's probably best to abstract away these platform-specific differences in some helper functions in a separate file, selecting the correct implementation using #ifdef ESP32, for example.

Yep. That's becoming the plan.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.