Can I use http request in AP mode?

jimcooper
Posts: 8
Joined: Thu Apr 12, 2018 4:07 am

Can I use http request in AP mode?

Postby jimcooper » Thu Jun 28, 2018 3:26 am

Hi all

I want to send http request from AP. Is it possible?
Or http request just can send from STA?

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Can I use http request in AP mode?

Postby ESP_Sprite » Thu Jun 28, 2018 4:02 am

As far as the TCP/IP layer is concerned, you don't have an AP, STA or wired connection, you only have a network with a bunch of IPs. As long as you have IP connectivity (which AP and STA both should give), you should be able to do http requests.

jimcooper
Posts: 8
Joined: Thu Apr 12, 2018 4:07 am

Re: Can I use http request in AP mode?

Postby jimcooper » Thu Jun 28, 2018 7:07 am

ESP_Sprite wrote:As far as the TCP/IP layer is concerned, you don't have an AP, STA or wired connection, you only have a network with a bunch of IPs. As long as you have IP connectivity (which AP and STA both should give), you should be able to do http requests.
But when I want to use AP sends an http request to the STA which connect to AP and got ip, there has no response.
I use two STA(sta1 & sat2)connect to a commercial router, and send http request from sta1 to sta2, the response is correct.
Did I miss some setup in AP mode?

User avatar
kolban
Posts: 1683
Joined: Mon Nov 16, 2015 4:43 pm
Location: Texas, USA

Re: Can I use http request in AP mode?

Postby kolban » Thu Jun 28, 2018 8:08 am

I am assuming that you have one ESP32 running as an access point (AP) and a second ESP32 running as a station (STA). When the AP ESP32 starts up and the STA ESP32 connects to it, then you should be able to form a TCP connection from a client application running on AP to a server application running on the STA. HTTP is merely a protocol on top of TCP. When we say that the client application running on AP doesn't get a response from the server application running on STA you are likely going to want to do some debugging. For example, listing the IP addresses of both ends, attempting to form a connection from the client to the server and looking for error codes. Logging connection requests at the server. Logging error responses at the server .... and so on. From a networking standpoint, once the STA connects to the AP, both then appear as peer IP hosts to each other.
Free book on ESP32 available here: https://leanpub.com/kolban-ESP32

jimcooper
Posts: 8
Joined: Thu Apr 12, 2018 4:07 am

Re: Can I use http request in AP mode?

Postby jimcooper » Thu Jun 28, 2018 10:39 am

If my ESP32 working on APSTA mode, and I want to send a http request.
How to decide the http request send by AP or STA?

Because my ESP32 working on APSTA mode, maybe this condition is the problem?

BTW, I use ESP32 arduino library(https://github.com/espressif/arduino-esp32).

ESP_Sprite
Posts: 9757
Joined: Thu Nov 26, 2015 4:08 am

Re: Can I use http request in AP mode?

Postby ESP_Sprite » Fri Jun 29, 2018 11:52 am

It depends on the IP. If the IP is in the AP subnet, it will be sent out of the AP. If it's in the STA subnet, it will be sent out of the STA. If it's in neither, it will be sent using the default route (which I think should be the STA in most circumstances)

jimcooper
Posts: 8
Joined: Thu Apr 12, 2018 4:07 am

Re: Can I use http request in AP mode?

Postby jimcooper » Mon Jul 02, 2018 3:31 am

When I use esp-idf "http_request" sample code, the result is same.
This is the log output below:

Code: Select all

I (16193) simple wifi: station:d8:a0:1d:40:8e:b4 join, AID=1
I (16693) simple wifi: (1)STA MAC:d8:a0:1d:40:8e:b4 IP:192.168.4.2
I (16693) simple wifi: mesh root IP:192.168.4.2
I (16693) simple wifi: DNS lookup succeeded. IP=192.168.4.2
I (16693) simple wifi: ... allocated socket
E (34923) simple wifi: ... socket connect failed errno=113
I (39923) simple wifi: DNS lookup succeeded. IP=192.168.4.2
I (39923) simple wifi: ... allocated socket
E (57683) simple wifi: ... socket connect failed errno=113
It looks like socket connect issue, but I don't know how to fix it.

Who is online

Users browsing this forum: No registered users and 340 guests