aurduino+website

i want to do two applications

1)displaying temparaure and pressure values on website

2)displaying text on lcd whatever i typed on website.]
i have codes individually but when i try to combine its displaying temparature and pressure values as zero.

as due length problem i am posting codes individually and i am attaching combined code in attachments can anyone help to modify the code

#include <SFE_BMP180.h>
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
SFE_BMP180 pressure;
#define ALTITUDE 1655.0
Servo myservo;

byte mac[] = { 0x98, 0x4F, 0xEE,0x01, 0x65, 0x4E };
IPAddress ip(192,168,19,170);


//EthernetServer server(80);
//int i=0;
//int j=0;
//int counter=0;
//int count=0;
//int temp,t1,t2;
//int mincount=0;
char server[] = "192.168.19.171"; // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie. "www.yourwebpage.com")

// Initialize the Ethernet server library
EthernetClient client;


void setup() {
 
  pressure.begin();
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // Serial.begin starts the serial connection between computer and Arduino
  
 
  // start the Ethernet connection
  Ethernet.begin(mac,ip);
    
}

void loop() {
 
   char status;
 double T,P,p0,a;
 
   status = pressure.startTemperature();
         
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);

    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.

    status = pressure.getTemperature(T);
    if (status != 0)
    {
      

      status = pressure.startPressure(3);
      if (status != 0)
      {
         //a = pressure.altitude(P,p0);
        // Wait for the measurement to complete:
        delay(status);

        

        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          // Print out the measurement:
          
          
 p0 = pressure.sealevel(P,ALTITUDE);
 a = pressure.altitude(P,p0);
         
          
        
      }
    }
  }
  }
 
  if (client.connect(server, 80)) 
  {
    Serial.println("Connection: done");
    
client.print("GET /smart/data.php?T=");// This
    client.print(T);
     client.print("&");
     client.print("P=");
     client.print(P);
    
     client.print("&");
     client.print("H=");
     client.print(a);
    
    //client.println(); 
  //client.print("GET /smart/data.php?T=");// This
    //client.print(T);
 


   //  client.print("P");
   client.println(" HTTP/1.0"); // Part of the GET request
   client.println("Host:192.168.19.171"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
   //client.println( "Content-Type: application/x-www-form-urlencoded" );
client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();    // Closing connection to server
  }

  else {
    // If Arduino can't connect to the server (your computer or web page)
    Serial.println("--> connection failed\n");
  }
 
  // Give the server some time to recieve the data and store it. I used 10 seconds here. Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.
  delay(1000);
}#include <SFE_BMP180.h>
#include <Wire.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Servo.h>
SFE_BMP180 pressure;
#define ALTITUDE 1655.0
Servo myservo;

byte mac[] = { 0x98, 0x4F, 0xEE,0x01, 0x65, 0x4E };
IPAddress ip(192,168,19,170);


//EthernetServer server(80);
//int i=0;
//int j=0;
//int counter=0;
//int count=0;
//int temp,t1,t2;
//int mincount=0;
char server[] = "192.168.19.171"; // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie. "www.yourwebpage.com")

// Initialize the Ethernet server library
EthernetClient client;


void setup() {
 
  pressure.begin();
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  // Serial.begin starts the serial connection between computer and Arduino
  
 
  // start the Ethernet connection
  Ethernet.begin(mac,ip);
    
}

void loop() {
 
   char status;
 double T,P,p0,a;
 
   status = pressure.startTemperature();
         
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);

    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.

    status = pressure.getTemperature(T);
    if (status != 0)
    {
      

      status = pressure.startPressure(3);
      if (status != 0)
      {
         //a = pressure.altitude(P,p0);
        // Wait for the measurement to complete:
        delay(status);

        

        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          // Print out the measurement:
          
          
 p0 = pressure.sealevel(P,ALTITUDE);
 a = pressure.altitude(P,p0);
         
          
        
      }
    }
  }
  }
 
  if (client.connect(server, 80)) 
  {
    Serial.println("Connection: done");
    
client.print("GET /smart/data.php?T=");// This
    client.print(T);
     client.print("&");
     client.print("P=");
     client.print(P);
    
     client.print("&");
     client.print("H=");
     client.print(a);
    
    //client.println(); 
  //client.print("GET /smart/data.php?T=");// This
    //client.print(T);
 


   //  client.print("P");
   client.println(" HTTP/1.0"); // Part of the GET request
   client.println("Host:192.168.19.171"); // IMPORTANT: If you are using XAMPP you will have to find out the IP address of your computer and put it here (it is explained in previous article). If you have a web page, enter its address (ie.Host: "www.yourwebpage.com")
   //client.println( "Content-Type: application/x-www-form-urlencoded" );
client.println("Connection: close"); // Part of the GET request telling the server that we are over transmitting the message
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();    // Closing connection to server
  }

  else {
    // If Arduino can't connect to the server (your computer or web page)
    Serial.println("--> connection failed\n");
  }
 
  // Give the server some time to recieve the data and store it. I used 10 seconds here. Be advised when delaying. If u use a short delay, the server might not capture data because of Arduino transmitting new data too soon.
  delay(1000);
}

[code]

Please use code tags (</> button on the toolbar) when you post code or warning/error messages. The reason is that the forum software can interpret parts of your code as markup, leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier to read your code and to copy it to the IDE or editor. Using code tags and other important information is explained in the How to use this forum post. Please read it.

Please always do a Tools > Auto Format on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

below is the code for sending text from website to lcd

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
#include "rgb_lcd.h"
#include <Wire.h>
rgb_lcd lcd;

#define REQ_BUF_SZ   90

#define LCD_BUF_SZ   17


byte mac[] = { 
  0x98, 0x4F, 0xEE,0x01, 0x65, 0x4E };
IPAddress ip(192,168,19,170);
String readString;



EthernetServer server(80);      // create a server at port 80
File webFile;                    // the web page file on the SD card
char HTTP_req[REQ_BUF_SZ] = {0}; // buffered HTTP request stored as null terminated string
char req_index = 0;              // index into HTTP_req buffer
char lcd_buf_1[LCD_BUF_SZ] = {0};// buffer to save LCD line 1 text to
char lcd_buf_2[LCD_BUF_SZ] = {0};// buffer to save LCD line 2 text to
//LiquidCrystal lcd(3, 2, 8, 7, 6, 5);

void setup()
{
    // disable Ethernet chip
    pinMode(10, OUTPUT);
    digitalWrite(10, HIGH);
    
    Serial.begin(115200);       // for debugging

    lcd.begin(16, 2);
    // Message on LCD
    lcd.print(F("Initializing"));
    
    // initialize SD card
    Serial.println("Initializing SD card...");
    if (!SD.begin(4)) {
        Serial.println("ERROR - SD card initialization failed!");
        lcd.print(F("SD init failed"));
        return;    // init failed
    }
    Serial.println("SUCCESS - SD card initialized.");
    // check for index.htm file
    if (!SD.exists("index.htm")) {
        Serial.println("ERROR - Can't find index.htm file!");
        return;  // can't find index file
    }
    Serial.println("SUCCESS - Found index.htm file.");

    Ethernet.begin(mac, ip);  // initialize Ethernet device
    server.begin();           // start to listen for clients

    // End of initialization message on LCD + print IP address
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print(F("Done."));
    lcd.setCursor(0, 1);
    lcd.print(ip);
}

void loop()
{
    EthernetClient client = server.available();  // try to get client

    if (client) {  // got client?
        boolean currentLineIsBlank = true;
        while (client.connected()) {
            if (client.available()) {   // client data available to read
                char c = client.read(); // read 1 byte (character) from client
                // limit the size of the stored received HTTP request
                // buffer first part of HTTP request in HTTP_req array (string)
                // leave last element in array as 0 to null terminate string (REQ_BUF_SZ - 1)
                if (req_index < (REQ_BUF_SZ - 1)) {
                    HTTP_req[req_index] = c;          // save HTTP request character
                    req_index++;
                }
                // last line of client request is blank and ends with \n
                // respond to client only after last line received
                if (c == '\n' && currentLineIsBlank) {
                    // send a standard http response header
                    client.println("HTTP/1.1 200 OK");
                    // remainder of header follows below, depending on if
                    // web page or XML page is requested
                    // Ajax request - send XML file
                    if (StrContains(HTTP_req, "ajax_inputs")) {
                        // send rest of HTTP header
                        client.println("Content-Type: text/xml");
                        client.println("Connection: keep-alive");
                        client.println();

                        // print the received text to the LCD if found
                        if (GetLcdText(lcd_buf_1, lcd_buf_2, LCD_BUF_SZ)) {
                          // lcd_buf_1 and lcd_buf_2 now contain the text from
                          // the web page
                          // write the received text to the LCD
                          lcd.clear();
                          lcd.setCursor(0, 0);
                          lcd.print(lcd_buf_1);
                          lcd.setCursor(0, 1);
                          lcd.print(lcd_buf_2);
                        }
                    }
                    else {  // web page request
                        // send rest of HTTP header
                        client.println("Content-Type: text/html");
                        client.println("Connection: keep-alive");
                        client.println();
                        // send web page
                        webFile = SD.open("index.htm");        // open web page file
                        if (webFile) {
                            while(webFile.available()) {
                                client.write(webFile.read()); // send web page to client
                            }
                            webFile.close();
                        }
                    }
                    // reset buffer index and all buffer elements to 0
                    req_index = 0;
                    StrClear(HTTP_req, REQ_BUF_SZ);
                    break;
                }
                // every line of text received from the client ends with \r\n
                if (c == '\n') {
                    // last character on line of received text
                    // starting new line with next character read
                    currentLineIsBlank = true;
                } 
                else if (c != '\r') {
                    // a text character was received from client
                    currentLineIsBlank = false;
                }
            } // end if (client.available())
        } // end while (client.connected())
        delay(1);      // give the web browser time to receive the data
        client.stop(); // close the connection
    } // end if (client)
}

// get the two strings for the LCD from the incoming HTTP GET request
boolean GetLcdText(char *line1, char *line2, int len)
{
  boolean got_text = false;    // text received flag
  char *str_begin;             // pointer to start of text
  char *str_end;               // pointer to end of text
  int str_len = 0;
  int txt_index = 0;
  char *current_line;

  current_line = line1;

  // get pointer to the beginning of the text
  str_begin = strstr(HTTP_req, "&L1=");

  for (int j = 0; j < 2; j++) { // do for 2 lines of text
    if (str_begin != NULL) {
      str_begin = strstr(str_begin, "=");  // skip to the =
      str_begin += 1;                      // skip over the =
      str_end = strstr(str_begin, "&");

      if (str_end != NULL) {
        str_end[0] = 0;  // terminate the string
        str_len = strlen(str_begin);

        // copy the string to the buffer and replace %20 with space ' '
        for (int i = 0; i < str_len; i++) {
          if (str_begin[i] != '%') {
            if (str_begin[i] == 0) {
              // end of string
              break;
            }
            else {
              current_line[txt_index++] = str_begin[i];
              if (txt_index >= (len - 1)) {
                // keep the output string within bounds
                break;
              }
            }
          }
          else {
            // replace %20 with a space
            if ((str_begin[i + 1] == '2') && (str_begin[i + 2] == '0')) {
              current_line[txt_index++] = ' ';
              i += 2;
              if (txt_index >= (len - 1)) {
                // keep the output string within bounds
                break;
              }
            }
          }
        } // end for i loop
        // terminate the string
        current_line[txt_index] = 0;
        if (j == 0) {
          // got first line of text, now get second line
          str_begin = strstr(&str_end[1], "L2=");
          current_line = line2;
          txt_index = 0;
        }
        got_text = true;
      }
    }
  } // end for j loop

  return got_text;
}

// sets every element of str to 0 (clears array)
void StrClear(char *str, char length)
{
    for (int i = 0; i < length; i++) {
        str[i] = 0;
    }
}

// searches for the string sfind in the string str
// returns 1 if string found
// returns 0 if string not found
char StrContains(char *str, char *sfind)
{
    char found = 0;
    char index = 0;
    char len;

    len = strlen(str);
    
    if (strlen(sfind) > len) {
        return 0;
    }
    while (index < len) {
        if (str[index] == sfind[found]) {
            found++;
            if (strlen(sfind) == found) {
                return 1;
            }
        }
        else {
            found = 0;
        }
        index++;
    }

    return 0;
}

my combined code.txt (10.8 KB)

Prudhvi:
i want to do two applications

I want...

you to 'edit/modify' your first post by hitting the modify button on the bottom right of the post

once on the edit screen
at the start of your code

type in a left bracket "[" followed by the word code and then close that bracket

then at then end of your code, do the same thing, but this time use /code inside of the brackets.

The first code has the Arduino acting as a client, making GET requests to a server.

The second has the Arduino acting as a server, responding to GET requests from clients.

While the Arduino can operate as client and server, it has limited memory, so it is limited in the amount of data it can serve up.

What have you tried in terms of combining the two sketches?