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;
}
JEEDOM good news !!!!
Moderators: grovkillen, Stuntteam, TD-er
-
- Normal user
- Posts: 25
- Joined: 20 Mar 2016, 17:38
Re: JEEDOM good news !!!!
can anyone integrate this in the future Releaase
-
- Normal user
- Posts: 25
- Joined: 20 Mar 2016, 17:38
Re: JEEDOM good news !!!!
nobody to integrate it in the sources???
Re: JEEDOM good news !!!!
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
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
-
- Normal user
- Posts: 25
- Joined: 20 Mar 2016, 17:38
Re: JEEDOM good news !!!!
@luna ...
did you think the ._C00x.ino could be integrate in Easyesp as offcial scketch
did you think the ._C00x.ino could be integrate in Easyesp as offcial scketch
-
- Normal user
- Posts: 25
- Joined: 20 Mar 2016, 17:38
Re: JEEDOM good news !!!!
@luna this code should be use with a virtual in jeedom ....
Who is online
Users browsing this forum: Ahrefs [Bot] and 18 guests