Thanks moelski
I've written my own plugin (thermostat+timer) which has 3 user vars I wish to see in domoticz:
Set point
Heating On
Flame Lit
These 3 values need to go to (in my case) domoticz, BUT 3 different IDX (3 different virtual devices in domoticz:
Virtual Thermostat
Virtual Switch
Virtual Switch.
How would I use the standard espeasy procedures? I woudl call it 3 times each time passing my own data (switch type, idx, value etc)
Thanks
At the moment I pinched the code from the standard domoticz controller and adjusted it as below. But obviously this is bad for duplication and also means it will only work for domoticz..
void Plugin_121_Manual_Controller_Update(int IDX, int DeviceType, int DeviceValue, float DeviceValueFloat)
{
String authHeader = "";
if ((SecuritySettings.ControllerUser[0] != 0) && (SecuritySettings.ControllerPassword[0] != 0))
{
base64 encoder;
String auth = SecuritySettings.ControllerUser;
auth += ":";
auth += SecuritySettings.ControllerPassword;
authHeader = "Authorization: Basic " + encoder.encode(auth) + " \r\n";
}
char log[80];
boolean success = false;
char host[20];
sprintf_P(host, PSTR("%u.%u.%u.%u"), Settings.Controller_IP[0], Settings.Controller_IP[1], Settings.Controller_IP[2], Settings.Controller_IP[3]);
sprintf_P(log, PSTR("%s%s using port %u"), "HTTP : connecting to ", host, Settings.ControllerPort);
addLog(LOG_LEVEL_DEBUG, log);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, Settings.ControllerPort))
{
connectionFailures++;
strcpy_P(log, PSTR("HTTP : connection failed"));
addLog(LOG_LEVEL_ERROR, log);
return;
}
if (connectionFailures)
connectionFailures--;
// We now create a URI for the request
String url = F("/json.htm?type=command¶m=");
switch (DeviceType)
{
case 1: // switch
url += F("switchlight&idx=");
url += String(IDX);
if (DeviceValue == 1) url += "&switchcmd=On";
if (DeviceValue == 0) url += "&switchcmd=Off";
break;
case 2: // Set Point
url += F("udevice&idx=");
url += String(IDX);
url += F("&nvalue=0&svalue=");
url += toString(DeviceValueFloat, 1);
break;
}
url.toCharArray(log, 80);
addLog(LOG_LEVEL_DEBUG_MORE, log);
// This will send the request to the server
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + authHeader + "Connection: close\r\n\r\n");
unsigned long timer = millis() + 200;
while (!client.available() && millis() < timer)
delay(1);
// Read all the lines of the reply from server and print them to Serial
while (client.available()) {
String line = client.readStringUntil('\n');
line.toCharArray(log, 80);
addLog(LOG_LEVEL_DEBUG_MORE, log);
if (line.substring(0, 15) == "HTTP/1.1 200 OK")
{
strcpy_P(log, PSTR("HTTP : Success"));
addLog(LOG_LEVEL_DEBUG, log);
success = true;
}
delay(1);
}
strcpy_P(log, PSTR("HTTP : closing connection"));
addLog(LOG_LEVEL_DEBUG, log);
client.flush();
client.stop();
}