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)