Hello,
I’m trying to connect the cactus micro rev2 to my hue light system. That can be configured via some simple put requests like this curl request here:
curl -H "Accept: application/json" -X PUT --data '{"on":false}' http://192.168.1.123/api/newdeveloper/lights/4/state
This simple turns off bulb number 4. It tried now for several hours to achieve this with the rest functionality of the cactus. Unfortunately nothing happens. Maybe someone has a hint?
Here is my code:
#include <espduino.h>
#include <rest.h>
#define PIN_ENABLE_ESP 13
#define SSID "SSID"
#define PASS "PASSWORD"
ESP esp(&Serial1, &Serial, PIN_ENABLE_ESP);
REST rest(&esp);
boolean wifiConnected = false;
void wifiCb(void* response)
{
uint32_t status;
RESPONSE res(response);
if(res.getArgc() == 1) {
res.popArgs((uint8_t*)&status, 4);
if(status == STATION_GOT_IP) {
Serial.println("WIFI CONNECTED");
wifiConnected = true;
} else {
wifiConnected = false;
}
}
}
void setup() {
Serial1.begin(19200);
Serial.begin(19200);
esp.enable();
delay(500);
esp.reset();
delay(500);
while(!esp.ready());
Serial.println("ARDUINO: setup rest client");
if(!rest.begin("philips-hue/api/newdeveloper")) {
Serial.println("ARDUINO: failed to setup rest client");
while(1);
}
/*setup wifi*/
Serial.println("ARDUINO: setup wifi");
esp.wifiCb.attach(&wifiCb);
esp.wifiConnect(SSID, PASS);
Serial.println("ARDUINO: system started");
}
void loop() {
char data_buf[256];
char response[266];
esp.process();
if(wifiConnected) {
sprintf(data_buf, "{\"on\":false}");
rest.put("/lights/4/state",(const char*)data_buf);
rest.getResponse(response, 255);
Serial.println(response);
delay(1000);
}
}
The response coming back from the hue bridge just seems to be rubbish:
kmw��F,}[?�1a���;j�������'
���1��-��9ͧ�gZi<�ظǩ�|�sɆd(g��r[5��=*��+[�O�.��7!l���U�Ļ����l��>���f�
>��۽{�J������d}�V!�<��s,��'�qE�qmӼ��ϝ����