5

I have made a simple Node.js local server to receive POST requests from ESP32 and put it in a database. The server is working fine as I tested it using postman. The server is listening to port 127.0.0.1:3000. My problem is that client.connect(host, port) always returns false. I cannot connect to the client in order to make POST requests.

#include "Arduino.h"
#include "Arduino.h"
#include "WiFi.h"

WiFiClient client;
const IPAddress server(192,168,1,10);
const int httpPort = 3000;
const char* ssid = "******";
const char* password =  "********";

void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println("Booted");
  Serial.println("Connecting to Wi-Fi");
  WiFi.begin (ssid, password);
  WiFi.mode(WIFI_STA);
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
    yield();
  }
  Serial.println("WiFi connected");
  if (client.connect(server,httpPort )) {
    Serial.println("Client Connected");
  } else {
    Serial.println("No Connection");
  }

void loop() {
}
dda
  • 5,700
  • 2
  • 23
  • 33
Natalie
  • 113
  • 1
  • 9
  • 3
    Have you verified that the server is accessible outside of localhost? Maybe check from another PC if the port is open. Some firewall might be blocking requests. Try binding the server to `0.0.0.0` maybe. – Maximilian Gerhardt Dec 06 '17 at 11:53

1 Answers1

4

The solution was to make the server listen to 0.0.0.0, which includes all IPv4 addresses on the server machine, instead of the loopback IP address 127.0.0.1

JMA
  • 1,673
  • 9
  • 16
Natalie
  • 113
  • 1
  • 9