ja dat zou ook kunnen ja
ik had al even wat veranderd aan de plugin maar kan nog even niet compileren zodat ik wat kan testen me pc happert ff zodra ik
meer weet laat ik het weten.
Mvg Mark
bunny007 schreef:Kunnen toch wel iets bedenken met de eventlist dat we een variable op de nodo berekenen en dat netjes meegeven naar Domoticz ?
bunny007 schreef:Moet wel lukken idd mss 15 extra regels in de eventlist, om die BMP aan te sluiten moet ik een mega uit de keuken gaan demonteren, of men laptop gaan afstoffen, uiteindelijk moet het toch een keer gaan gebeuren
//#######################################################################################################
//############################### Plugin-250: SendHTTP for Domoticz JSON API #######################
//#######################################################################################################
/*********************************************************************************************\
* This plugin provides direct HTTP communication from a Nodo (mega with ethernetshield) to a Domoticz controller
*
* Author : Martinus van den Broek
* Updated by : The Bunny (31-01-2016)
* Support : NONE!
* Date : Feb 2015
* Version : 0.4
* Compatibility : R744
* Syntax : "sendHTTP <command>,<IDX>,<Value/state>,<Value>,<Value>
*
* Changelog 0.4
* -. Changed support status from : None! demo... to uppercase NONE!
* -. Added the baro sensors with SendHTTP 5,92,24,0,23 and baro forecast (/json.htm?type=command¶m=udevice&idx=IDX&nvalue=0&svalue=1000;1)
*
* Changelog 0.3
* -. Dont use numbers above 255 for uservariables etc
* -. Added Domoticz Scenes with SendHTTP 3,2,1,0,0 (/json.htm?type=command¶m=switchscene&idx=2&switchcmd=On)
* -. Added Domoticz UserVariables with SendHTTP 4,3,123,100,0 (/json.htm?type=command¶m=updateuservariable&idx=3&vname=100&vtype=0&vvalue=123)
*
* Changelog 0.2
* -. Possible to have negative value's (-5.04)
* -. Temp in normal format (12.34)
* -. Added the Domoticz nvalue with Par 4
*
*
* For Variables with the Svalue
* Timer 1; SendHTTP 2,6,1,0,0 # send tempsensor command to device idx=6 with value from var1 to Svalue
* Timer 1; SendHTTP 2,7,2,0,0 # send tempsensor command to device idx=7 with value from var2 to Svalue
*
* For Variables with the Nvalue
* Timer 1; SendHTTP 2,8,0,4,0 # send tempsensor command to device idx=8 with value from var4 to Nvalue
* Timer 1; SendHTTP 2,9,0,5,0 # send tempsensor command to device idx=9 with value from var5 to Nvalue
*
* For Switches
* SendHTTP 1,6,1,0,0 # send On command to device idx=6 with value 1
* SendHTTP 1,6,0,0,0 # send Off command to device idx=6 with value 0
* SendHTTP 1,7,1,0,0 # send On command to device idx=7 with value 1
* SendHTTP 1,8,0,0,0 # send Off command to device idx=8 with value 0
*
* For Scenes
* SendHTTP 3,2,1,0,0 # Set scene with idx=2 with value On
* SendHTTP 3,2,0,0,0 # Set scene with idx=2 with value Off
*
* For Uservariables (ONLY NUMBERS AS NAME AND VALUE)
* SendHTTP 4,3,123,100,0 # Set uservariable with idx=3 with value 123 and name 100
* SendHTTP 4,3,124,111,0 # Set uservariable with idx=3 with value 124 and name 111
*
* For the BMP085 or BMP180 Baro Sensor
* SendHTTP 5,92,24,0,23 # Set uservariable with idx=92 with Nodo variable 24 (baro value) and Nodo variable 23 (baro forecast 0-1-2-3-4-6)
* SendHTTP 5,92,20,0,19 # Set uservariable with idx=92 with Nodo variable 20 (baro value) and Nodo variable 19 (baro forecast 0-1-2-3-4-6)
*
* Action on: NewKakuSend 1,On
* http://192.168.50.198:6636/?event=NewKakuSend%201,On
*
* Action off: NewKakuSend 1,Off
* http://192.168.50.198:6636/?event=NewKakuSend%201,Off
*
* Action on: Userevent 110,1
* http://192.168.50.198:6636/?event=Userevent%20110,1
*
* Action VariableSet: VariableSet 8,1
* http://192.168.50.198:6636/?event=VariableSet%208,1
*
* Action off: Userevent 110,2
* http://192.168.50.198:6636/?event=Userevent%20110,2
*
* Action off: ExtWiredOut 10,Off
* http://192.168.50.198:6636/?event=ExtWiredOut%2010,Off
*
* Multi Action on: Userevent 126,1;Sound 0,10;TimerSet 22,600
* http://192.168.50.198:6636/?event=Userevent%20126,1;Sound%200,10;TimerSet%2022,600
*
\*********************************************************************************************/
boolean P250SendCustomHTTPRequest(char* Request, byte ip, unsigned long port);
#define PLUGIN_250_IP 189 // x.x.x.8 = address of Domoticz, enter the last number in the subnet
#define PLUGIN_250_PORT 8080 // Default port of Domoticz
#define PLUGIN_ID 250
#define PLUGIN_NAME "SendHTTP"
boolean Plugin_250(byte function, struct NodoEventStruct *event, char *string)
{
boolean success=false;
switch(function)
{
#ifdef PLUGIN_250_CORE
#if NODO_MEGA
case PLUGIN_COMMAND:
{
// Par 1 ='command/type' 1=Switch 2=Variable 3=Scene 4=Uservariables
byte Par2=event->Par2 & 0xff; // Par 2 = Domoticz Device IDX
byte Par3=event->Par2>>8 & 0xff; // Par 3 = Variable or number for domoticz (svalue or 0=Off, 1=On )
byte Par4=event->Par2>>16 & 0xff; // Par 4 = Variable or number for domoticz (nvalue)
byte Par5=event->Par2>>24 & 0xff; // Par 5 = Variable for domoticz baro 0-1-2-3-4-5-6
byte x;
char *HttpRequest=(char*)malloc(INPUT_LINE_SIZE+1);
if (event->Par1 == 1) // Switches On/Off
{
strcpy(HttpRequest,"/json.htm?type=command¶m=switchlight&idx=");
strcat(HttpRequest,int2str(Par2));
strcat(HttpRequest,"&switchcmd=");
if (Par3==1)
strcat(HttpRequest,"On");
else
strcat(HttpRequest,"Off");
strcat(HttpRequest,"&level=0");
}
if (event->Par1 == 2) // TempSensors & Humidity
{
strcpy(HttpRequest,"/json.htm?type=command¶m=udevice&idx=");
strcat(HttpRequest,int2str(Par2));
strcat(HttpRequest,"&nvalue=");
// Send the value of nvalue
float nvalue = UserVar[Par4-1];
char buffer1[12];
String tempStr1 = dtostrf(nvalue, 4,2,buffer1);
strcat(HttpRequest, buffer1);
strcat(HttpRequest,"&svalue=");
// Send the value of svalue
float svalue = UserVar[Par3-1];
char buffer2[12];
String tempStr2 = dtostrf(svalue, 4,2,buffer2);
strcat(HttpRequest, buffer2);
}
if (event->Par1 == 3) // Scenes On/Off
{
//strcpy(HttpRequest,"/json.htm?type=command¶m=switchlight&idx=");
strcpy(HttpRequest,"/json.htm?type=command¶m=switchscene&idx=");
strcat(HttpRequest,int2str(Par2));
strcat(HttpRequest,"&switchcmd=");
if (Par3==1)
strcat(HttpRequest,"On");
else
strcat(HttpRequest,"Off");
strcat(HttpRequest,"&level=0");
}
if (event->Par1 == 4) // User Variables in Domoticz (only numbers as name and value)
{
strcpy(HttpRequest,"/json.htm?type=command¶m=updateuservariable&idx=");
strcat(HttpRequest,int2str(Par2));
strcat(HttpRequest,"&vname=");
// Send the name of uservariable (only numbers as name and value)
strcat(HttpRequest,int2str(Par4));
strcat(HttpRequest,"&vtype=0&vvalue=");
// Send the value of uservariable (only numbers as name and value)
strcat(HttpRequest,int2str(Par3));
}
if (event->Par1 == 5) // Baro meter value for Domoticz
{
strcpy(HttpRequest,"/json.htm?type=command¶m=udevice&idx=");
strcat(HttpRequest,int2str(Par2));
strcat(HttpRequest,"&nvalue=0&svalue=");
// Send the value of the barometer + baro forecast (for example 1000;1)
// Send the value of the barometer
float barovalue = UserVar[Par3-1];
char buffer3[12];
String tempStr3 = dtostrf(barovalue, 4,2,buffer3);
strcat(HttpRequest, buffer3);
strcat(HttpRequest,";");
// Send the value of the baro forecast
float forecastvalue = UserVar[Par5-1];
char buffer4[12];
String tempStr4 = dtostrf(forecastvalue, 4,2,buffer4);
strcat(HttpRequest, buffer4);
}
x=P250SendCustomHTTPRequest(HttpRequest,PLUGIN_250_IP,PLUGIN_250_PORT);
free(HttpRequest);
success=true;
break;
}
#endif
#endif // PLUGIN_250_CORE
#if NODO_MEGA
case PLUGIN_MMI_IN:
{
char *TempStr=(char*)malloc(INPUT_COMMAND_SIZE);
if(GetArgv(string,TempStr,1))
{
if(strcasecmp(TempStr,PLUGIN_NAME)==0)
{
if(GetArgv(string,TempStr,3))
event->Par2=str2int(TempStr);
if(GetArgv(string,TempStr,4))
event->Par2|=str2int(TempStr)<<8;
if(GetArgv(string,TempStr,5))
event->Par2|=str2int(TempStr)<<16;
if(GetArgv(string,TempStr,6))
event->Par2|=str2int(TempStr)<<24;
event->Type = NODO_TYPE_PLUGIN_COMMAND;
event->Command = PLUGIN_ID; // Plugin nummer
success=true;
}
}
free(TempStr);
break;
}
case PLUGIN_MMI_OUT:
{
strcpy(string,PLUGIN_NAME); // Eerste argument=het commando deel
strcat(string," ");
strcat(string,int2str(event->Par1));
strcat(string,",");
strcat(string,int2str(event->Par2 & 0xff));
strcat(string,",");
strcat(string,int2str(event->Par2>>8 & 0xff));
strcat(string,",");
strcat(string,int2str(event->Par2>>16 & 0xff));
strcat(string,",");
strcat(string,int2str(event->Par2>>24 & 0xff));
break;
}
#endif //NODO_MEGA
}
return success;
}
#define IP_BUFFER_SIZE 256
boolean P250SendCustomHTTPRequest(char* Request, byte ip, unsigned long port)
{
byte targetIP[4];
int InByteCounter,x,y;
byte InByte;
unsigned long TimeoutTimer;
const int TimeOut=5000;
EthernetClient HTTPClient; // Client class voor HTTP sessie.
byte State=0;
char *IPBuffer=(char*)malloc(IP_BUFFER_SIZE+1);
targetIP[0] = EthernetNodo.localIP()[0];
targetIP[1] = EthernetNodo.localIP()[1];
targetIP[2] = EthernetNodo.localIP()[2];
targetIP[3] = ip;
strcpy(IPBuffer,"GET ");
// Alle spaties omzetten naar %20 en toevoegen aan de te verzenden regel.
y=strlen(IPBuffer);
for(x=0;x<strlen(Request);x++)
{
if(Request[x]==32)
{
IPBuffer[y++]='%';
IPBuffer[y++]='2';
IPBuffer[y++]='0';
}
else
{
IPBuffer[y++]=Request[x];
}
}
IPBuffer[y]=0;
strcat(IPBuffer," HTTP/1.1");
Serial.println(IPBuffer);
if(HTTPClient.connect(targetIP,port))
{
HTTPClient.println(IPBuffer);
HTTPClient.println("Host: 192.168.0.123");
HTTPClient.println("User-Agent: Mozilla/5.0");
HTTPClient.println(F("Connection: Close"));
HTTPClient.println();// Afsluiten met een lege regel is verplicht in http protocol/
TimeoutTimer=millis()+TimeOut; // Als er te lange tijd geen datatransport is, dan wordt aangenomen dat de verbinding (om wat voor reden dan ook) is afgebroken.
IPBuffer[0]=0;
InByteCounter=0;
while(TimeoutTimer>millis() && HTTPClient.connected())
{
if(HTTPClient.available())
{
InByte=HTTPClient.read();
if(isprint(InByte) && InByteCounter<IP_BUFFER_SIZE)
IPBuffer[InByteCounter++]=InByte;
else if(InByte==0x0A)
{
IPBuffer[InByteCounter]=0;
// De regel is binnen
InByteCounter=0;
}
}
}
delay(500);
HTTPClient.flush();// Verwijder eventuele rommel in de buffer.
HTTPClient.stop();
}
free(IPBuffer);
return State;
}
Gebruikers in dit forum: Geen geregistreerde gebruikers. en 1 gast