Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By espforuandme
#90943 Hello all,

the following sketch does what it should:

Code: Select all#include <ESP8266WiFi.h>
char APssid[5]="Test";
char APpassword[10]="123456789";

void setup() {
  Serial.begin(9600);
  Serial.print("Password:");
  Serial.println(APpassword);
  WiFi.mode(WIFI_AP);
  WiFi.softAP(APssid, APpassword);
}

void loop() {
  // put your main code here, to run repeatedly:

}


The ESP is listed in the network with the SSID "Test" and you can log in with the password 123456789.

But: I want the SSID to have a unique name and the password to be generated as a random number.
The background is that I may have different users, each with an ESP in close proximity to each other, all using the same sketch.
If the SSID and the password would be the same for all ESPs, it would be chaotic.

Therefore, the plan is that the respective user gets the dynamic password and the SSID of his ESP in a display, and can then connect to his ESP.

As a first test I wrote the following sketch. The thing with the display is still missing. I just want to generate a dynamic password and a dynamic SSID in the first step.

Code: Select all#include <ESP8266WiFi.h>

char APssid[25];
char APpassword[10]; // leave password empty for now

void setup() {
  Serial.begin(9600);
  // put your setup code here, to run once:
  uint32_t chipid=ESP.getChipId();
  snprintf(APssid,25, "Test-%08X",chipid);
  Serial.print("APssid:");
  Serial.println(APssid);
  int randNumber = random(100000, 999999);
  itoa(randNumber, APpassword, 10);
  Serial.print("Password:");
  Serial.println(APpassword);
  WiFi.mode(WIFI_AP);
  WiFi.softAP(APssid, APpassword);
}

void loop() {
  // put your main code here, to run repeatedly:
}


SSID and password seem to be generated correctly, because they are displayed correctly in the serial monitor, but: the ESP is not displayed in the network with the dynamically generated SSID, but with "ESP-F5AAB9". Furthermore you don't have to enter a password. You can connect directly.

Where is my error in thinking here?

Many greetings and thanx for your help in advance