Hi sivar2311,
I expected the new ESP32 to get a different IP address, but by NOT trying to force a static IP address, it comes up with the following on the VSC serial monitor ….
IP address: 192.168.0.127
MAC address: 84:1F:E8:27:8F:6C
Google tells me this IP address is usually my router’s admin page.
If I force an avilable static IP address, the VSC serial monitor shows …..
IP address: 192.168.1.150
MAC address: 84:1F:E8:27:8F:6C
My router shows no such device connected.
I’ve used this new ESP32 device (with separate aerial) before and it connected ok, but not now.
I’ve also tried again today my old ESP32-Wroom (without a sparate aerial), with this same code and it works fine with or without a static IP. It’s “natural” IP is 192.168.1.160, or I can force it to claim 192.168.1.150.
This is my code (not showing all webserver HTML, etc) …
/*********
Trev's ESP32-WROOM control system - WiFi Webserver controlled, with WhatsApp messaging and CAN bus.
Based on Rui Santos & Sara Santos - Random Nerd Tutorials
*********/
// Import required libraries
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <HTTPClient.h>
#include <UrlEncode.h>
#include <CAN.h>
// Replace with your network credentials
const char* ssid = "xxxxxxxxxxxxx"; //set to Trev's router ssid
const char* password = "xxxxxxxxxxx"; //set to router password
// CALLMEBOT WhatsApp support
String phoneNumber = "xxxxxxxx"; //Trev's phone number
String apiKey = "xxxxxx"; //Trev's apiKEY for CALLMEBOT.com
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
// Set your Static IP address
IPAddress local_IP(192, 168, 1, 150);
// Set your Gateway IP address
IPAddress gateway(192, 168, 1, 254);
IPAddress subnet(255, 255, 0, 0);
//IPAddress primaryDNS(8, 8, 8, 8); //optional
//IPAddress secondaryDNS(8, 8, 4, 4); //optional
...... GPIO define, HTML, etc ........
// SETUP ROUTINE ###################################
void setup(){
// Serial port for debugging purposes
Serial.begin(115200);
// WiFi LED on board OFF
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// Setup PWM LED
// ledcSetup(LED32Channel, freq, resolution);
// ledcAttachPin(LED32pin, LED32Channel);
// Setup GPIOs all as OUTPUTS
pinMode(LED13, OUTPUT);
// Setup GPIOs OUTPUTS all OFF
digitalWrite(LED13, LOW);
// Force static IP address #######################################
if (!WiFi.config(local_IP, gateway, subnet)) {
Serial.println("STA Failed to configure");
}
// Connect to Wi-Fi ##############################################
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println("Connecting to WiFi..");
}
// WiFi connected OK
Serial.println("");
Serial.println("WiFi connected.");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
// WiFi LED on board ON
digitalWrite(LED_BUILTIN, HIGH);
// Print ESP MAC Address
Serial.println("MAC address: ");
Serial.println(WiFi.macAddress());
// Set the CAN TX RX pins and start CAN #########################
CAN.setPins (RX_GPIO_NUM, TX_GPIO_NUM);
CAN.begin(500E3);
// Route for root / web page ####################################
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/html", index_html, processor);
});
// LOOP #########################################################
void loop() {
//send CAN messages
sendCANALL();
//Flash GPIO 13;
int LED = 13;
digitalWrite(LED13, HIGH);
delay(200);
digitalWrite(LED13, LOW);
delay(200);
}
Thank you