Hi all
I have a motion sensor which turns lights on and off.
I want it to randomly select colours from a few presets rather than show the same colour all the time.
It is called by
light_control(hue_on1);
and I want it to select from the folllowing:
String hue_on1 = "{\"on\":true, \"bri\":255, \"xy\":[0.3052,0.3305]}";
String hue_on2 = "{\"on\":true, \"bri\":150, \"xy\":[0.1450,0.01520]}";
String hue_on3 = "{\"on\":true, \"bri\":255, \"xy\":[0.1052,0.2205]}";
light_control is the prefix to hue_on:
bool light_control(String command)
{
int retval = 0; // return value
WiFiClient client; // WiFiClient class to create TCP connections
if (!client.connect(bridge_ip, port))
{
Serial.println("ERR>> light_control - Connection failed");
return -1;
}
// This will send PUT request to the server
client.println("PUT /api/" + user + "/lights/" + light + "/state HTTP/1.1");
client.println("Host: " + String(bridge_ip) + ":" + String(port));
client.println("User-Agent: ESP8266/1.0");
client.println("Connection: keep-alive");
client.println("Content-type: text/xml; charset=\"utf-8\"");
client.print("Content-Length: ");
client.println(command.length());
client.println();
client.println(command);
// Wait 10 seconds for server to respond
unsigned long timeout = millis();
while (client.available() == 0)
{
if (millis() - timeout > 10000)
{
Serial.println("ERR>> light_control - Client timeout");
client.stop();
return -1;
}
}
I have tried the following with no success:
int randNumber;
in the main loop I have added:
randNumber = random(1,3);
and I am calling it with the following:
light_control(hue_on(randNumber));
With that I get the following error:
esp8266Huemotion.ino: In function 'void loop()':
esp8266Huemotion:365: error: no match for call to '(String) (int&)'
light_control2(hue_on(randNumber));
^
exit status 1
no match for call to '(String) (int&)'
Code anyone give me some pointers please? Whilst I'm asking for pointers, what are some good resources to learn programming arduinos?
motion.ino (10.6 KB)