Read and Write at the same time

Hi every body,
I can send data to my data base and read it from the arduino, but i search to use them at the same time, if you can help me please

It's the code for send

// On construit l'en-tete de la requete
client.print("GET /enregistrer.php/?analog1="); //attention, pas de saut de ligne !
client.print(analogRead(A1));
client.print("&analog2=");
client.print(analogRead(A2));
client.print("&millis=");
client.print(millis());
// On finit par le protocole
client.println(" HTTP/1.1"); //ce coup-ci, saut de ligne pour valider !
// on aurait alors :
// "GET /enregistrer.php/?analog1=<valeur-de-A1>&analog2=<valeur-de-A2>&millis=<valeur-de-millis()> HTTP/1.1"
client.println("Host: mapageweb.com");
client.println("Connection: close");
client.println();

download

/*  
lire un fichier net avec une info
basé sur le script de tweet de Tom Igoe

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

This code is in the public domain.

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
IPAddress ip(192,168,1,20);

// initialize the library instance:
EthernetClient client;

const unsigned long requestInterval = 60000;  // delay between requests

char serverName[] = "www.codedrops.net";

boolean requested;                   // whether you've made a request since connecting
unsigned long lastAttemptTime = 0;   // last time you connected to the server, in milliseconds

String currentLine = "";            // string to hold the text from server
String message = "";                  // string to hold the message
boolean lecture = false;       // if you're currently reading the message

void setup() {
 // reserve space for the strings:
 currentLine.reserve(256);
 message.reserve(150);

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

 // attempt a DHCP connection:
 Serial.println("Attempting to get an IP address using DHCP:");
 if (!Ethernet.begin(mac)) {
   // if DHCP fails, start with a hard-coded address:
   Serial.println("failed to get an IP address using DHCP, trying manually");
   Ethernet.begin(mac, ip);
 }
 Serial.print("Mon adresse:");
 Serial.println(Ethernet.localIP());
 // premiere connection :
 connectToServer();
}

void loop(){
 if(message.length() > 0 && lecture==false){
   Serial.print("je viens de recevoir un message : ");
  Serial.println(message);
 message=""; 
 }
 
 if (client.connected()) {
   checke_page(); 
 }
 else if (millis() - lastAttemptTime > requestInterval) {
   // if you're not connected, and two minutes have passed since
   // your last connection, then attempt to connect again:
   connectToServer();
 } 
}

void checke_page(){
 if (client.available()) {
   // read incoming bytes:
   char inChar = client.read();

   // add incoming byte to end of line:
   currentLine += inChar; 

   // si on a un retour chariot, c'est que ce n'est pas encore le debut, on supprime:
   if (inChar == '\n') {
     currentLine = "";
   } 

   // si on trouve le message <text>, c'est 
   // que le message suit:
   if ( currentLine.endsWith("<info>")) {

     // debut du message, on vide la string message:
     lecture = true; 
     message = "";
     inChar = client.read(); // lire le caractere suivant
   }
   // on lit caractere par caractere,
   // et les ajoute au message
   if (lecture) {
     if (inChar != '<') {
       message += inChar;
     } 
     else {
       // isi vous avez un "<",
       // c'est la fin du message:
       lecture = false;
          
       // fermer la connexion au serveur:
       client.stop(); 
     }
   }
 }
}

void connectToServer() {
 // attempt to connect, and wait a millisecond:
 Serial.println("connecting to server...");
 if (client.connect(serverName, 80)) {
   Serial.println("making HTTP request...");
   // make HTTP GET request:
   client.println("GET /sandbox/writefile/update.php HTTP/1.1");
   client.println("Host: www.codedrops.net");
   client.println();
 }
 // remettre le compteur a zero pour la prochaine connexion:
 lastAttemptTime = millis();
}

How to use the at the same time. please help

ndimby:
How to use the at the same time. please help

How to do what at the same time?
Please explain what you want to achieve in more detail.

I wonder if the demo several things at a time would be useful

...R

i want to send and receive data on my php server, in one request i want to be able to write in my database and download data

How to add 2 differents GET in one arduino sketch, 'cause it don't work on mine arduino please help
i want to get gifferents PHP page

I wonder if you mean that you would like to have two functions in your Arduino code - one of them accesses WebPageA and the other accesses WePageB ?

That should be perfectly feasible.

You may get some ideas for program organization in planning and implementing a program
...R

the problem is that both GET never connect together in the same program or one or the other function and the other can not connect. or separate they work well ie in two different sketch. I would like if possible and if you have, see a code where there are 2 GET walking together.
I think that there is interference between the two GET and this is where I would get help.
thank you in advance

ndimby:
the problem is that both GET never connect together in the same program or one or the other function and the other can not connect. or separate they work well ie in two different sketch.

Post the code that you are talking about - with the two GET functions. I'm afraid I cannot make sense of your description.

...R

/*  
lire un fichier net avec une info
basé sur le script de tweet de Tom Igoe

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

This code is in the public domain.

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

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
IPAddress ip(192,168,1,20);

// initialize the library instance:
EthernetClient client;

const unsigned long requestInterval = 60000;  // delay between requests

char serverName[] = "www.codedrops.net";

boolean requested;                   // whether you've made a request since connecting
unsigned long lastAttemptTime = 0;   // last time you connected to the server, in milliseconds

String currentLine = "";            // string to hold the text from server
String message = "";                  // string to hold the message
boolean lecture = false;       // if you're currently reading the message

void setup() {
 // reserve space for the strings:
 currentLine.reserve(256);
 message.reserve(150);

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

 // attempt a DHCP connection:
 Serial.println("Attempting to get an IP address using DHCP:");
 if (!Ethernet.begin(mac)) {
   // if DHCP fails, start with a hard-coded address:
   Serial.println("failed to get an IP address using DHCP, trying manually");
   Ethernet.begin(mac, ip);
 }
 Serial.print("Mon adresse:");
 Serial.println(Ethernet.localIP());
 // premiere connection :
 connectToServer();
}

void loop(){
 
  send_data();
 if(message.length() > 0 && lecture==false){
   Serial.print("je viens de recevoir un message : ");
  Serial.println(message);
 message=""; 
 }
 
 if (client.connected()) {
   checke_page(); 
 }
 else if (millis() - lastAttemptTime > requestInterval) {
   // if you're not connected, and two minutes have passed since
   // your last connection, then attempt to connect again:
   connectToServer();
 } 
}

void checke_page(){
 if (client.available()) {
   // read incoming bytes:
   char inChar = client.read();

   // add incoming byte to end of line:
   currentLine += inChar; 

   // si on a un retour chariot, c'est que ce n'est pas encore le debut, on supprime:
   if (inChar == '\n') {
     currentLine = "";
   } 

   // si on trouve le message <text>, c'est 
   // que le message suit:
   if ( currentLine.endsWith("<info>")) {

     // debut du message, on vide la string message:
     lecture = true; 
     message = "";
     inChar = client.read(); // lire le caractere suivant
   }
   // on lit caractere par caractere,
   // et les ajoute au message
   if (lecture) {
     if (inChar != '<') {
       message += inChar;
     } 
     else {
       // isi vous avez un "<",
       // c'est la fin du message:
       lecture = false;
          
       // fermer la connexion au serveur:
       client.stop(); 
     }
   }
 }
}

   void send_data(){
   if (client.connect(serverName, 80))
   {
  // On construit l'en-tete de la requete
client.print("GET /enregistrer.php/?analog1="); //attention, pas de saut de ligne !
client.print(analogRead(A1));
client.print("&analog2=");
client.print(analogRead(A2));
client.print("&millis=");
client.print(millis());
// On finit par le protocole
client.println(" HTTP/1.1"); //ce coup-ci, saut de ligne pour valider !
// on aurait alors :
// "GET /enregistrer.php/?analog1=<valeur-de-A1>&analog2=<valeur-de-A2>&millis=<valeur-de-millis()> HTTP/1.1"
client.println("Host: mapageweb.com");
client.println("Connection: close");
client.println();
}
  if (!client.connected())
  {
    Serial.println();
    client.stop();

    // do nothing forevermore:

  }
  
  if (client.connected()) 
  {
    Serial.println();
    client.stop();

    // do nothing forevermore:

  }
}

void connectToServer() {
 // attempt to connect, and wait a millisecond:
 Serial.println("connecting to server...");
 if (client.connect(serverName, 80)) {
   Serial.println("making HTTP request...");
   // make HTTP GET request:
   client.println("GET /sandbox/writefile/update.php HTTP/1.1");
   client.println("Host: www.codedrops.net");
   client.println();
 }
 // remettre le compteur a zero pour la prochaine connexion:
 lastAttemptTime = millis();
}

it's on my first post. send_data is use to send data on the php and chake_page for downloading

If I understand correctly both of the functions sendData() and checke_page() work properly if you only use one of them.

Does that mean that the code in Reply #7 would work properly if either lines 60 to 65 or lines 67 to 74 are commented out - please try both.

If the code will not work as I suggest then please post the two complete programs (for sending data and checking a page) that do work properly so we can see where they differ from the code in Reply #7

...R