I update a code with a new command: SendToHUE, I did it finally.. but I dont have too match knowledge of programming in Arduino... someone can I help me to get a better code, please?
1- Add in ESPEasy.ini this:
Code: Select all
#include <RestClient.h>
Code: Select all
.
..
if (strcasecmp_P(Command, PSTR("SendToHUE")) == 0)
{
success = true;
String strLine = Line;
String host = parseString(strLine,2);
String port = parseString(strLine,3);
int pathinipos = getParamStartPos(strLine,4);
int pathfinpos = getParamStartPos(strLine,5);
String path = strLine.substring(pathinipos,(pathfinpos-1)); // With this line dont work because change it to a "lower" case.
//const char *cpath = path.c_str();
String msgs = parseString(strLine,5);
//const char *cmsgs = msgs.c_str();
const char HUE_IP[] = "192.168.1.201";
const int HUE_PORT = 80;
RestClient hue(HUE_IP,HUE_PORT);
String response;
response = "";
int statusCode = 0;
char c_path[(path.length()+1)];
path.toCharArray(c_path, (path.length()+1));
char c_msgs[(msgs.length()+1)];
msgs.toCharArray(c_msgs, (msgs.length()+1));
statusCode = hue.put(c_path, c_msgs, &response);
Serial.print("Status code from server: ");
Serial.println(statusCode);
Serial.print("Response body from server: ");
Serial.println(response);
}
..
.
Code: Select all
on sw1#Switch do
if [sw1#Switch]=1
SendToHUE <ip>,<port>,/api/<mykey>/lights/6/state,{"on":true}
else
SendToHUE <ip>,<port>,/api/<mykey>/lights/6/state,{"on":false}
endif
endon
Thank you very match..
Antoni.