Notifications
Clear all

ESP32 WiFi Access Point Creation Issues

23 Posts
3 Users
2 Likes
627 Views
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@helisteve I have a version of your code that is getting to the end of setup. I still have those 2 lines commented out as I have no idea what they should be.

This is now what the serial log looks like (I hard coded the 192.168.4.200 because of my router situation, yours may be different) If you want to see the modified code, let me know.

Setting the AP
ESP32 AP IP address: 192.168.4.200
ESP32 WiFi Robot Controller.
Build 02, Date : 1/10/2024

 

 

 

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
HeliSteve
(@helisteve)
Member
Joined: 4 months ago
Posts: 20
Topic starter  

Hi Ron. Sorry for slow response. I took some time away to watch YouTube vids of robot arms. That is where this project is slowly heading towards. Below is what the two lines of code refer to. My bad, I should have added them in my earlier post.

/**************************************
* Deal with root handle request here.
*/
void HTTP_handleRoot(void) {
  if (server.hasArg("State")) {
    Serial.println(server.arg("State"));
  }
  server.send(200, "text/html", "ESP32 OK");
  delay(1000);
}  // End of HTTP_handleRoot()


/**************************************
* Deal with HTTP handle not found issue.
*/
void HTTP_handle_NotFound(void) {  // I need to find a better way to notify user.
  Serial.println(F("404: Not Found."));
}  // End of HTTP_handle_NotFound()

Yes please. I would love to see the code you've created. And thank you for your help with this. 🙂

 

Gone Flying, Sailing, or Both..


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@helisteve Ok, here is my code. You will need to remove my //RCA and put in the above code. Hopefully you can compare and see your old commented out code as compared to the new code. YES, the AP address is hard coded, I am sure there is a way to use a symbolic address or some other name server. 

Don't ask me too many questions; I am not trained on web stuff; I am an old tube guy (and former sailor first mate on a Siren 17, O'day 25, Bayfield 32, and one day on a Viking 33 with a racing crew who at one time broached it)

#include <WiFi.h>
#include <WebServer.h>
#include "esp_wifi.h"


#define leftDIR 13   // Left motor direction   GPIO13
#define rightDIR 12  // Right motor direction  GPIO12
#define leftPWM 14   // Left motor PWM         GPIO14
#define rightPWM 27  // Right motor PWM        GPIO27


#define ledLight 4  // Light  GPIO4


#define FORWARD LOW
#define REVERSE HIGH
#define OFF 0
#define duty2580
#define duty50127
#define duty75180
#define duty100255


#define BT_DISCOVER_TIME 10000


String command;    //String to store app command state.
int speedCar = 0;  // 0 to 255


//SSID and Password to your ESP Access Point
const char* ssid = "Robot Wifi";
const char* password = "robot";


WebServer server(80);


String myName = "ESP32-Robot-Control";


/**************************************
*
*/
void setup() {
  digitalWrite(leftDIR, FORWARD);
  digitalWrite(rightDIR, FORWARD);
  analogWrite(leftPWM, OFF);
  analogWrite(rightPWM, OFF);


  pinMode(leftDIR, OUTPUT);
  pinMode(rightDIR, OUTPUT);
  pinMode(leftPWM, OUTPUT);
  pinMode(rightPWM, OUTPUT);
  pinMode(ledLight, OUTPUT);


  Serial.begin(115200);
/*
  WiFi.mode(WIFI_MODE_AP);
  // Start WiFi AP HOTspot, removing password will disable security
  if (!WiFi.softAP(ssid, password)) {
    Serial.println(F("Soft AP creation Failed.."));
  }
*/

  WiFi.mode(WIFI_AP); 
  WiFi.softAP(ssid, password);   //launch the access point
  delay(100) ;  // a more correct approach is to wait for SYSTEM_EVENT_AP_START to fire
  Serial.println("Setting the AP");
  IPAddress Ip(192, 168, 4, 200);    //setto IP Access Point same as gateway
  IPAddress NMask(255, 255, 255, 0);
  WiFi.softAPConfig(Ip, Ip, NMask);
  // Show IP address.
  IPAddress myIP = WiFi.softAPIP();
  Serial.print("ESP32 AP IP address: ");
  Serial.println(myIP);

  // Start WEB-server
  //RCAserver.on("/", HTTP_handleRoot);
  //RCAserver.onNotFound(HTTP_handle_NotFound);
  server.begin();
  Serial.println("ESP32 WiFi Robot Controller.");
  Serial.println("Build 02, Date : 1/10/2024");
}  // End of setup()

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

}

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
HeliSteve
(@helisteve)
Member
Joined: 4 months ago
Posts: 20
Topic starter  

@zander Hi Ron. Well your code worked. I added in all my original code except for the if(!WiFi.softAP(ssid, password); that you commented out. Ran the code and had no errors and the IP was what you set. Then I commented out the hard coded IP stuff, compiled and it worked and set the IP to 192.168.4.1 like it is supposed to do. So now it is working as it should. You know there are days I ask myself why I like electronics and programming. It drives me nuts sometimes. My original code is running and working great on a project I made for my wife. Using an App I wrote using MIT App Inventor she can control a bunch of bluetooth connected AC outlets. The phone connects to the ESP32 AP 192.168.4.1 using WiFi, then the ESP32 connects to all the AC outlets using bluetooth. So why that same code would not work on this project is beyond me. At this point I am going to chalk it up to something in my setup, but I hate not knowing what really is going on. Sadly like you, I am not good with Web related programs (guess I should have taken some classes when I was younger), and there seems to be hundreds of different ways to write web server and client code, sockets, HTTP, etc..

Sounds like you have had some good sailing experiences. My wife and I own a 43' Irwin CC. She is actually for sale as my wife's hands are getting crippled, and my shoulders are shot. I played with some tube TV's and radios when I was young but quickly decided they were not for me. Moved on to transistors and left the tubes behind, Lol.

So this project you helped me with was just a small test platform so I could test out an old robot base I made in the 90's. I just needed a wireless way to control the old motor driver I built decades ago. It was connected using RS485 cabling and I didn't want that. The end goal is going to be a completely new robot that will run autonomously through our property digging up cactus plants. So I will be adding vision (something I've always wanted to mess with), GPS waypoints and routes. I plan to make the base similar to the MARS rover. Should be a fun and exciting project when completed.

I'm retired and lost my work buddy to bounce problems off of. So now I've come to the internet to find new work buddies to bounce problems off of. 🙂 Thank you so much for you time and effort helping me with this program. I am happy it is working because I do have other needs for it. Have a great day!!

Gone Flying, Sailing, or Both..


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@helisteve Just a caution Steve. The address 192.168.4.1 is a special address to be only used to get a device properly set up, NOT to be used continuously.

It is not clear to me if you are doing that but if so, I bet your wife's 'app' will not work if she reboots. Perhaps you should look at WiFiManager. Bill did a video/article that can be found at. I think what you need to do is look at the part of the article with heading of

Modifying Existing Sketches to use WiFiManager

any questions?

Video Article

 

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
ReplyQuote
HeliSteve
(@helisteve)
Member
Joined: 4 months ago
Posts: 20
Topic starter  

@zander Hi Ron. I did watch (well listen) Bill's video about wifi manager and I planned to revisit later and watch it thoroughly. I usually listen to Bill's videos while working on other projects. Hopefully to plant a seed that sprouts later when I need it. 

So far I have not had any issues with the default IP address the ESP32 creates. But I appreciate you bringing it to my attention. I will do some research to learn why ESP32 uses that, and why I should not use it continuously. 

Have a great day. 

Gone Flying, Sailing, or Both..


   
ReplyQuote
Ron
 Ron
(@zander)
Father of a miniature Wookie
Joined: 3 years ago
Posts: 6988
 

@helisteve 192.168.4.1 is a STANDARD used by almost every WiFi device. It is baked in somewhere in the hard/firmware BUT as you have seen can be overridden. As long as the esp32 has NO need to connect to anything else (ie STA mode) then AP is fine, but if you used that original code on your wife's esp32 then you will have two esp32's in AP mode listening at the same 192.168.4.1 address. This is why that address is reserved and meant to be only used for a few seconds while the AP either changes to STA mode or STA+AP mode but with a new unique IP address.

 

First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.


   
HeliSteve reacted
ReplyQuote
HeliSteve
(@helisteve)
Member
Joined: 4 months ago
Posts: 20
Topic starter  

@zander Hi Ron. Thanks for the update. That makes sense to me and now I will go back and update my code. Luckily she only uses the bluetooth outlets at Christmas right now, so I have some time to get to it.

Gone Flying, Sailing, or Both..


   
ReplyQuote
Page 2 / 2