Arduino read value from local server webpage and write on LCD

Hi !
I want to do a project, where Arduino reads value from local webpage server, and write it to LCD display.

Here is my example:

Local web page is “LAN CONTROLLER” and have ip 192.168.5.100 without User/pass and show me web page with different values. ( screenshot in attavhments )
In my case value is Temperature.

I want to arduino read tamperature value and write to lcd display.

Is this possible ?
Can you help me please?

I forgot to write :confused: ....

I have : -Arduino uno -Ethernet shield -lcd display

Sure, that's called screen scraping (assuming it's plain HTML and not a Java applet or flash or something painting that page - feels like plain HTML from 10 years ago though from the look of it)

just send the http request for that page, you'll receive the flow of HTML data that you need to parse on the fly - so look at how your page is coded in HTML, identify what comes in just before your values, look for that and extract the value

Are you on windows or Mac/Linux?

If on unix system, just type curl 192.168.5.100 in a terminal and you'll see the plain HTML coming in. (alternatively your browser probably has a menu to show page source code - copy that and look at it or post it here and we will help point out where things are if needed)

Im on Windows 10.... Can you send me example code ?

THX

This is my page code on 192.168.5.100

Thanks for help

Lan kotroler izvorna koda.txt (13 KB)

Perhaps you should rename that file to have an htm or html extension, and paste it in a browser. Is the data there that you want?

unfortunately the data comes from Ajax calls - and not there as plain text - it's dynamically filled in. So you need to play with the .cgi and see what you get

Does anyone have any example code?

What do I actually am looking for? Arduino ajax calls ? screen scraping ?

PAULS this is just copy-paste source code from chrome in my home page of lan controller 192.168.5.100

If it more easily i can use two arduino.... One have web server on 192.168.5.91 and read temperature and write to web server...

On www page from arduino 192.168.5.91 have :

Temperatura Head: [50.44] ° C Temperatura Water: [60.422] ° C

.... and now how second arduino with 191.168.5.90 read this from first and write me to LCD or serial monitor?

J-M-L : and this is my page source code

<font color=black size=7>

<font color=black size=7>Temperatura pri kurah: [11.56] °
C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Temperatura v kurilnici: [13.50] °
C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Temperatura v garazi: [13.00] °
C
<font color=green size=7>

That page has the temperature info built in, so that is easy to parse. Get a web client object, send a request, read lines (cf the serial basics parsing examples) and extract the value.

Thankyou

I’ll try to find sample code for this… :o

I am a beginner and still learn. :confused:

I want to display on the screen in the apartment temperature of central heading- wood stove, Water heater and temperature of pipes.
Now i can read only on www, but this is not for my wife 8)

Unfortunately, but the distance is too big to pull cable for sensors and connest to arduino in apartment. :blush:

For now i created project for reading 6 DS18B20 temp. sensors and one DHT22, write temperature
to web page, write to lcd and connect web page with paesler network monitor, so i have monitoring and
phone gaguges on mobile phone and tablet. :smiley: :smiley:
Super for 40 years boy :slight_smile: hahaha

Regards…

if someone have code for me, I’m very grateful…

can you make a request to the server from one arduino that will return this?

<font color=black size=7>

<font color=black size=7>Temperatura pri kurah: [11.56] °C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Temperatura v kurilnici: [13.50] °C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Temperatura v garazi: [13.00] °C
<font color=green size=7>

?

Sorry, I do not know how. Example code I can not find.

Can you please help me ?

Thankyou

Regards

Now i can see this in my serial.

With this code:

/*
  Web client

 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe, based on work by Adrian McEwen

 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x84, 0x42, 0x8B, 0xBA, 0xB2, 0x31 }; //mac address of ethernet shield
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(192,168,5,91);  // numeric IP for Google (no DNS)
//char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 5, 92);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}

i see this in serial monitor :

connecting...
connected
HTTP/1.1 200 OK
Content-Type: text/html
Connection: close
Refresh: 5

<font color=black size=7>Senzorji DS18B20<font color=black size=7>

<font color=black size=7>Temperatura pri kurah: [5.06] °
C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Temperatura v kurilnici: [9.88] °
C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Temperatura v garazi: [6.63] °
C
<font color=black size=7>



Senzor DHT22<font color=black size=7>

<font color=black size=7>Temperatura v garazi: [nan] °
C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Vlaga v garazi: [nan] %
<font color=green size=7>
disconnecting.

How now extract this value [6.63] and show in LCD ?

I use some sketch for lcd

Like this :

void loop() {
  delay(250);
  //float h = dht.readHumidity();
  //float t = dht.readTemperature();
  float temp1 = sensors.getTempC(Thermometer1); //Kurilnica
  float temp2 = sensors.getTempC(Thermometer2); //Peč
  float temp3 = sensors.getTempC(Thermometer3); //Dovod
  float temp4 = sensors.getTempC(Thermometer4); //Povratek

   //prints sensor output to lcd and serial monitor

// LCD 1
    //lcd1.clear();
    // prva vrsta 
    lcd1.setCursor(0, 0);
    lcd1.print("PIN8/PEC:");
    lcd1.setCursor(13, 0);
    lcd1.print(temp2);
    
    
    // druga vrsta
    lcd1.setCursor(0, 1);
    lcd1.print("DOVOD:");
    lcd1.setCursor(13, 1);
    lcd1.print(temp3);
    // tretja vrsta
    lcd1.setCursor(0, 2);
    lcd1.print("POVARETEK:");
    lcd1.setCursor(13, 2);
    lcd1.print(temp4);
    // četrta vrsta
    lcd1.setCursor(0, 3);
    lcd1.print("KURILNICA:");
    lcd1.setCursor(13, 3);
    lcd1.print(temp1);

    
// LCD 2
   // lcd2.clear();
    // prva vrsta 
    lcd2.setCursor(0, 0);
    lcd2.print("PIN8/PEC:");
    lcd2.setCursor(13, 0);
    lcd2.print(temp2);
    
    
    // druga vrsta
    lcd2.setCursor(0, 1);
    lcd2.print("DOVOD:");
    lcd2.setCursor(13, 1);
    lcd2.print(temp3);
    // tretja vrsta
    lcd2.setCursor(0, 2);
    lcd2.print("POVRATEK:");
    lcd2.setCursor(13, 2);
    lcd2.print(temp4);
    // četrta vrsta
    lcd2.setCursor(0, 3);
    lcd2.print("KURILNICA:");
    lcd2.setCursor(13, 3);
    lcd2.print(temp1);

Thankyou for help…

  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

You need to do more than just print them. You need to save them, starting when the [ arrives, and stopping, and using the data, when the ] arrives.

char theBuffer[20];
byte theIndex = 0;

theBuffer[theIndex] = '\0';

bool saving = false;

  if (client.available() > 0)
  { // Down here where the damned thing belongs
     while(client.available() > 0)
     {
       char c = client.read();
       Serial.print(c);
       if(c == '[')
          saving = true;
       else if(c == ']')
       {
          // Show the data in theBuffer somewhere

          theIndex = 0;
          theBuffer[theIndex] = '\0';

          saving = false;
       }
       else if(saving)
       {
          theBuffer[theIndex++] = c;
          theBuffer[theIndex] = '\0';
       }
    }
  }

I change CODE but in serial monitor is the same…

CODE

/*
  Web client

 This sketch connects to a website (http://www.google.com)
 using an Arduino Wiznet Ethernet shield.

 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13

 created 18 Dec 2009
 by David A. Mellis
 modified 9 Apr 2012
 by Tom Igoe, based on work by Adrian McEwen

 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x84, 0x42, 0x8B, 0xBA, 0xB2, 0x31 }; //mac address of ethernet shield
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress server(192,168,5,91);  // numeric IP for Google (no DNS)
//char server[] = "www.google.com";    // name address for Google (using DNS)

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192, 168, 5, 92);

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: www.google.com");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
 // brišem
  // //if there are incoming bytes available
  // // from the server, read them and print them:
  //if (client.available()) {
   // char c = client.read();
   // Serial.print(c);
   //PAULS:
char theBuffer[20];
byte theIndex = 0;

theBuffer[theIndex] = '\0';

bool saving = false;

  if (client.available() > 0)
  { // Down here where the damned thing belongs
     while(client.available() > 0)
     {
       char c = client.read();
       Serial.print(c);
       if(c == '[')
          saving = true;
       else if(c == ']')
       {
          // Show the data in theBuffer somewhere

          theIndex = 0;
          theBuffer[theIndex] = '\0';

          saving = false;
       }
       else if(saving)
       {
          theBuffer[theIndex++] = c;
          theBuffer[theIndex] = '\0';
       }
    }
  }
   
  

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while (true);
  }
}

Serial monitor:

connecting...
connected
HTTP/1.1 200 OK
Content-Type: text/html
Connection: close
Refresh: 5

<font color=black size=7>Senzorji DS18B20<font color=black size=7>

<font color=black size=7>Temperatura pri kurah: [4.00] °
C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Temperatura v kurilnici: [9.38] °
C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Temperatura v garazi: [6.00] °
C
<font color=black size=7>



Senzor DHT22<font color=black size=7>

<font color=black size=7>Temperatura v garazi: [nan] °
C
<font color=green size=7><font color=black size=7>

<font color=black size=7>Vlaga v garazi: [nan] %
<font color=green size=7>
disconnecting.

I do not understand how to get the three values in brackets give them a name, and display on the LCD

How do I change the code that does not stop? To constantly read the temperature?

Regards

I try another code with “finder find”, which to me is more understandable and closer to work my project.

I use this CODE :

/*
* Based on SimpleClientGoogleWeatherDHCP - This one comes with High Temp and Current conditions data.
* gets xml data from http://www.google.com/ig/api?weather=milwaukee,wi
* reads temperature from field:  <temp_f data="66" /> 
* writes temperature  to 20x4 LCD. Using Ardiuno Mega 2640
*/

//#if ARDUINO > 18
#include <SPI.h>         // needed for Arduino versions later than 0018 
//#endif

#include <Ethernet.h>
//#include <EthernetDHCP.h>  // uses DHCP code from: http://blog.jordanterrell.com/post/Arduino-DHCP-Library-Version-04.aspx 
#include <TextFinder.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 3, 4, 5, 6);

#include <SPI.h>
#include <Ethernet.h>


byte mac[] = { 0x84, 0x42, 0x8B, 0xBA, 0xB2, 0x31 }; //mac address of ethernet shield
IPAddress server(192,168,5,91);  // numeric IP for Google (no DNS)
IPAddress ip(192, 168, 5, 92);
EthernetClient client;
TextFinder  finder( client );  
char cond[40];



void setup()
{
  
  Serial.begin(9600);
  while (!Serial) {
    
  }

  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /search?q=arduino HTTP/1.1");
    client.println("Host: 192.168.5.91");
    client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

  //pinMode(backLight, OUTPUT);
  //digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
  // onemogočam LCD ker javlja napako
  
  //lcd.begin(20,4);
  //lcd.setCursor(0,0);
  //lcd.print("I'm alive");
  //if(EthernetDHCP.begin(mac)) {
    // begin method returns 1 if successful  
    //lcd.setCursor (0,1);
    //lcd.print("got IP address, connecting...");
    //lcd.clear();
    //delay(500);  

  //else {
    //lcd.clear();
    //lcd.print("unable to acquire ip address!");
    //while(true)
      //;  // do nothing




void loop()
{
 
  if (client.connected()) {
    finder.find("Temperatura v kurilnici:");
    int temperature = finder.getValue();
    
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Temperature = ");
    lcd.print(temperature);
    delay(3000);
    Serial.println(temperature);
    
    
    lcd.setCursor(0,1);
    lcd.print("High Temp ");
    finder.find("<high data=");
    int temp = finder.getValue();
    lcd.print(temp);
    delay(3000);
    
    lcd.setCursor(0,2);
    lcd.print("Current Conditions ");
    finder.find("<condition data");
    finder.getString("=","/",cond,(40));
    lcd.setCursor(0,3);
    lcd.print(cond);

  }
  else {
    lcd.clear();
    lcd.print("Can not find xml tag");

  }
  client.stop();
  client.flush();  
  delay(4000); // wait a minute before next update
}

In serial monitor i see :

connecting...
connected
9

9 = temperature in one room

  • Why not show decimal places like 9.43 ?
  • How do I change the code that does not stop? To constantly read the temperature?
finder.find("Temperatura v kurilnici:"); // TEMP1
    int temperature = finder.getValue();

How change code for next sensors ? TEMP2 and TEMP3

    int temperature = finder.getValue();

You don't REALLY expect to see 9.43 when printing an int, do you?

  • How do I change the code that does not stop? To constantly read the temperature?

You are making one GET request. If you want to make more than one, make more than one.

You don't REALLY expect to see 9.43 when printing an int, do you?

Paul, Paul ...... Your answers are very mysterious for beginners.

Help from anyone else?