Bonjour a tous !
Je cherche un moyen de changer une valeur de Analog write juste avec une adresse URL, je m'explique:
Admettons que mon adresse internet est example.fr - Example Resources and Information.
J'aimerais que la valeur "1.45" vienne écraser et remplacer la valeur précédente sur mon analogwrite présent dans mon programme arduino.
Je vous remercie d'avance ! ![]()
voici le programme concerné en ébauche : (je sais que j'ai plein de choses inutiles et a remplacer dedans
)
#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[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(10,119,26,195);
String readString;
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
EthernetServer server(80);
float Envoi ;
//float v1= 0 ;
void setup() {
pinMode(5, OUTPUT); //pin selected to control
// 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("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//Serial.print("readString =");
//Serial.println(readString);
if (readString.length() < 100) {
// Serial.println(readString.length());
//store characters to string
readString += c;
}
/*
Serial.print("readString_length()=");
Serial.println(readString.length());
Serial.print("c=");
Serial.println(c);
Serial.print("ReadString=");
Serial.println(readString);
*/
//int indextension = readString.indexOf("Tension1=");
//Serial.println(indextension);
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// Serial.print("c=");
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
client.println("<form name=\"mon-formulaire1\" action=\"1\" method=\"get\">");
client.println("<textarea name=\"Tension1\" rows=\"2\" cols=\"4\"></textarea>");
client.println("
");
client.println("<input type=\"submit\" value=\"Envoyer\" />");
client.println("<input type=\"reset\" value=\"Annuler\" />");
client.println("</form>");
client.println("
");
client.println("</html>");
break;
}
//Serial.print(c);
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("affichage de la tension");
if(readString.indexOf("Tension1") >0) {
Serial.println("Tension 1 lue");
int pos = readString.indexOf("Tension1");
Serial.println(pos);
//String v1=" ";
//for( int i=indextension+15;i<indextension+18;++i)
// v1 = v1+readString[i];
//Serial.println(v1);
//analogWrite(6, 1023);
}
Serial.println("client disonnected");
}
}
}
}
}