Hi evryone!
Sorry for my bad english, i'm french student ![]()
So, i wanna collect URL information to put it on the arduino'code
Example: web URL: www.test.fr/value=1.42 I want that value (1.42) replaces the previous value present in AnalogWrite
I just want to change tension of led with webserver, for the moment, i'v create text area , when you write something on, this value go dirrectely on the URL of the website.
thank you in advance
cordially Aedriar
Extract of my actually arduino'code:
#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");
}
}
}
}
}