Hello! I am working on my bachelor's degree and I got stuck .
The main idea is that I have 2 sensors, one for light and another for temperature and humidity.
I have 2 different arduino scripts for each to get my readings from them into a database but I can't manage how to merge these two into a single code and have multiple http GET requests . How should I change my code? Should I esablish a new connection for each request and run them in parallel? I would be grateful if you could give me some help or some examples.
This is my code that I am trying to manage it to work right now :
//light sensor
cliente.print("GET /light/write_data.php?");
Serial.println(" light post has been made " ) ;
cliente.print("value=");
cliente.print(photocellReading); // And this is what we did in the testing section above. We are making a GET request just like we would from our browser but now with live data from the sensor
cliente.println(" HTTP/1.1");
cliente.print("GET /temp/data.php?"); //Connecting and Sending values to database
Serial.println(" temp post has been made " ) ;
cliente.print("temperature=");
cliente.print(temp);
cliente.print("&humidity=");
cliente.print(hum);
cliente.print("&heat_index=");
cliente.println(heat_indexC);
//Printing the values on the serial monitor
Serial.print("Temperature= ");
Serial.println(temp);
Serial.print("Humidity= ");
Serial.println(hum);
Serial.print("Heat Index= ");
Serial.println(heat_indexC);
cliente.stop(); //Closing the connection
}
/[code]
The code does something (besides tell the server to f**k off without reading it's reply). You need to tell us what it actually does, how that differs from what you want, and why you don't bother reading the server's reply.
basket777: @ieee488
because I have 2 different php scripts that get the data from my arduino . Or should I use a post request?
I am relatively new working with these kind of requests.
@PaulS
How should I read the server's reply ?
You are sending one script 3 pieces of data, already. Sending 4 won't make that much difference.
Look at EXACTLY what goes into the first GET request, all the way to the carriage return/line feed. Look at EXACTLY what goes into the second GET request, all the way to the carriage return/line feed. See the difference?
Look at the client example, that makes a GET request to google. It would be silly to do that without reading the response. Look at how that is done.