Avis sur fonction de ce shield

Bonjour à tous,

Pourriez-vous me donner la fonction de ce shield:

https://github.com/evothings/evothings-examples/blob/master/resources/arduino/arduinoethernet/arduinoethernet.ino

/*
Arduino Ethernet Script Server
Created Mars 4, 2014
Mikael Kindborg, Evothings AB
TCP socket server that accept commands for basic scripting
of the Arduino board.
This example is written for use with an Ethernet shield.
The API consists of the requests listed below.
Requests and responses end with a new line.
The input parameter n is a pin number ranging from 2 to 9.
The response is always a 4-character string with a
hex encoded number ranging from 0 to FFFF.
Possible response string values:
H (result from digital read)
L (result from digital read)
0 to 1023 - Analog value (result from analog read)
Set pin mode to OUTPUT for pin n: On
Response: None
Example: O5
Note: O is upper case letter o, not digit zero (0).
Set pin mode to INPUT for pin n: In
Response: None
Example: I5
Write LOW to pin n: Ln
Response: None
Example: L5
Write HIGH to pin n: Hn
Response: None
Example: H5
READ pin n: Rn
Response: "H" (HIGH) or "L" (LOW)
Example: R5 -> H
ANALOG read pin n: An
Response: int value as string (range "0" to "1023")
Example: A5 -> 42
*/

// Include files.
#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address for your controller below, usually found on a sticker
// on the back of your Ethernet shield.
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0xD0, 0x93 };

// The IP address will be dependent on your local network.
// If you have IP network info, uncomment the lines starting
// with IPAddress and enter relevant data for your network.
// If you don't know, you probably have dynamically allocated IP adresses, then
// you don't need to do anything, move along.
// IPAddress ip(192,168,1, 177);
// IPAddress gateway(192,168,1, 1);
// IPAddress subnet(255, 255, 255, 0);

// Create a server listening on the given port.
EthernetServer server(3300);

void setup()
{
	// Start serial communication with the given baud rate.
	// NOTE: Remember to set the baud rate in the Serial
	// monitor to the same value.
	Serial.begin(9600);

	// Wait for serial port to connect. Needed for Leonardo only.
	while (!Serial) { ; }

	// Initialize the Ethernet shield.
	// If you entered fixed ipaddress info, gateway, subnet mask,
	// then uncommment the next line.
	// Ethernet.begin(mac, ip, gateway, subnet);

	// If it works to get a dynamic IP from a DHCP server, use this
	// code to test if you're getting a dynamic adress. If this
	// does not work, use the above method of specifying an IP-address.
	// dhcp test starts here
	if (Ethernet.begin(mac) == 0)
	{
		Serial.println("Failed to configure Ethernet using DHCP");
		// No point in carrying on, stop here forever.
		while(true) ;
	}
	// dhcp test end

	// Start the server.
	server.begin();

	// Print status.
	printServerStatus();
}

void loop()
{
	// Listen for incoming client requests.
	EthernetClient client = server.available();
	if (!client)
	{
		return;
	}

	Serial.println("Client connected");

	String request = readRequest(&client);
	executeRequest(&client, &request);

	// Close the connection.
	//client.stop();

	Serial.println("Client disonnected");
}

// Read the request line,
String readRequest(EthernetClient* client)
{
	String request = "";

	// Loop while the client is connected.
	while (client->connected())
	{
		// Read available bytes.
		while (client->available())
		{
			// Read a byte.
			char c = client->read();

			// Print the value (for debugging).
			Serial.write(c);

			// Exit loop if end of line.
			if ('\n' == c)
			{
				return request;
			}

			// Add byte to request line.
			request += c;
		}
	}
	return request;
}

void executeRequest(EthernetClient* client, String* request)
{
	char command = readCommand(request);
	int n = readParam(request);
	if ('O' == command)
	{
		pinMode(n, OUTPUT);
	}
	else if ('I' == command)
	{
		pinMode(n, INPUT);
	}
	else if ('L' == command)
	{
		digitalWrite(n, LOW);
	}
	else if ('H' == command)
	{
		digitalWrite(n, HIGH);
	}
	else if ('R' == command)
	{
		sendResponse(client, String(digitalRead(n)));
	}
	else if ('A' == command)
	{
		sendResponse(client, String(analogRead(n)));
	}
}

// Read the command from the request string.
char readCommand(String* request)
{
	String commandString = request->substring(0, 1);
	return commandString.charAt(0);
}

// Read the parameter from the request string.
int readParam(String* request)
{
	// This handles a hex digit 0 to F (0 to 15).
	char buffer[2];
	buffer[0] = request->charAt(1);
	buffer[1] = 0;
	return (int) strtol(buffer, NULL, 16);
}

void sendResponse(EthernetClient* client, String response)
{
	// Send response to client.
	client->println(response);

	// Debug print.
	Serial.println("sendResponse:");
	Serial.println(response);
}

void printServerStatus()
{
	Serial.print("Server address:");
	Serial.println(Ethernet.localIP());
}

Relié l'arduino a internet ou crée un serveur local, cette shield est composé aussi d'un slot pour carte micro sd.

Merci Standby,

J'avais bien compris cette première partie de fonction: serveur local.

J'ai une carte ethernet et voudrais utiliser mon shield et ce sketch car je pense que j'en trouverai une application interessante.

J'aurais donc souhaité qu'un spécialiste analyse ce sketch et me dise ce que je peux connecter à ma carte.

A l'origine, j'ai trouvé ce sketch en souhaitant commandé une led par exemple à partir d'un iphone ou lire la valeur d'une entrée analogique.

Toute info est la bienvenue.

Vous avez bien compris que j'ai très peu d'expérience.

Bonne journée,

P

Salut,

le fonctionnement du script que tu as publié est décris dans l'entête. Il s'agit d'un serveur connecté sur Ethernet écoutant sur le port 3300. Le client envoie des commandes selon une codification basique ( O5, I5, L5 ....) que l'Arduino execute dans la procédure executeRequest()

Il s'agit seulement d'un exemple et certainement de rien de concret. Si tu veux un vrai bon site de tuto avec une chance de passer a quelque chose de réalisable derrière je te conseille l'excellent blog d'Eskimon et en français de plus comme tu ne semble pas trop à l'aise avec l'anglais. :wink:

Bon courage

Merci Landid, je vais m'instruire un peu sur le site d'eskimon :slight_smile:

Bonjour,

Personne n'aurait sous le coude, un sketch tout fait qui active une led connectée à un arduino et son shield ethernet. La commande devant être une requête http. Je sais qu'une recherche fait apparaitre souvent cet exemple mais ce n'est jamais exactement ce que je recherche.

Merci à tous