WiFiAccess point question about network name and password.

Lets say I am located out in the middle of a desert where there is no WiFi at all and I want to communicate between two ESP32s that have WiFi capability.

So I set up one ESP as a server and the other as a client. It is my understanding that I have to assign a network name and password to the server and the client.

I think I can statically assign an IP number and port number to the server. I then have to enter the same IP address and port number in the client.

Now I think the client can send a query to the server.

So my basic question is, in this setup, why do I need a network name and password. When during any transaction does the network name and password get used?

Maybe what I am wanting is to use a socket connection between the ESPs and not even use the web server and client protocol. I seems to me that I should be able to communicate between ESPs with nothing but the IP addresses and port number.

You need to set up WiFi first. One ESP32 as access point and the other as station.
Try to Google : 'ESP32 access point' and it will tell you what you need (examples too)

So my basic question is, in this setup, why do I need a network name and password. When during any transaction does the network name and password get used?

You're mixing a few things. Theoretically you don't have to set a network name and password but for most situations it makes sense to do it. For the start you don't have to decide about server and client, you have to decide for one side to be the access point and the other side to be the device connecting to that access point (that makes up a virtual wire at the Ethernet level).
Then you can decide with side will be the server and which will be the client. From a manageability point of view it may make sense to have the server on the side which forms the access point but technically it's not necessary.

I seems to me that I should be able to communicate between ESPs with nothing but the IP addresses and port number.

This is correct once you got that virtual wire (the WiFi network) up and running. It's about the same as with a wired connection. If you don't plug in the network cable you cannot use sockets for communication because there's no way for one computer to see the other. So before you get a WiFi link between the two parties you won't be able to use sockets. Once you got the virtual wire plugged in (that's what you need the network name and password for) you can use your sockets.

I am still confused. I thought I could basically setup each ESP with the identical setup with the exception of the IP address to listen too. For example, set ESP1 to IP address 123.456.789.1 and set the ESP to listen on port 45. Then set ESP2 to listen to IP address 123.456.789.2 at port 45. Then It seems to me that I should be able to send a message from ESP1 to ESP2 by sending to the ESP2s IP and port address, and likewise I could send from ESP2 to ESP1 by sending to ESP!s IP and port addresses. Isn't this what sockets are all about? Why would I have to make one a server and the other a client and it seems that no network name and password would be required.

For example, set ESP1 to IP address 123.456.789.1 and set the ESP to listen on port 45. Then set ESP2 to listen to IP address 123.456.789.2 at port 45. Then It seems to me that I should be able to send a message from ESP1 to ESP2 by sending to the ESP2s IP and port address, and likewise I could send from ESP2 to ESP1 by sending to ESP!s IP and port addresses.

Yes, you can do that, but it's not the usual way to do it.

Why would I have to make one a server and the other a client

I didn't write that you have to make one a server, you can make both a server and both a client if you like.

it seems that no network name and password would be required.

That's wrong because without it the (virtual) network wire is missing. That's below the IP layer (sockets are on that layer). That's about the same as with the telephone network. You may know the number and if your telephone is connected to your telephone company you can just dial the number to be connected to the remote party. If the telephone company never got a cable to your house you can dial the number as often as you like you will never be connected.
Or to make an example with a wireless connection. If you don't insert the SIM card in your cellular phone you can dial the given number as often as you like, the provider won't make a connection. I hope this analogy makes it more clear for you.

You made an analogy with sim cards and cell phones. I am thinking of a case whee there is no cell service, no routers, and no networks, just two cell phones by themselves wanting to send a message between only those two phones. If these are the only items trying to communicate, then there should be no need for networks or passwords.

I think you can, with the proper software, have each phone, or ESP open a socket for listening and then wait for the other to connect. My application here is say I want to control a drone using wifi and the drone will fly so far as to not be able to connect to a router. Maybe I have a directional antenna so my phone can beam a strong signal to the drone. In this case, I just want a reliable one to one connection. I hate to be stubborn but isn't there some simple socket software that only require3s knowing the IP and port of the distant endpoint?

You made an analogy with sim cards and cell phones. I am thinking of a case whee there is no cell service, no routers, and no networks, just two cell phones by themselves wanting to send a message between only those two phones. If these are the only items trying to communicate, then there should be no need for networks or passwords.

The analogy with cell phone would not work as well as the ESP32 case does not work if you just use them as WiFi clients. You must configure one of them to do the access point job, otherwise they won't be able communicate.

I think you can, with the proper software, have each phone, or ESP open a socket for listening and then wait for the other to connect.

No, you need the underlying network layer (in both scenarios).

I hate to be stubborn but isn't there some simple socket software that only require3s knowing the IP and port of the distant endpoint?

Sockets are simply a term used in the IP software layer. If you don't have the underlying network connection established, you cannot use the IP layer on top of it. In the wired world that is the Ethernet layer and the physical wire, in the WiFi world it's the WiFi connection which builds the Ethernet layer and for that you need at least a network name, the password is optional, if you don't care for security you can omit it. To build a WiFi network you need a device that does the access point. That device may be a router or it may be one of the ESP32s but it won't work without it. Don't insist on something you don't understand.

Maybe i am not using the proper names for things. I may be using "socket" for "access point".

Consider my example where I have no router just two ESPs. Can I not set each one up as an access point, or socket, and this way either ESP can start the conversation?

If this is possible, then where would the network name come into play? Does each ESP exchange network names? I thought that only doing a send to an IP/port is all that is required.

Consider my example where I have no router just two ESPs. Can I not set each one up as an access point, or socket, and this way either ESP can start the conversation?

No, you cannot. There's exactly one access point in a WiFi network. So you have to configure one to be the access point and the other one as the client.

I thought that only doing a send to an IP/port is all that is required.

I understood that you thought that but that thought is wrong as I explained several times above. You need the base layers before you start IP communication.

I guess I had better do more studying.

You don't necessarily need a password, but for two devices to talk to each other they must be connected to each other.

When we connect computers together, we call this a network.

IP addresses are how we direct traffic on an IP network. Hardware and software can be used to route messages to the correct address only if there is a physical path for the messages to follow. One physical path packets can follow is on a WiFi connection.

You also don't necessarily need to setup your devices as web servers and web clients, but when two devices are connected in a network many times we will write a client program that makes requests of a server program. You can do this with whatever protocol you like, even a custom interface. You do not need to use a web server and respond to HTTP requests. You can write a custom server to respond to custom requests.

Depending on what you are trying to achieve, it may or may not be beneficial to use HTTP requests and a standard web server.

Thanks for the response Karma. I am trying to understand the simplest way for two wifi devices to communicate without using a router or other assistant device. I keep thinking, but many on this site think I am crazy, that I only need the IP/port of each device to send/receive data. I am not trying to make a network, only a simple connection between two devices. Given this situation, I cannot see why a network name and password are required. I don't even know how they would be used. I can see that each phone can be set to listen on a particular IP address and port. If I know the IP/port of the other phone, and the other phone is set to listen, then it seems to me that all I need to do is to send to the proper IP/port and get heard by the other phone. I would probably set each phone to listen on a particular IP/port. If I need to use a network name and password, how would I use it?

I think that what I am talking about is simply opening a socket on each phone and listening for another phone to send to their IP.

Yes, this can be done without a router, switch or other hardware, but you still must use a network. You can only send messages by IP address on an IP network. (IPv4 or IPv6) this is a software layer that is already written that allows for a programmer to do things like open a socket.

You are able to create an IP network using WiFi on an ESP 8266 or 32 using the WiFi library. A password is not a requirement, but SSID is.

One ESP will be setup as an access point to broadcast the SSID and the other will connect to the network using the SSID. Then you can open sockets and send data back and forth freely.

Technically, if you wanted to, you could make your own RF interface that just broadcast a signal with a device identifying id that looks like an IP address and all yor RF devices that don't have that id drop the data, but this seems like a lot of work to get this functionality and it would be far inferior to an IP network.

I don't think anyone thinks you are crazy, they just don't know exactly what information you are missing to understand what you need to do to successfully complete your project.

barryjo:
...I am not trying to make a network, only a simple connection between two devices. Given this situation, I cannot see why a network name and password are required. I don't even know how they would be used. I can see that each phone can be set to listen on a particular IP address and port. If I know the IP/port of the other phone, and the other phone is set to listen, then it seems to me that all I need to do is to send to the proper IP/port and get heard by the other phone. I would probably set each phone to listen on a particular IP/port. If I need to use a network name and password, how would I use it?

I think that what I am talking about is simply opening a socket on each phone and listening for another phone to send to their IP.

Again, to be clear here, the password part is optional. The name is so devices know what access point they are connecting to.

If you don't connect your two devices together (in a network, though the simplest form of a network [one device connected to another with a wire or wireless connection]) how are the data signals / radio waves going to be sent out of your device to be read by another device listening on that IP / port?

The WiFi network connection will handle all the RF data sending for you so that all you need to do is open a socket.

OK, lets say that ESP1 sets up with a network name of Hello, and listens on IP 123.456.789.1 and port 80.
Now lets set up ESP2 with a network name of World, listen on IP 123.456.789.2 and port 2.

Now, if I try to send from ESP1 to ESP 2 but sending a message with ip of123.456.789.2/80 Where does the network name come into play? Where is this example is the network name used?

It just doesn't seem like it is necessary for point to point, or peer to peer communication. IP/port identifies the ESP you are sending too, why do I need a network name? Really now.

Does a computer that is hardwired via a cable to a router need a network name and password?

barryjo:
Does a computer that is hardwired via a cable to a router need a network name and password?

Usually, no. As long as it has (or acquires) an IP address it can just start sending packets without any other setup.

In the previous posts, I have been trying to establish that if there were two ESPs in an area without a router, thee is really no reason to have them require a network name and password to communicate. Granted when a router is involved, this is a different matter. I say that a network name and password is really only necessary when wifi is the connection mechanism. So now, I need to learn how to merely set up sockets on two different ESPs without having a network name and password.

barryjo, you are seeing the things in a far too complicated way.

See the documentation of the Wifi library, how to make up a so called "peer", "on-the-go", or "ad-hoc" network. That works fairly well.

Your approach, though, may make things more complicated than simply turn one of the devices into a "master" or "controller", the other sides then as "slaves"or "clients".

= But that is up to you.

You can find all of that in the Wifi-class documentation. See "WiFi.mode()" for the datails you are looking for.

Hope that helps, Jack.


"MicroSoft" expands to "NanoWeak" - With Linux since Kernel 1.0.36, 1995.

Here is a dumb question. Where is the wifi documentation? Do you mean to look through the header files?

Way not!, see here:

"WiFi.mode()" is whar you are looking for. As I see, exactly this item is missing in the wiki...

I can look that up for you, but it would be easier if you did it youself. Damn!

That holds the answer to all of your questions. - I'm going to file a ticket for that. Sorry.