Hello.
I'm almost newbee.
I have a arduino 2560+ the ethernet shield.
I need to send a command to my home automate software(Homidom, french software).
The syntax is:
http://192.168.0.177:7999/api/123456789/command/device/4b993548-b81b-4565-9cae-cb2c3f4abcde/SetValue?Value=x
where is x is a variable depending of a sensor.
How can I do that?
Thank you for your help!
Patrick
Basic client test code where you can change the IP address and GET line to your setup.
//zoomkat 12-01-11
//simple client test
//for use with IDE 0021
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte myserver[] = { 208, 104, 244, 25 }; // zoomkat web page server IP address
EthernetClient client; // connect to web server using port 80
//////////////////////
void setup(){
Ethernet.begin(mac);
Serial.begin(9600);
Serial.println("Better client test 12/01/11"); // so I can keep track of what is loaded
Serial.println("Send an e in serial monitor to test"); // what to do to test
}
void loop(){
// check for serial input
if (Serial.available() > 0) //if something in serial buffer
{
byte inChar; // sets inChar as a byte
inChar = Serial.read(); //gets byte from buffer
if(inChar == 'e') // checks to see byte is an e
{
sendGET(); // call send GET function below when byte is an e
}
}
}
//////////////////////////
void sendGET() //client function to send/receive GET request data.
{
if (client.connect(myserver, 80)) { //starts client connection, checks for connection
Serial.println("connected");
client.println("GET /~shb/arduino.txt HTTP/1.1"); //download text
client.println("Host: web.comporium.net");
client.println("Connection: close"); //close 1.1 persistent connection
client.println(); //end of get request
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
while(client.connected() && !client.available()) delay(1); //waits for data
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
Serial.print(c); //prints byte to serial monitor
}
Serial.println();
Serial.println("disconnecting.");
Serial.println("==================");
Serial.println();
client.stop(); //stop client
}
Thank you for your response.
Excuses for my probably stupid question:
I thougt I had to use the POST function to send the information from my arduino to my home automate software, and not the GET function.
Thanks
Since both GET and POST require you to send information to the server, if you control the server, you can use either and GET is nice and simple.
In your case, it very much depends what your automation system expects.
Hello everybody!
It almost works!! with the command:
client.println("GET /api/123456789/command/device/4b993548-b81b-4565-9cae-cb2c3f4abcd/SetValue?Value=199 HTTP/1.0");
My home automate receive the value 199.
But how can I send the value: analogRead(3) instead of a fixe value (199) ?
Thanks a lot!