# How to display localhost server in node red

**URL:** <https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368>\
**Category:** General\
**Created:** [29 January 2019 13:59 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368 "2019-01-29T13:59:15Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Varul92](https://avatars.discourse-cdn.com/v4/letter/v/b4bc9f/32.png) [@Varul92](https://discourse.nodered.org/u/Varul92)\
**Post date:** [29 January 2019 13:59 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/1 "2019-01-29T13:59:15Z")

</div>

Hello, I have made the local server using the ESP8266 web browser which is named as "192.168.1.110" and its is display the values of my sensor in the web browser also.  
Without using MQTT I want to display the data in debug node in the node-red.  
But while using HTTP node I am not able to make it work properly due to something is missing.  
I have made the flow for testing which is mentioned in the snap

 ![Http%20node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cbd20d2718044a3a1234790235405d8008fcb7ce.png)

Any advice on this will be helpful.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [29 January 2019 15:04 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/2 "2019-01-29T15:04:10Z")

</div>

Hi @Varul92

the HTTP In node you have used is for defining HTTP endpoints hosted by the Node-RED runtime.

To _get_ data from another HTTP server, you should use the HTTP Request node instead.

---

<div class="post-metadata">

**Author:** ![Varul92](https://avatars.discourse-cdn.com/v4/letter/v/b4bc9f/32.png) [@Varul92](https://discourse.nodered.org/u/Varul92)\
**Post date:** [30 January 2019 08:18 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/3 "2019-01-30T08:18:47Z")

</div>

Hi @knolleary thanks for the reply, will it work with HTTP request node only or do I have to use any other node also actually I have configured my ESP8266 as mentioned below code

```
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h> 
#include <Wire.h>
#include<ESP8266WebServer.h>

static float humidity,cTemp,fTemp;

//I2C registe for SHT31
#define Addr 0x44

const char* ssid = "ssid";
const char* password = "password";
IPAddress ip(192,168,1,110);
IPAddress gateway(192,168,1,254);
IPAddress subnet(255,255,255,0); 
ESP8266WebServer server(80);

void reconnect(){
  WiFi.disconnect(true);
  delay(100);
  Serial.print(WiFi.softAP(ssid,password)? "Wifi Connected" : "Not Connected");
  delay(100);
  WiFi.softAPConfig(ip,gateway,subnet);
  Serial.print(WiFi.softAPIP());  
}

void setup() {
  // Initialize serial port
  Serial.begin(115200);
   // Initialise I2C communication as MASTER
  while (!Serial) continue;
  Wire.begin(2,14);
  reconnect();
   // Start to listen
  server.begin();
  server.on("/",jsonRoot);
}

void loop() {
sht31();
server.handleClient(); 
}

void jsonRoot(){

  server.send(200,"application/json",Buff());
  
}
String Buff(){
DynamicJsonBuffer jsonBuffer;
   //StaticJsonBuffer<300> jsonBuffer;
JsonObject& root =jsonBuffer.createObject();
root["device"] = "Huzzah Board";
root["sensorType"] = "SHT31";
JsonArray& temp = root.createNestedArray("temp");
temp.add(String(cTemp,2));
temp.add(String(fTemp,2));
temp.add(String(humidity,2));
String JSON;
root.printTo(Serial);
root.prettyPrintTo(JSON);
return JSON;
  
}

void sht31()
{
  unsigned int data[6];

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Send 16-bit command byte
  Wire.write(0x2C);
  Wire.write(0x06);
  // Stop I2C transmission
  Wire.endTransmission();
  delay(300);

  // Start I2C Transmission
  Wire.beginTransmission(Addr);
  // Stop I2C Transmission
  Wire.endTransmission();

  // Request 6 bytes of data
  Wire.requestFrom(Addr, 6);

  // Read 6 bytes of data
  // temp msb, temp lsb, temp crc, hum msb, hum lsb, hum crc
  if (Wire.available() == 6)
  {
data[0] = Wire.read();
data[1] = Wire.read();
data[2] = Wire.read();
data[3] = Wire.read();
data[4] = Wire.read();
data[5] = Wire.read();
  }
  // Convert the data
  int temp = (data[0] * 256) + data[1];
  float ctemp = -45.0 + (175.0 * temp / 65535.0);
  float ftemp = (cTemp * 1.8) + 32.0;
  float humid = (100.0 * ((data[3] * 256.0) + data[4])) / 65535.0;

  // Output data to serial monitor
  Serial.print("Temperature in Celsius :");
  Serial.print(ctemp);
  Serial.println(" C");
  Serial.print("Temperature in Fahrenheit :");
  Serial.print(ftemp);
  Serial.println(" F");
  Serial.print("Relative Humidity :");
  Serial.print(humid);
  Serial.println(" %RH");
  delay(500);

   cTemp = ctemp;
   fTemp = ftemp ;
  humidity = humid;
  
}

```

and getting the reply on my web browser like this

 ![1%20more](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f67de676c5a50ace0efe8179d8b4a14c4aaaed15.png)

but even after using the HTTP request and mentioned URL details and connected with debug node, I am still not able to receive the data

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [30 January 2019 08:21 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/4 "2019-01-30T08:21:24Z")

</div>

What does your flow look like? If you can load the data in your browser then, assuming Node-RED is running on the same network as your device, then it will be able to get the data with the HTTP Request node.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [30 January 2019 08:49 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/5 "2019-01-30T08:49:43Z")

</div>

You also need an inject node to trigger the request node to do the request.

---

<div class="post-metadata">

**Author:** ![Andrei](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/andrei/32/10446_2.png) [@Andrei](https://discourse.nodered.org/u/Andrei)\
**Post date:** [30 January 2019 10:18 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/6 "2019-01-30T10:18:19Z")

</div>

I don´t know how the ESP webserver works. Having a look on your code my guess is that the statement `server.on("/",jsonRoot);` is where you define an endpoint. My suggestion is to change this to something like `server.on("/mything",jsonRoot);` . In Node-RED your flow will have only three nodes. The http request should be configured like below:

 ![r-01](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/223da0f3803dc1c8746c40686e5b64d3dda1c05d.png)

 ![r-02](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/313f57edf17f369ce293a6f38177abc9221661f4.png)

---

<div class="post-metadata">

**Author:** ![Varul92](https://avatars.discourse-cdn.com/v4/letter/v/b4bc9f/32.png) [@Varul92](https://discourse.nodered.org/u/Varul92)\
**Post date:** [30 January 2019 11:07 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/7 "2019-01-30T11:07:18Z")

</div>

@knolleary and @Andrei  
I have connected the ESP8266 in local wifi and I have hosted a web page on the same network, so my device webpage and node red are on the same network (Local Wifi).  
Further, I have created a flow with HTTP request node, Now I want a response from the webpage in the node-red flow.

 ![1%20more](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/30baff7e61401dfdfdb6d0c3197627f864197184.png) ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/21da9be0f4a800f4b79af2d1583bc82548fec658.png)

I am a bit confused about which IP should I use in URL option

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [30 January 2019 11:12 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/8 "2019-01-30T11:12:56Z")

</div>

You want Node-RED to load the webpage from your ESP8266, you need the IP address of your ESP8266. As you are currently serving it as it's root page you should only need the IP address. So I would start by copying what worked for you in your browser when you connected to the ESP8266.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [30 January 2019 11:17 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/9 "2019-01-30T11:17:44Z")

</div>

Just to be as clear as possible...

In the screenshot of your browser showing the data from the ESP, you used the address `http://192.168.1.29/root` to access it. That is _exactly_ the address you'd put the url field of the HTTP Request node.

---

<div class="post-metadata">

**Author:** ![Varul92](https://avatars.discourse-cdn.com/v4/letter/v/b4bc9f/32.png) [@Varul92](https://discourse.nodered.org/u/Varul92)\
**Post date:** [30 January 2019 13:34 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/10 "2019-01-30T13:34:58Z")

</div>

With the help of `inject` node, I am able to read the sensor data.  
But is there any other way which automatically get the response from the webpage?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [30 January 2019 13:42 UTC](https://discourse.nodered.org/t/how-to-display-localhost-server-in-node-red/7368/11 "2019-01-30T13:42:43Z")

</div>

It depends what you mean by "automatically"

If you wish to use a web server on your ESP8266, you could set the `inject` node to **repeat** at an interval for example each minute

But it's really what MQTT is very good at, but for whatever reason you have ruled that out.
