JEEDOM good news !!!!

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
vinceducat
Normal user
Posts: 25
Joined: 20 Mar 2016, 17:38

JEEDOM good news !!!!

#1 Post by vinceducat » 28 Mar 2016, 16:27

Hello

i write my first _C00x.ino script for sending value of a ds18b20 to jeedom.

this code is very sad ... but works if the specialist in ino code are here perhaps they could use it and clean it

thanks

this code is based on thinkspeak .....


//#######################################################################################################
//########################### Controller Plugin 009: Jeedom #########################################
//#######################################################################################################

#define CPLUGIN_009
#define CPLUGIN_ID_009 9
#define CPLUGIN_NAME_009 "Jeedom HTTP"

boolean CPlugin_009(byte function, struct EventStruct *event, String& string)
{
boolean success = false;

switch (function)
{
case CPLUGIN_PROTOCOL_ADD:
{
Protocol[++protocolCount].Number = CPLUGIN_ID_009;
Protocol[protocolCount].usesMQTT = false;
Protocol[protocolCount].usesAccount = false;
Protocol[protocolCount].usesPassword = true;
Protocol[protocolCount].defaultPort = 80;
break;
}

case CPLUGIN_GET_DEVICENAME:
{
string = F(CPLUGIN_NAME_009);
break;
}

case CPLUGIN_PROTOCOL_SEND:
{
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 false;
}
statusLED(true);
if (connectionFailures)
connectionFailures--;

String postDataStr = SecuritySettings.ControllerPassword; // "0UDNN17RW6XAS2E5" // api key for jeedom

switch (event->sensorType)
{
case SENSOR_TYPE_SINGLE: // single value sensor, used for Dallas, BH1750, etc
case SENSOR_TYPE_SWITCH:
postDataStr += F("&field");
postDataStr += event->idx;
postDataStr += "=";
postDataStr += toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
break;
case SENSOR_TYPE_TEMP_HUM: // dual value
case SENSOR_TYPE_TEMP_BARO:
postDataStr += F("&field");
postDataStr += event->idx;
postDataStr += "=";
postDataStr += toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
postDataStr += F("&field");
postDataStr += event->idx + 1;
postDataStr += "=";
postDataStr += toString(UserVar[event->BaseVarIndex + 1],ExtraTaskSettings.TaskDeviceValueDecimals[1]);
break;
case SENSOR_TYPE_TEMP_HUM_BARO:
postDataStr += F("&field");
postDataStr += event->idx;
postDataStr += "=";
postDataStr += toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
postDataStr += F("&field");
postDataStr += event->idx + 1;
postDataStr += "=";
postDataStr += toString(UserVar[event->BaseVarIndex + 1],ExtraTaskSettings.TaskDeviceValueDecimals[1]);
postDataStr += F("&field");
postDataStr += event->idx + 2;
postDataStr += "=";
postDataStr += toString(UserVar[event->BaseVarIndex + 2],ExtraTaskSettings.TaskDeviceValueDecimals[2]);
break;
}
postDataStr += F("\r\n\r\n");

String postStr = F("POST ");
postStr += F("/jeedom/core/api/jeeApi.php?apikey=");
postStr += SecuritySettings.ControllerPassword;
postStr += F("&type=virtual&id=");
postStr += event->idx;
postStr += F("& HTTP/1.1\n");
postStr += F("Host: ");
postStr += host;
postStr += ("\n");
postStr += F("Connection: close\n");
postStr += F("Content-Type: application/x-www-form-urlencoded\n");
postStr += F("Content-Length: ");
postDataStr = F("value=");
postDataStr += toString(UserVar[event->BaseVarIndex],ExtraTaskSettings.TaskDeviceValueDecimals[0]);
postStr += postDataStr.length();
postStr += F("\n\n");
postStr += postDataStr;

// This will send the request to the server
client.print(postStr);

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 : Succes!"));
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();
break;
}

}
return success;
}

vinceducat
Normal user
Posts: 25
Joined: 20 Mar 2016, 17:38

Re: JEEDOM good news !!!!

#2 Post by vinceducat » 28 Mar 2016, 18:12

can anyone integrate this in the future Releaase

vinceducat
Normal user
Posts: 25
Joined: 20 Mar 2016, 17:38

Re: JEEDOM good news !!!!

#3 Post by vinceducat » 01 Apr 2016, 18:50

nobody to integrate it in the sources???

lunarok
Normal user
Posts: 34
Joined: 28 Oct 2015, 10:11

Re: JEEDOM good news !!!!

#4 Post by lunarok » 01 Apr 2016, 22:51

Yes will be very good to have such a connector.
If someone care enough to integrate this plugin, I will be happy to build a dedicated plugin for ESPeasy in Jeedom and give it more light

vinceducat
Normal user
Posts: 25
Joined: 20 Mar 2016, 17:38

Re: JEEDOM good news !!!!

#5 Post by vinceducat » 02 Apr 2016, 13:14

@luna ...

did you think the ._C00x.ino could be integrate in Easyesp as offcial scketch

vinceducat
Normal user
Posts: 25
Joined: 20 Mar 2016, 17:38

Re: JEEDOM good news !!!!

#6 Post by vinceducat » 02 Apr 2016, 13:15

@luna this code should be use with a virtual in jeedom ....

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 18 guests