POST についてはわかりませんが、GET は確実に機能します。これは、私が使用してきた AJAX の例です。RGB LED を制御するだけです。
xmlhttp.open("GET", "http://ipAddressOfArduino?r=" + redVal + "&g=" + greenVal + "&b=" + blueVal + "&e", true);
次に、Arduino 側では、データを解析するだけです。
//ARDUINO 1.0+ ONLY
//ARDUINO 1.0+ ONLY
#include <Ethernet.h>
#include <SPI.h>
boolean reading = false;
String myStr;
int redVal, greenVal, blueVal;
////////////////////////////////////////////////////////////////////////
//CONFIGURE
////////////////////////////////////////////////////////////////////////
//byte ip[] = { 192, 168, 0, 1 }; //Manual setup only
//byte gateway[] = { 192, 168, 0, 1 }; //Manual setup only
//byte subnet[] = { 255, 255, 255, 0 }; //Manual setup only
// if need to change the MAC address (Very Rare)
byte mac[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
EthernetServer server = EthernetServer(80); //port 80
////////////////////////////////////////////////////////////////////////
void setup(){
Serial.begin(9600);
pinMode(3, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
Ethernet.begin(mac);
//Ethernet.begin(mac, ip); //for manual setup
server.begin();
Serial.println(Ethernet.localIP());
}
void loop(){
// listen for incoming clients, and process qequest.
checkForClient();
}
void checkForClient(){
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
boolean sentHeader = false;
myStr = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
if(reading && c == ' ') reading = false;
if(c == '?') reading = true; //found the ?, begin reading the info
if(reading){
//Serial.print(c);
if (c!='?') {
myStr += c;
}
}
if (c == '\n' && currentLineIsBlank) break;
if (c == '\n') {
currentLineIsBlank = true;
}else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
parseThangs(myStr);
analogWrite(3, redVal);
analogWrite(5, greenVal);
analogWrite(6, blueVal);
delay(100); // give the web browser time to receive the data
client.stop(); // close the connection:
}
}
void parseThangs(String str) {
int startIndex = str.indexOf("r");
int endIndex = str.indexOf("g");
String redStr = str.substring(startIndex + 2, endIndex - 1);
char tempRed[4];
redStr.toCharArray(tempRed, sizeof(tempRed));
redVal = atoi(tempRed);
startIndex = str.indexOf("g");
endIndex = str.indexOf("b");
String greenStr = str.substring(startIndex + 2, endIndex -1);
char tempGreen[4];
greenStr.toCharArray(tempGreen, sizeof(tempGreen));
greenVal = atoi(tempGreen);
startIndex = str.indexOf("b");
endIndex = str.indexOf("e");
String blueStr = str.substring(startIndex + 2, endIndex -1);
char tempBlue[4];
blueStr.toCharArray(tempBlue, sizeof(tempBlue));
blueVal = atoi(tempBlue);
Serial.println(redStr + " " + greenStr + " " + blueStr);
}
おそらく少しずさんですが、うまくいきます。