Salut,
Je bosse sur une lecture de variable que j’envoie sur mon client (carte arduino) avec une méthode get :
Si quelqu’un pourrait m’éclairer, ou juste alléger le programme.
Merci d’avance
#include <Arduino.h>
#include <Ethernet2.h>
#include <SPI.h>
#include <Wire.h>
#include <SD.h>
#include "SHT31.h"
#include <String.h>
int hum = 0
int temp = 0
byte mac[] = {0x90,0xA2,0xDA,0x10,0x72,0xB5}; //L'adresse MAC de votre shield Ethernet
IPAddress ip(20,20,20,4); // @ IP du shield
EthernetServer server(80);
String readString;
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// Start the Ethernet connection and the server:
Ethernet.begin(mac,ip);
server.begin();
Serial.print("Arduino IP server: ");
Serial.println(Ethernet.localIP());
}
void loop()
{
// Create a client connection
EthernetClient client = server.available();
if (client)
{
while (client.connected())
{
if (client.available())
{
char c = client.read();
//read char by char HTTP request
if (readString.length() < 100)
{
//store characters to string
readString += c;
// Serial.println(c);
}
//if HTTP request has ended
if (c == '\n')
{
// readString.contains() replaced with readString.indexOf(val) > -1 by Katsu
// indexOf locates a character or String within another String.
// Returns the index of val within the String, or -1 if not found.
if(readString.indexOf("temp=") > -1){
char d = client.read();
Serial.println("------------------------------------------");
Serial.println("Température repérée :");
temp = cl.read()
Serial.println(temp);
}
if(readString.indexOf("hum=") > -1) {
char z = client.read();
Serial.println("Humidité repérée :");
hum = cl.read()
Serial.println(hum);
}
Serial.println("Chaîne de caractères string allignée :"); //print to serial monitor for debuging
Serial.print(readString); //print to serial monitor for debuging
Serial.println("------------------------------------------");
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta charset='UTF-8'>");
client.println("<meta http-equiv='refresh' content='5'>");
client.println("<TITLE>Temp</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("Test!!!");
client.println("</BODY>");
client.println("</HTML>");
delay(1);
//stopping client
client.stop();
//Gestion des sorties
//en fonction de readString
//...
//clearing string for next read
readString="";
}
}
}
}
}