Arduino + philips色调

时间:2014-03-11 11:33:11

标签: http-headers arduino philips-hue

我一直在努力奋斗数小时。能够让色调改变浅色并使用卷曲关闭(卷曲-v -X PUT -d' {" on":true," bri":254 }' http://192.168.x.x/api/newdeveloper/lights/3/state)和浏览器界面,但是当我尝试使arduino做同样的事情时我得到错误:无效/缺少参数。以下是我的代码。我从浏览器界面查看标题中获得了很多,这些标题确实起作用(来自浏览器):

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x83, 0x0B };

IPAddress server(74,125,232,128);  
IPAddress server(192,168,x,x);     

IPAddress ip(192,168,0,177);

EthernetClient client;

void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(2000);
Serial.println("connecting...");

if (client.connect(server, 80)) {
Serial.println("connected");
client.println("PUT /api/newdeveloper/lights/3/state HTTP/1.1");
client.println("Host: 192.168.x.x");
client.println("Connection: keep-alive");
client.println("Content-Length: 45");
client.println("Origin: http://192.168.x.x");
client.println("User-Agent: arduino-ethernet");
client.println("Content-Type: text/plain;charset=UTF-8");
//client.println("Accept: */*");
client.println("Referer: http://192.168.x.x/debug/clip.html");
client.println("Accept-Encoding: gzip,deflate,sdch");
client.println("Accept-Language: en-US,en;q=0.8");
client.println("{\"on\":true, \"sat\":20, \"bri\":255,\"hue\":10000}");
//client.println();
} 
else {
Serial.println("connection failed");
}
}

void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}

if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();

// do nothing forevermore:
while(true);
}
}

1 个答案:

答案 0 :(得分:0)

我认为您在请求标头和正文之间缺少换行符。 尝试这样的事情:

client.println("Accept-Language: en-US,en;q=0.8");
client.println();
client.println("{\"on\":true, \"sat\":20, \"bri\":255,\"hue\":10000}");