- Notifications
You must be signed in to change notification settings - Fork 13.3k
Closed
Description
I have some old ESP8266 NOOS CODE that works but goes buggy after a few days. I want to port this to arduino as this uses 3.x of the SDK and I have an old 2.0 version of the NO OSSDK. In the old code I can randomize both the STATION and SOFT AP at the same time. But in this sketch only the first one is chnaged the station MAC doesn't change
#include <ESP8266WiFi.h> #include <ESP8266TrueRandom.h> /* Set these to your desired credentials for ESP8266 AP. */ const char *ssid = "SOFTAP"; const char *password = "01234567"; // Setup credentials for original WiFi, that we plan to repeat const char* ssidExt = "ISPWIFI"; void setup() { uint8_t newMACAddress[6]; Serial.begin(76800); ESP8266TrueRandom.mac(&newMACAddress[0]); Serial.printf("SOFTAP_IF %02x:%02x:%02x:%02x:%02x:%02x\r\n", newMACAddress[0],newMACAddress[1],newMACAddress[2],newMACAddress[3],newMACAddress[4], newMACAddress[5]); WiFi.softAPmacAddress( &newMACAddress[0]); ESP8266TrueRandom.mac(&newMACAddress[0]); Serial.printf("STATION_IF %02x:%02x:%02x:%02x:%02x:%02x\r\n", newMACAddress[0],newMACAddress[1],newMACAddress[2],newMACAddress[3],newMACAddress[4], newMACAddress[5]); wifi_set_macaddr(STATION_IF, &newMACAddress[0]); WiFi.mode(WIFI_AP_STA); WiFi.begin(ssidExt, password); WiFi.softAP(ssid, password); IPAddress myIP = WiFi.softAPIP(); IPAddress apIP(192, 168, 4, 1); Serial.print("AP IP address: "); Serial.println(myIP); } bool connected = false; void loop() { bool newConnected = (WiFi.status() == WL_CONNECTED); if(!connected && newConnected) { Serial.print("Connected to "); Serial.println(WiFi.macAddress()); Serial.println(ssidExt); Serial.print("IP address: "); Serial.println(WiFi.localIP()); Serial.print("dnsIP address: "); Serial.println(WiFi.dnsIP()); Serial.print("gatewayIP address: "); Serial.println(WiFi.gatewayIP()); Serial.print("subnetMask address: "); Serial.println(WiFi.subnetMask()); } else if (connected && !newConnected) { Serial.print("Lost connection"); } connected = newConnected; delay(5000); }