Internet does not work on esp32, when distributing wifi from mobile data (android), but in other cases it works

Why when connecting to the wifi access point of the phone (android), http.POST returns -1, although there is Internet and everything is fine when connected to the home network, and also when the phone is a repeater from the home network to its own network, which it distributes, everything also works , stops working (giving HTTPC_ERROR_CONNECTION_REFUSED (-1)) when trying to reach the server (tried on different ones, httpbin is one of them) when the phone acts as a wifi access point, using mobile data, and other devices connected to this network work correctly, here diagnostic output

IP address:
192.168.81.157
Mode: STA
Channel: 2
SSID (3): ssid
Passphrase (8): password
BSSID set: 0
httpCode: -1

#include <Arduino.h>

#include "WiFi.h"
#include <HTTPClient.h>


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  WiFi.begin("ssid", "password");
  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.print(".");
  }
  WiFi.printDiag(Serial);
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());


  WiFiClient client;
  HTTPClient http;

  if (http.begin(client, "http://httpbin.org/post")) {
    http.addHeader("Content-Type", "application/json");

    int httpCode = http.POST("{\"my_json\":1}");
    if (httpCode > 0) {
      if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
        Serial.println(http.getString());
      }
    }
    http.end();
    Serial.println("httpCode: "+String(httpCode));
  }
}

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

}

I also ran ifconfig on this phone, maybe that will help (termux)

ifconfig
Warning: cannot open /proc/net/dev (Permission denied). Limited output.
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)

rmnet_data1: flags=65<UP,RUNNING>  mtu 1404
        inet 192.0.0.2  netmask 255.255.255.224
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 1000  (UNSPEC)

wlan1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.81.205  netmask 255.255.255.0  broadcast 192.168.81.255
        unspec 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  txqueuelen 3000  (UNSPEC)

Does the phone have a proxy server that you need to route through?

I unfortunately don't know how to check this, if you can tell me I will be happy to check, here is also the output from ubuntu which I used to connect to this network

ifconfig

enp3s0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        ether 3c:7c:3f:d4:73:c9  txqueuelen 1000  (Ethernet)
        RX packets 423413  bytes 390895992 (390.8 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 352721  bytes 47413345 (47.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Локальна петля (Loopback))
        RX packets 11854  bytes 4163007 (4.1 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 11854  bytes 4163007 (4.1 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlx002e2d30430f: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.81.221  netmask 255.255.255.0  broadcast 192.168.81.255
        inet6 2a02:2378:119f:9ca0:aebb:1791:6c9d:1fd6  prefixlen 64  scopeid 0x0<global>
        inet6 2a02:2378:119f:9ca0:e63f:1b15:d7cb:5223  prefixlen 64  scopeid 0x0<global>
        inet6 fe80::531f:5c4a:cda4:f7a9  prefixlen 64  scopeid 0x20<link>
        ether 00:2e:2d:30:43:0f  txqueuelen 1000  (Ethernet)
        RX packets 8404  bytes 6081332 (6.0 MB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 7430  bytes 1462928 (1.4 MB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I also noticed that if I start the server on flask (python) in termux, it receives requests from esp32, it appears at 192.0.0.2
Here is the flask server output

* Serving Flask app 'main'
 * Debug mode: off
WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
 * Running on all addresses (0.0.0.0)
 * Running on http://127.0.0.1:8080
 * Running on http://192.0.0.2:8080

It could be a 2.4GHz / 5 GHz issue. The ESP devices do not support the 5GHz radio frequency (yet?).

No, it works purely on 2.4G

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.