Some small questions

  1. This is how to set a mode - WiFi.mode(WIFI_STA); But how to get the mode - to print it out to a user?
  2. This is how to get MAC into a variable - WiFi.macAddress(mac); But how to set a new MAC?

Why would you need to change your MAC address?

In case there is the same one on LAN. For example we have SOMs and we buy and assign MACs for each. How guarantee it'll be no collision.

Have you ever come across that situation, two identical MAC addresses?

Tom... :grinning: :+1: :coffee: :australia:

OK. What about number 1? Suppose there is a situation a user wants to know the wifi mode.

That's already done for you, unless you buy some badly counterfeited devices, you can assume this will never happen.

ESP32 Wi-Fi Modes

The ESP32 board can act as Wi-Fi Station, Access Point or both. To set the Wi-Fi mode, use WiFi.mode() and set the desired mode as argument:

WiFi.mode(WIFI_STA) station mode: the ESP32 connects to an access point
WiFi.mode(WIFI_AP) access point mode: stations can connect to the ESP32
WiFi.mode(WIFI_STA_AP) access point and a station connected to another access point

This is a setting of the program. You should track that in a variable and set it yourself. Reading it back is like reading an LED to determine if you turned it on or the tail wagging the dog.
You should know the state of your machine as they are settings that you set.

Seriously? Why not some WiFi.mode() ? Like I have WiFi.status() to display a status. Why not the same for a mode? And after reset the board - what my variable indicating?

Because it's a setting that you control and because of such you should keep track of it.
The general reasoning is that these are tiny machines and extra code that eliminates the need to responsibly track your machine's state is costly and unnecessary.

Just make a variable:

byte wifi_mode = 0; 

if (wifi_mode == 0) {
} else if (wifi_mode == 1) {
} else if (wifi_mode == 2) {

You can use the same decision tree to display the status by replacing the WiFi.mode() call with a println or other display function.

Than you.
What is enum for modes? This one?

You can use an enumeration if you like. Integer values are assigned starting from 0 automatically, so unless you need different values you can assume the values start at 0 and are assigned in order of creation.

Thank you.

1 Like

No worries.
Please select whichever reply best answers your question and mark it as the solution so others know this thread is complete.

Happy programming!

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