nodeMCU Updating Label in web server

hi guys can someone help me im new to programing and im trying to make an html that have a label where the text is updating on what the LDR is getting connected to a nodeMCU. is it possible to send data from the LDR and change the text of a html label in my phone? is there a simple code on how to do this?

It is possible to do what you want. Have you got a Webserver running on the nodeMCU serving fixed test to clients ? If so, then please post the code here. If not then please look at the examples in the IDE

i got this working in my phone it shows the webpage.

#include <ESP8266WebServer.h>
#define LDR 2

const char* ssid = "neneboots";;
const char* password = "87654321";
String notice;

ESP8266WebServer server(80);

char webpage[] = R"=(
<!DOCTYPE html>
<h3>LDR VALUE </h3>
<div><label>0.00 units</label></div>

void setup() {

  float LDRVALUE;

  //Wifi as access point__________________
  Serial.print("CONNECTING TO ");
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WIFI CONNECTED!");
  Serial.println("SERVER STARTS AT : ");
  server.on("/postForm", handlePostForm);   

void loop() {
  LDRVALUE = analogRead(LDR);

yes you can dynamically 'poll' the LDR value

all you have to do is set a timer on JS ( with setInterval() ) that repeatedly sends request to the ESP, at say

every 500 milli_secs

the response from the ESP carries the LDR value you want

see this

i got this working in my phone it shows the webpage.

Then at its simplest all you need to do is to change your webpage string at intervals and put the value of LDRVALUE in the appropriate place in the HTML code and the Webserver will serve the updated page including the value of LDRVALUE

The post convenient way to update the webpage string is probably to use the sprintf() function

sorry but do you have an example of this that i can watch? cause to be honest i still dont understand how i can do this.

sprintf() is a standard C function
Here is an example of it used to change a char array named webpage

char webpage[200];
float ldrValue;

char ldrChars[10];

void setup()
  while (!Serial);
  ldrValue = 123.45;
  ldrValue = 1023.99;

void loop()

void makePage()
  dtostrf(ldrValue, 5, 2, ldrChars);  //convert float to string for sprintf()
  sprintf(webpage, "\
  <!DOCTYPE html>\
  <h3>LDR VALUE </h3>\
  <div><label>%s</label> </div>\
  </html> ", ldrChars);