# Unable to connect to server 127.0.0.1:1880 through port 1880

**URL:** <https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444>\
**Category:** General\
**Created:** [9 February 2020 06:28 UTC](https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444 "2020-02-09T06:28:13Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![HelenH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/helenh/32/16871_2.png) [@HelenH](https://discourse.nodered.org/u/HelenH)\
**Post date:** [9 February 2020 06:28 UTC](https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444/1 "2020-02-09T06:28:14Z")

</div>

Hello

lately, I was trying to deploy Temperature and Humidity measurement on Node-Red Using an ESP32 DevKit module.

Through Arduino IDE I Checked that module successfully reads values and connects to my WiFi.  
In Node-Red side, it appears to be all ok, But I have my Doubts.

The Flow that I implemented its this:

 ![deploy_TnH_Node_Red](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/7/e7aafa86f6dd673d0c11ffb298e6319dc0801bd8.png)

and the Code:

#include "WiFi.h"  
#include "DHT.h"  
#define DHTPIN 4  
#define DHTTYPE DHT11  
const char\* ssid = ////////////////////////wifi Name  
const char\* password = //////////////////////////WiFi key  
int port = 1880;  
const char\* URL = "SensorTemperatura"; //  
const char\* host = "[http://127.0.0.1:1880](http://127.0.0.1:1880)";  
unsigned long lastSend;  
float humidity = 0.0;  
float temperature = 0.0;  
String payload = "";  
DHT dht(DHTPIN, DHTTYPE);

void setup(){  
Serial.begin(115200);  
Serial.println();  
Serial.printf("Connecting to %s ", ssid);  
WiFi.begin(ssid, password);  
while (WiFi.status() != WL\_CONNECTED)  
{ delay(500);  
Serial.print(".");  
} Serial.println(" connected");  
dht.begin();  
}

void loop(){ if ( millis() - lastSend \> 1000 ) {  
leerSensor();  
delay(10);  
json();  
servicioPost();  
lastSend = millis();  
}  
}void leerSensor() { humidity = dht.readHumidity();// Lee la humedad  
temperature = dht.readTemperature(); // Lee la temperatura  
if (isnan(humidity) || isnan(temperature)) { // Verifica si hay errores de lectura en el sensor.  
Serial.println("Failed to read from DHT sensor!"); // Mensaje de falla en el sensor  
return; //Si los hay, vuelve a intentar la comunicación }}  
}  
}

void servicioPost() {  
WiFiClient client;  
Serial.printf("\n[Connecting to %s ... ", host);  
if (client.connect(host, port)) {  
Serial.println("connected]");  
Serial.println("[Sending a request]");  
client.print(String("POST /") + URL + "HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "Accept: /" + "\*\r\n" + "Content-Length: " + payload.length() + "\r\n" + "Content-Type: application/json" + "\r\n" + "\r\n" + payload );  
Serial.println("[Response:]");  
while (client.connected() || client.available())  
{ if (client.available())  
{ String line = client.readStringUntil('\n');  
Serial.println(line);  
}  
}  
client.stop();  
Serial.println("\n[Disconnected]");  
}  
else { Serial.println("connection failed!]");  
client.stop();  
}  
}

```
 void json() {
  String humedad = String(humidity, 2);
  String temperatura = String(temperature, 2);
  
  payload = "{"; payload += "\"temperatura\":"; payload += temperatura;
  payload += ",";
  payload += "\"humedad\":"; payload += humedad;
  payload += "}";
  Serial.println(temperatura);
  }

```

and the Error that I Received its this:

 ![ESP32_TO SERVER](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/2/a27739e2a01d43ac851bd73ee20d10734b2e896c.png)

will have any idea what I'm doing wrong????

Regards!!

---

<div class="post-metadata">

**Author:** ![GJames](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gjames/32/16872_2.png) [@GJames](https://discourse.nodered.org/u/GJames)\
**Post date:** [9 February 2020 06:35 UTC](https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444/2 "2020-02-09T06:35:47Z")

</div>

> [@HelenH](#):
>
> const char\* host = "[http://127.0.0.1:1880](http://127.0.0.1:1880)";

I'm a newbie here. Since you are specifying the port (1880) in the port variable, are you sure you need it in the host parameter too?

> **[WiFi - Arduino Reference](https://www.arduino.cc/reference/en/libraries/wifi/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

Perhaps try removing ":1880" from your host string and try again?

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [9 February 2020 08:06 UTC](https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444/3 "2020-02-09T08:06:25Z")

</div>

This code will only work if node-red runs on that same ESP32. You see, the reason it works when running from the debugger is that 127.0.0.1 means the local machine, itself. And when the debugger and node-red run on the same machine that’s good. And when you connect to node-red in the browser on that same machine 127.0.0.1 will work too. But from the ESP32’s perspective, 127.0.0.1 points to itself, aka the ESP32. So it needs an address for the machine running node-red instead, in such a format that it can understand it. For example a local ip address in the 192.168.x.x range when located in that same network, or perhaps an external ip address that is forwarded to that machine if it is located outside of that network.

---

<div class="post-metadata">

**Author:** ![HelenH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/helenh/32/16871_2.png) [@HelenH](https://discourse.nodered.org/u/HelenH)\
**Post date:** [9 February 2020 23:12 UTC](https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444/4 "2020-02-09T23:12:07Z")

</div>

hello

you both right in some way

I get my ip adress PC and replace that 127.0.0.1 also remove the port 1880 from host IP  
now it seems to connect whit IP 192.168... but is not able to comunicate to node-red just got this.  
maybe I need to change the server running IP from cmd to my local IP too??

Connecting to 192.168///// ... connected]  
[Sending a request]  
[Response:]  
HTTP/1.1 404 Not Found

X-Powered-By: Express

Access-Control-Allow-Origin: \*

Content-Security-Policy: default-src 'none'

X-Content-Type-Options: nosniff

Content-Type: text/html; charset=utf-8

Content-Length: 165

Vary: Accept-Encoding

Date: Sun, 09 Feb 2020 22:31:29 GMT

Connection: close

Error
```
Cannot POST /SensorTemperaturaHTTP/1.1
```

[Disconnected]

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [9 February 2020 23:31 UTC](https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444/5 "2020-02-09T23:31:05Z")

</div>

Can you export your NR flow and [attach it to a reply](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506).

Also, have you thought about using MQTT to send the data? Once you get the hang of it, it is easy to setup and use to communicate back and forth between devices.

---

<div class="post-metadata">

**Author:** ![HelenH](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/helenh/32/16871_2.png) [@HelenH](https://discourse.nodered.org/u/HelenH)\
**Post date:** [10 February 2020 04:16 UTC](https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444/6 "2020-02-10T04:16:46Z")

</div>

```auto
[
    {
        "id": "5763bf65.3cfac8",
        "type": "tab",
        "label": "Flow 3",
        "disabled": false,
        "info": ""
    },
    {
        "id": "9361adcc.7fa1f",
        "type": "debug",
        "z": "5763bf65.3cfac8",
        "name": "",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "x": 840,
        "y": 340,
        "wires": []
    },
    {
        "id": "2ec217e7.c3b658",
        "type": "http response",
        "z": "5763bf65.3cfac8",
        "name": "confirmación mensaje",
        "statusCode": "",
        "headers": {},
        "x": 810,
        "y": 100,
        "wires": []
    },
    {
        "id": "740c83f7.76b10c",
        "type": "http in",
        "z": "5763bf65.3cfac8",
        "name": "SensorTemperatura",
        "url": "test.mosquitto.org",
        "method": "post",
        "upload": true,
        "swaggerDoc": "",
        "x": 380,
        "y": 160,
        "wires": [
            [
                "9361adcc.7fa1f",
                "2ec217e7.c3b658"
            ]
        ]
    }
]

```

there is

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 February 2020 09:04 UTC](https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444/7 "2020-02-10T09:04:07Z")

</div>

ok, lets backup for a moment. Can you please describe your environment.

1. what platform is NR installed on?
2. what version of NR and node.js are running? (see startup log to get version #'s)
3. did you just add the url for '[test.mosquitto.org](http://test.mosquitto.org)' before sending the flow?
4. can you describe how you expect the data to get from the esp32 to NR?

When I suggested using MQTT, I should have explained that you need to install a broker somewhere (on the device running NR is a good place), alter your sketch to use the pub/sub library and then use the mqtt-in node in your flow.

how to install mosquitto will depend on the platform NR is running on. For a Pi, there are many tutorials such as [https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/](https://randomnerdtutorials.com/how-to-install-mosquitto-broker-on-raspberry-pi/)

For the sketch again you can find tutorials on the web such as [https://www.digikey.com/en/maker/blogs/2018/how-to-use-basic-mqtt-on-arduino](https://www.digikey.com/en/maker/blogs/2018/how-to-use-basic-mqtt-on-arduino)

While I originally used a sketch to send the readings from my dht22, I'm now flashing my WeMos's with ESPeasy which makes adding sensors a snap once it is all [setup](https://www.letscontrolit.com/wiki/index.php/Tutorial_ESPEasy_Firmware_Upload).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 April 2020 09:04 UTC](https://discourse.nodered.org/t/unable-to-connect-to-server-127-0-0-1-1880-through-port-1880/21444/8 "2020-04-10T09:04:09Z")

</div>

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