[vz-dev] Interessantes ESP8266-Projekt - nur leider reichen meine Arduino-Kenntnisse nicht

Klaus Reichenecker kr at kr123.de
Sun Nov 15 20:35:37 CET 2015


Zufällig habe ich dieses Projekt hier gefunden:
http://www.esp8266.nu/index.php/Main_Page

Dort wird über ein ESP-WIFI-Modul Daten an verschiedene Heimautomatisierungs-Software geschickt.
Vorteil ist, das die Interfaces über eine Weboberfläche programmiert werden können, also nicht jedes mal wenns ein zusätzlicher Sensor ist oder sich die IP ändert wieder Änderungen am Code nötig sind.
Ich denke das wäre ein sehr einfacher Weg, Sensoren für VZ zu realisieren ?

Platinen gibts z.B. hier für 7 ?:
http://www.ebay.de/itm/WIFI-ESP8266-Seriell-Dev-Modul-Drahtlos-Test-Board-Full-IO-Leads-ESP-12-TE301/311484720899?_trksid=p2047675.c100011.m1850&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D20140107083420%26meid%3D1d203b50fed94739822dba52b6ed0b3e%26pid%3D100011%26rk%3D1%26rkt%3D10%26sd%3D201464921200&tfrom=201464921200&tpos=unknow&ttype=price&talgo=origal


Leider unterstützt die Software momentan nur verschiedene vorgegeben Heimautomatisierungs-Zentralen oder ThingSpeak
http://www.esp8266.nu/index.php/EasyProtocols

Es müsste ein rel. einfaches sein, die Software so zu ändern, das sie auch in VZ loggt ?
Mir fehlen aber leider die detailierten Arduino-Programmierkenntnisse, um das zu ändern.

Als, falls jemand Lust hat ?

Viele Grüße

Klaus


Hier noch ein Beispiel wie Daten momentan geschickt werden:

//#######################################################################################################
//########################### Controller Plugin 001: Domoticz HTTP ######################################
//#######################################################################################################

#define CPLUGIN_001
#define CPLUGIN_ID_001         1
#define CPLUGIN_NAME_001       "Domoticz HTTP"

boolean CPlugin_001(byte function, struct EventStruct *event)
{
  boolean success = false;

  switch (function)
  {
    case CPLUGIN_PROTOCOL_ADD:
      {
        Protocol[++protocolCount].Number = CPLUGIN_ID_001;
        strcpy_P(Protocol[protocolCount].Name, PSTR(CPLUGIN_NAME_001));
        Protocol[protocolCount].usesMQTT = false;
        Protocol[protocolCount].usesAccount = false;
        Protocol[protocolCount].usesPassword = false;
        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"), "HTTP : connecting to ", host);
        addLog(LOG_LEVEL_DEBUG, log);
        if (printToWeb)
        {
          printWebString += log;
          printWebString += "<BR>";
        }
        // 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);
          if (printToWeb)
            printWebString += F("connection failed<BR>");
          return false;
        }
        if (connectionFailures)
          connectionFailures--;

        // We now create a URI for the request
        String url = F("/json.htm?type=command&param=udevice&idx=");
        url += event->idx;

        switch (event->sensorType)
        {
          case SENSOR_TYPE_SINGLE:                      // single value sensor, used for Dallas, BH1750, etc
            url += F("&svalue=");
            url += UserVar[event->BaseVarIndex];
            break;
          case SENSOR_TYPE_TEMP_HUM:                      // temp + hum + hum_stat, used for DHT11
            url += F("&svalue=");
            url += UserVar[event->BaseVarIndex];
            url += ";";
            url += UserVar[event->BaseVarIndex + 1];
            url += ";0";
            break;
          case SENSOR_TYPE_TEMP_BARO:                      // temp + hum + hum_stat + bar + bar_fore, used for BMP085
            url += F("&svalue=");
            url += UserVar[event->BaseVarIndex];
            url += ";0;0;";
            url += UserVar[event->BaseVarIndex + 1];
            url += ";0";
            break;
          case SENSOR_TYPE_SWITCH:
            url = F("/json.htm?type=command&param=switchlight&idx=");
            url += event->idx;
            url += F("&switchcmd=");
            if (UserVar[event->BaseVarIndex] == 0)
              url += "Off";
            else
              url += "On";
            break;
          case SENSOR_TYPE_DIMMER:
            url = F("/json.htm?type=command&param=switchlight&idx=");
            url += event->idx;
            url += F("&switchcmd=");
            if (UserVar[event->BaseVarIndex] == 0)
              url += "Off";
            else
            {
              url += F("Set%20Level&level=");
              url += UserVar[event->BaseVarIndex];
            }
            break;
        }

        url.toCharArray(log, 80);
        addLog(LOG_LEVEL_DEBUG_MORE, log);
        if (printToWeb)
        {
          printWebString += log;
          printWebString += "<BR>";
        }

        // This will send the request to the server
        client.print(String("GET ") + url + " HTTP/1.1\r\n" +
                     "Host: " + host + "\r\n" +
                     "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 : Succes!"));
            addLog(LOG_LEVEL_DEBUG, log);
            if (printToWeb)
              printWebString += F("Success<BR>");
            success = true;
          }
          delay(1);
        }
        strcpy_P(log, PSTR("HTTP : closing connection"));
        addLog(LOG_LEVEL_DEBUG, log);
        if (printToWeb)
          printWebString += F("closing connection<BR>");

        client.flush();
        client.stop();

        break;
      }

  }
  return success;
}

boolean Domoticz_getData(int idx, float *data)
{
  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]);

  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  if (!client.connect(host, Settings.ControllerPort))
  {
    connectionFailures++;
    return false;
  }
  if (connectionFailures)
    connectionFailures--;

  // We now create a URI for the request
  String url = F("/json.htm?type=devices&rid=");
  url += idx;

  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "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');
    if (line.substring(10, 14) == "Data")
    {
      String strValue = line.substring(19);
      byte pos = strValue.indexOf(' ');
      strValue = strValue.substring(0, pos);
      strValue.trim();
      float value = strValue.toFloat();
      *data = value;
      success = true;
    }
  }
  return success;
}


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://demo.volkszaehler.org/pipermail/volkszaehler-dev/attachments/20151115/7779d53d/attachment.html>


More information about the volkszaehler-dev mailing list