Retrieving information from a Weishaupt WCM-COM module into the loxone environment

Einklappen
X
 
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge
  • guido4096
    Dumb Home'r
    • 11.10.2015
    • 18

    #1

    Retrieving information from a Weishaupt WCM-COM module into the loxone environment

    Just in case somebody is interested. I've developed in PicoC the protocol to retrieve (and set if needed) information from a WCM-COM module from Weishaupt.
    This allows me for example to use the outside and room temperatue inside my loxone programming.
    The WCM-COM cannot be queried using the regular HTTP Virtual Input commands, because it uses HTTPPost. HTTPPost is not available in the HTTP Virtual Input, it is only available in the HTTP Virtual Output. I don't really understand why this is not available in the Virtual HTTP Input command... . The code includes authentication and to do so requires MD5 calculcation, which I ported to PicoC.

    If somebody is interested just let me know.
  • Gast

    #2
    Hello, I just got a WCM-COM and I want to write a script for my Fritz!Box so that it queries the oil counter value once a day, because the logger of the WCM-COM isn't able to log that value. It would be great if you could send me your code, because you seem to be the only one who even considered talking to the WCM-COM directly

    Kommentar

    • guido4096
      Dumb Home'r
      • 11.10.2015
      • 18

      #3
      Hi,

      ​See the PicoC code below. This is very much tuned to PicoC, not sure how you can integrate additional functionality in the Fritz.Box with the current firmware versions. Remark somewhere 3/4 of the code you need to fill in the hostname(IP address), username and password for your WCM-COM. Also, a large part of the code is just to handle authorization. If you can live without password protected accounts on thw WCM-COM, you could do without that authorization. For lots more of information on how to talk to the WCM-COM (which is basically just a HTTPOST with JSON formatted messages), see this :


      It explains more details how to query the WCM-COM.

      Hope this helps,

      Guido



      // HTTP buffer sizes
      #define BUFF_SIZE 40000
      #define RD_BLOCK_SIZE 128

      // MD5 hash calculation
      unsigned int F(unsigned int x, unsigned int y, unsigned int z)
      {
      return (z ^ (x & (y ^ z)));
      }
      unsigned int G(unsigned int x, unsigned int y, unsigned int z)
      {
      return (y ^ (z & (x ^ y)));
      }
      unsigned int H(unsigned int x, unsigned int y, unsigned int z)
      {
      return ((x ^ y) ^ z);
      }
      unsigned int H2(unsigned int x, unsigned int y, unsigned int z)
      {
      return (x ^ (y ^ z));
      }
      unsigned int I(unsigned int x, unsigned int y, unsigned int z)
      {
      return (y ^ (x | ~z));
      }

      unsigned int rsh(unsigned int a, unsigned int s)
      {
      return a >> s;
      // rsh operator is broken on loxone picoc on version 7.1.x and before.
      // It pulls in 1's instead of 0's. Use this code to workaround.
      //unsigned int r = a >> 1;
      //r = r & 0x7fffffff;
      //return r >> (s - 1);
      }

      unsigned int STEPF(unsigned int a, unsigned int b, unsigned int c, unsigned int d, unsigned int x, unsigned int t, unsigned int s)
      {
      a += F(b, c, d) + x + t;
      a = ((a << s) | rsh(a & 0xffffffff, (32 - s)));
      a += b;
      return a;
      }
      unsigned int STEPG(unsigned int a, unsigned int b, unsigned int c, unsigned int d, unsigned int x, unsigned int t, unsigned int s)
      {
      a += G(b, c, d) + x + t;
      a = ((a << s) | rsh(a & 0xffffffff, (32 - s)));
      a += b;
      return a;
      }
      unsigned int STEPH(unsigned int a, unsigned int b, unsigned int c, unsigned int d, unsigned int x, unsigned int t, unsigned int s)
      {
      a += H(b, c, d) + x + t;
      a = ((a << s) | rsh(a & 0xffffffff, (32 - s)));
      a += b;
      return a;
      }
      unsigned int STEPH2(unsigned int a, unsigned int b, unsigned int c, unsigned int d, unsigned int x, unsigned int t, unsigned int s)
      {
      a += H2(b, c, d) + x + t;
      a = ((a << s) | rsh(a & 0xffffffff, (32 - s)));
      a += b;
      return a;
      }
      unsigned int STEPI(unsigned int a, unsigned int b, unsigned int c, unsigned int d, unsigned int x, unsigned int t, unsigned int s)
      {
      a += I(b, c, d) + x + t;
      a = ((a << s) | rsh(a & 0xffffffff, (32 - s)));
      a += b;
      return a;
      }
      struct MD5_CTX {
      unsigned int lo;
      unsigned int hi;
      unsigned int a;
      unsigned int b;
      unsigned int c;
      unsigned int d;
      unsigned char buffer[64];
      unsigned int block[16];
      };
      unsigned int GET(struct MD5_CTX* ctx, int n)
      {
      return ctx->block[n];
      }
      unsigned int SET(struct MD5_CTX* ctx, unsigned char *ptr, int n)
      {
      ctx->block[n] = (unsigned int)ptr[n * 4] |
      ((unsigned int)ptr[n * 4 + 1] << 8) |
      ((unsigned int)ptr[n * 4 + 2] << 16) |
      ((unsigned int)ptr[n * 4 + 3] << 24) ;
      return ctx->block[n];
      }
      void *body(struct MD5_CTX *ctx, void *data, unsigned long size)
      {
      unsigned char *ptr;
      unsigned int a;
      unsigned int b;
      unsigned int c;
      unsigned int d;
      unsigned int saved_a;
      unsigned int saved_b;
      unsigned int saved_c;
      unsigned int saved_d;

      ptr = (unsigned char *)data;

      a = ctx->a;
      b = ctx->b;
      c = ctx->c;
      d = ctx->d;

      do {
      saved_a = a;
      saved_b = b;
      saved_c = c;
      saved_d = d;

      // Round 1
      a=STEPF( a, b, c, d, SET(ctx,ptr,0), 0xd76aa478, 7);
      d=STEPF( d, a, b, c, SET(ctx,ptr,1), 0xe8c7b756, 12);
      c=STEPF( c, d, a, b, SET(ctx,ptr,2), 0x242070db, 17);
      b=STEPF( b, c, d, a, SET(ctx,ptr,3), 0xc1bdceee, 22);
      a=STEPF( a, b, c, d, SET(ctx,ptr,4), 0xf57c0faf, 7);
      d=STEPF( d, a, b, c, SET(ctx,ptr,5), 0x4787c62a, 12);
      c=STEPF( c, d, a, b, SET(ctx,ptr,6), 0xa8304613, 17);
      b=STEPF( b, c, d, a, SET(ctx,ptr,7), 0xfd469501, 22);
      a=STEPF( a, b, c, d, SET(ctx,ptr,8), 0x698098d8, 7);
      d=STEPF( d, a, b, c, SET(ctx,ptr,9), 0x8b44f7af, 12);
      c=STEPF( c, d, a, b, SET(ctx,ptr,10), 0xffff5bb1, 17);
      b=STEPF( b, c, d, a, SET(ctx,ptr,11), 0x895cd7be, 22);
      a=STEPF( a, b, c, d, SET(ctx,ptr,12), 0x6b901122, 7);
      d=STEPF( d, a, b, c, SET(ctx,ptr,13), 0xfd987193, 12);
      c=STEPF( c, d, a, b, SET(ctx,ptr,14), 0xa679438e, 17);
      b=STEPF( b, c, d, a, SET(ctx,ptr,15), 0x49b40821, 22);


      // Round 2
      a=STEPG( a, b, c, d, GET(ctx,1), 0xf61e2562, 5);
      d=STEPG( d, a, b, c, GET(ctx,6), 0xc040b340, 9);
      c=STEPG( c, d, a, b, GET(ctx,11), 0x265e5a51, 14);
      b=STEPG( b, c, d, a, GET(ctx,0), 0xe9b6c7aa, 20);
      a=STEPG( a, b, c, d, GET(ctx,5), 0xd62f105d, 5);
      d=STEPG( d, a, b, c, GET(ctx,10), 0x02441453, 9);
      c=STEPG( c, d, a, b, GET(ctx,15), 0xd8a1e681, 14);
      b=STEPG( b, c, d, a, GET(ctx,4), 0xe7d3fbc8, 20);
      a=STEPG( a, b, c, d, GET(ctx,9), 0x21e1cde6, 5);
      d=STEPG( d, a, b, c, GET(ctx,14), 0xc33707d6, 9);
      c=STEPG( c, d, a, b, GET(ctx,3), 0xf4d50d87, 14);
      b=STEPG( b, c, d, a, GET(ctx,8), 0x455a14ed, 20);
      a=STEPG( a, b, c, d, GET(ctx,13), 0xa9e3e905, 5);
      d=STEPG( d, a, b, c, GET(ctx,2), 0xfcefa3f8, 9);
      c=STEPG( c, d, a, b, GET(ctx,7), 0x676f02d9, 14);
      b=STEPG( b, c, d, a, GET(ctx,12), 0x8d2a4c8a, 20);

      // Round 3
      a=STEPH( a, b, c, d, GET(ctx,5), 0xfffa3942, 4);
      d=STEPH2( d, a, b, c, GET(ctx,8), 0x8771f681, 11);
      c=STEPH( c, d, a, b, GET(ctx,11), 0x6d9d6122, 16);
      b=STEPH2( b, c, d, a, GET(ctx,14), 0xfde5380c, 23);
      a=STEPH( a, b, c, d, GET(ctx,1), 0xa4beea44, 4);
      d=STEPH2( d, a, b, c, GET(ctx,4), 0x4bdecfa9, 11);
      c=STEPH( c, d, a, b, GET(ctx,7), 0xf6bb4b60, 16);
      b=STEPH2( b, c, d, a, GET(ctx,10), 0xbebfbc70, 23);
      a=STEPH( a, b, c, d, GET(ctx,13), 0x289b7ec6, 4);
      d=STEPH2( d, a, b, c, GET(ctx,0), 0xeaa127fa, 11);
      c=STEPH( c, d, a, b, GET(ctx,3), 0xd4ef3085, 16);
      b=STEPH2( b, c, d, a, GET(ctx,6), 0x04881d05, 23);
      a=STEPH( a, b, c, d, GET(ctx,9), 0xd9d4d039, 4);
      d=STEPH2( d, a, b, c, GET(ctx,12), 0xe6db99e5, 11);
      c=STEPH( c, d, a, b, GET(ctx,15), 0x1fa27cf8, 16);
      b=STEPH2( b, c, d, a, GET(ctx,2), 0xc4ac5665, 23);

      // Round 4
      a=STEPI( a, b, c, d, GET(ctx,0), 0xf4292244, 6);
      d=STEPI( d, a, b, c, GET(ctx,7), 0x432aff97, 10);
      c=STEPI( c, d, a, b, GET(ctx,14), 0xab9423a7, 15);
      b=STEPI( b, c, d, a, GET(ctx,5), 0xfc93a039, 21);
      a=STEPI( a, b, c, d, GET(ctx,12), 0x655b59c3, 6);
      d=STEPI( d, a, b, c, GET(ctx,3), 0x8f0ccc92, 10);
      c=STEPI( c, d, a, b, GET(ctx,10), 0xffeff47d, 15);
      b=STEPI( b, c, d, a, GET(ctx,1), 0x85845dd1, 21);
      a=STEPI( a, b, c, d, GET(ctx,8), 0x6fa87e4f, 6);
      d=STEPI( d, a, b, c, GET(ctx,15), 0xfe2ce6e0, 10);
      c=STEPI( c, d, a, b, GET(ctx,6), 0xa3014314, 15);
      b=STEPI( b, c, d, a, GET(ctx,13), 0x4e0811a1, 21);
      a=STEPI( a, b, c, d, GET(ctx,4), 0xf7537e82, 6);
      d=STEPI( d, a, b, c, GET(ctx,11), 0xbd3af235, 10);
      c=STEPI( c, d, a, b, GET(ctx,2), 0x2ad7d2bb, 15);
      b=STEPI( b, c, d, a, GET(ctx,9), 0xeb86d391, 21);

      a += saved_a;
      b += saved_b;
      c += saved_c;
      d += saved_d;

      ptr += 64;
      } while (size -= 64);

      ctx->a = a;
      ctx->b = b;
      ctx->c = c;
      ctx->d = d;

      return ptr;
      }
      void MD5_Init(struct MD5_CTX *ctx)
      {
      ctx->a = 0x67452301;
      ctx->b = 0xefcdab89;
      ctx->c = 0x98badcfe;
      ctx->d = 0x10325476;

      ctx->lo = 0;
      ctx->hi = 0;
      }
      void MD5_Update(struct MD5_CTX *ctx, void *data, unsigned long size)
      {
      unsigned int saved_lo;
      unsigned long used;
      unsigned long available;

      saved_lo = ctx->lo;
      if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo)
      ctx->hi++;
      ctx->hi += size >> 29;

      used = saved_lo & 0x3f;

      if (used) {
      available = 64 - used;

      if (size < available) {
      memcpy(&ctx->buffer[used], data, size);
      return;
      }

      memcpy(&ctx->buffer[used], data, available);
      data = (unsigned char *)data + available;
      size -= available;
      body(ctx, ctx->buffer, 64);
      }

      if (size >= 64) {
      data = body(ctx, data, size & ~(unsigned long)0x3f);
      size &= 0x3f;
      }

      memcpy(ctx->buffer, data, size);
      }
      void MD5_Final(unsigned char *result, struct MD5_CTX *ctx)
      {
      unsigned long used;
      unsigned long available;

      used = ctx->lo & 0x3f;

      ctx->buffer[used++] = 0x80;

      available = 64 - used;

      if (available < 8) {
      memset(&ctx->buffer[used], 0, available);
      body(ctx, ctx->buffer, 64);
      used = 0;
      available = 64;
      }

      memset(&ctx->buffer[used], 0, available - 8);

      ctx->lo <<= 3;
      ctx->buffer[56] = ctx->lo;
      ctx->buffer[57] = rsh(ctx->lo, 8);
      ctx->buffer[58] = rsh(ctx->lo, 16);
      ctx->buffer[59] = rsh(ctx->lo, 24);
      ctx->buffer[60] = ctx->hi;
      ctx->buffer[61] = rsh(ctx->hi, 8);
      ctx->buffer[62] = rsh(ctx->hi, 16);
      ctx->buffer[63] = rsh(ctx->hi, 24);

      body(ctx, ctx->buffer, 64);

      result[0] = ctx->a;
      result[1] = rsh(ctx->a , 8);
      result[2] = rsh(ctx->a , 16);
      result[3] = rsh(ctx->a , 24);
      result[4] = ctx->b;
      result[5] = rsh(ctx->b , 8);
      result[6] = rsh(ctx->b , 16);
      result[7] = rsh(ctx->b , 24);
      result[8] = ctx->c;
      result[9] = rsh(ctx->c , 8);
      result[10] = rsh(ctx->c , 16);
      result[11] = rsh(ctx->c , 24);
      result[12] = ctx->d;
      result[13] = rsh(ctx->d , 8);
      result[14] = rsh(ctx->d , 16);
      result[15] = rsh(ctx->d , 24);

      memset(ctx, 0, sizeof(*ctx));
      }

      // Convert 16 byte MD5 hash into printable HEX encoded string
      void MD5_CONVERT(char* iMD5, char* oMD5_A)
      {
      for (int i = 0; i < 16; i++)
      {
      sprintf(oMD5_A, "%02x", iMD5[i]);
      oMD5_A += 2;
      }
      *oMD5_A = 0;
      }

      void calculate_token(char* iUnauthorizedMessage, char* iMethod, char* iUser, char* iPassword, char* oRealm, char* oNonce, char* oDomain, char* oResponse)
      {
      if (iUnauthorizedMessage == 0)
      return;
      if (iMethod == 0)
      return;
      if (iUser == 0)
      return;
      if (iPassword == 0)
      return;
      if (oRealm == 0)
      return;
      if (oNonce == 0)
      return;
      if (oResponse == 0)
      return;
      if (oDomain == 0)
      return;

      *oRealm=0;
      *oNonce=0;
      *oResponse=0;
      *oDomain=0;

      char* unauthorized=strstrskip(iUnauthorizedMessage, "401 Unauthorized");
      if (unauthorized==0)
      return;

      // Retrieve realm
      char* realm=strstrskip(unauthorized, "realm="");
      if (realm==0)
      return;
      char* closing_realm=index(realm, '"');
      if (closing_realm != 0)
      {
      *closing_realm=0;
      closing_realm++;
      }

      // Retrieve domain
      char* domain=strstrskip(closing_realm, "domain="");
      if (domain == 0)
      return;
      char* closing_domain=index(domain, '"');
      if (closing_domain != 0)
      {
      *closing_domain=0;
      closing_domain++;
      }

      // Retrieve nonce
      char* nonce=strstrskip(closing_domain, "nonce="");
      if (nonce == 0)
      return;
      char* closing_nonce=index(nonce, '"');
      if (closing_nonce != 0)
      {
      *closing_nonce=0;
      closing_nonce++;
      }

      // Struct to do MD5 calculations
      struct MD5_CTX ctx;

      // Create HA1 MD5: username:realmassword
      char HA1_TEXT[1000];
      HA1_TEXT[0]=0;
      strcat(HA1_TEXT, iUser);
      strcat(HA1_TEXT, ":");
      strcat(HA1_TEXT, realm);
      strcat(HA1_TEXT, ":");
      strcat(HA1_TEXT, iPassword);
      MD5_Init(&ctx);
      MD5_Update(&ctx, HA1_TEXT, strlen(HA1_TEXT));
      char HA1_MD5[16];
      MD5_Final(HA1_MD5, &ctx);
      char HA1_MD5_A[32+1];
      MD5_CONVERT(HA1_MD5, HA1_MD5_A);

      // Create HA2 MD5: METHOD:URI
      char HA2_TEXT[1000];
      HA2_TEXT[0]=0;
      strcat(HA2_TEXT, iMethod);
      strcat(HA2_TEXT, ":");
      strcat(HA2_TEXT, domain);
      MD5_Init(&ctx);
      MD5_Update(&ctx, HA2_TEXT, strlen(HA2_TEXT));
      char HA2_MD5[16];
      MD5_Final(HA2_MD5, &ctx);
      char HA2_MD5_A[32+1];
      MD5_CONVERT(HA2_MD5, HA2_MD5_A);

      // Create Response MD5: HA1:nonce[:request counter][:client nonce][:quality of protection code]:HA2
      char RESPONSE_TEXT[1000];
      RESPONSE_TEXT[0]=0;
      strcat(RESPONSE_TEXT, HA1_MD5_A);
      strcat(RESPONSE_TEXT, ":");
      strcat(RESPONSE_TEXT, nonce);
      strcat(RESPONSE_TEXT, ":");
      strcat(RESPONSE_TEXT, HA2_MD5_A);
      MD5_Init(&ctx);
      MD5_Update(&ctx, RESPONSE_TEXT, strlen(RESPONSE_TEXT));
      char RESPONSE_TEXT_MD5[16];
      MD5_Final(RESPONSE_TEXT_MD5, &ctx);
      char RESPONSE_TEXT_MD5_A[32+1];
      MD5_CONVERT(RESPONSE_TEXT_MD5, RESPONSE_TEXT_MD5_A);

      strcpy(oRealm,realm);
      strcpy(oNonce,nonce);
      strcpy(oDomain,domain);
      strcpy(oResponse,RESPONSE_TEXT_MD5_A);

      //printf("realm=%s\n", oRealm);
      //printf("nonce=%s\n", oNonce);
      //printf("domain=%s\n", oDomain);
      //printf("Response=%s\n", oResponse);
      }

      STREAM* open_stream(char* iAdress, int iPort)
      {
      char address[200]; address[0]=0;
      sprintf(address, "/dev/tcp/%s/%d", iAdress, iPort);
      return stream_create(address, 0, 0);
      }

      char* HttpCommand(char* host, int port, char* iCommand, char* buffer, int buflen)
      {
      STREAM* pTcpStream = open_stream(host, port);

      stream_write(pTcpStream, iCommand, strlen(iCommand)); // write to output buffer
      stream_flush(pTcpStream); // flush output buffer

      int nBytesReceived = 0;
      int nCnt = 0;

      // read stream
      // TODO: check for buffer length
      char szTmpBuffer[RD_BLOCK_SIZE];
      do
      {
      nCnt = stream_read(pTcpStream, szTmpBuffer, RD_BLOCK_SIZE, 4000);
      if (nCnt > 0)
      memcpy((char*)buffer + nBytesReceived, szTmpBuffer, nCnt);
      nBytesReceived += nCnt;
      } while (nCnt > 0);
      buffer[nBytesReceived] = 0;
      stream_close(pTcpStream);
      return buffer;
      }

      char* HttpPostAuthorization(char* host, int port, char* uri, char* auth, char* content, char* buffer, int buflen)
      {
      char contentlength[16]; contentlength[0] = 0;
      sprintf(contentlength, "%d", strlen(content));

      char pTcpCmd[4000]; pTcpCmd[0] = 0;
      strcpy(pTcpCmd, "POST "); strcat(pTcpCmd, uri); strcat(pTcpCmd, " HTTP/1.0\r\n");
      strcat(pTcpCmd, "Host: "); strcat(pTcpCmd, host); strcat(pTcpCmd, "\r\n");
      strcat(pTcpCmd, "Accept: text / plain; charset = utf - 8\r\n");
      strcat(pTcpCmd, "Content-Length: "); strcat(pTcpCmd, contentlength); strcat(pTcpCmd, "\r\n");
      if (auth[0]!=0)
      strcat(pTcpCmd, auth);
      strcat(pTcpCmd, "User-Agent: LoxLIVE [en]\r\n");
      strcat(pTcpCmd, "\r\n");
      strcat(pTcpCmd, content);
      return HttpCommand(host, port, pTcpCmd, buffer, buflen);
      }

      char* HttpPost(char* host, int port, char* uri, char* username, char* password, char* auth, char* content, char* buffer, int buflen)
      {
      buffer[0]=0;
      char* res = HttpPostAuthorization(host, port, uri, auth, content, buffer, buflen);
      if (strstr(res, "401 Unauthorized") != 0)
      {
      printf("Calculate authorization and try again\n");
      char realm[200]; realm[0] = 0;
      char nonce[200]; nonce[0] = 0;
      char domain[200]; domain[0] = 0;
      char response[200]; response[0] = 0;
      calculate_token(res, "POST", username, password, realm, nonce, domain, response);
      auth[0] = 0;
      sprintf(auth, "Authorization: Digest username="%s",realm="%s",nonce="%s",uri="%s",respo nse="%s"\r\n", username, realm, nonce, domain, response);
      buffer[0]=0;
      res = HttpPostAuthorization(host, port, uri, auth, content, buffer, buflen);
      }
      return res;
      }

      void GetTempValue(char* value, char* after, int* h, int* l)
      {
      *h=-1000;
      *l=-1000;
      char* v = strstrskip(value, after);
      if (v!=0)
      {
      char* closing=index(v, ',');
      if (closing != 0)
      {
      *closing=0;
      *l=atoi(v);
      *closing=',';
      v=closing;
      v++;
      closing=index(v,']');
      if (closing != 0)
      {
      *closing=0;
      *h=atoi(v);
      *closing=',';
      }
      }
      }
      }

      double GetTempValueDouble(char* value, char* after)
      {
      double res = -1000;
      int h,l;
      GetTempValue(value, after, &h, &l);
      if (h>=0 && l>=0)
      {
      if (h<128)
      res=((h*256)+l)/10.0;
      else
      res=-((256-h)*256-l)/10.0;
      }
      return res;
      }

      // Configuration data
      #define READ_INTERVAL 600
      #define USERNAME "username"
      #define PASSWORD "password"
      #define HOST "192.168.178.10"
      #define PORT 80

      // Hold authorization data
      char auth[200]; auth[0] = 0;

      // Start of program
      int read_on_start = 1;
      unsigned int last_read = getcurrenttime();
      int sREAD_INTERVAL=READ_INTERVAL;
      int bad_reads = 0;

      while (TRUE)
      {
      int nEvents = getinputevent();
      unsigned int current_time = getcurrenttime();
      // READ every READ_INTERVAL seconds
      // READ when the user forces through the UI
      // READ every 10 seconds if the last read was bad and there were no more than 100 bad reads
      if ( (nEvents & 0xe) || read_on_start==1 || (current_time - last_read) > READ_INTERVAL || (bad_reads > 0 && bad_reads < 100 && (current_time - last_read) > 10) )
      {

      last_read = getcurrenttime();
      read_on_start = 0;

      //printf("start event\n");
      char* pJSON = "{"prot":"coco","telegramm":[[6,1,1,17,0,0,0,0],[6,2,1,17,0,0,0,0],[10,0,1,12,0,0,0,0]}";
      char szBuffer[BUFF_SIZE]; szBuffer[0] = 0;
      char* res = HttpPost(HOST, PORT, "/parameter.json", USERNAME, PASSWORD, auth, pJSON, szBuffer, BUFF_SIZE);
      printf("Weishaupt HTTPOST Response=%s\n", res);
      double temp_g=GetTempValueDouble(res, "[6,1,1,17,0,0,");
      if (temp_g > -100)
      setoutput(0,temp_g);
      double temp_u=GetTempValueDouble(res, "[6,2,1,17,0,0,");
      if (temp_u > -100)
      setoutput(1,temp_u);
      double temp_o=GetTempValueDouble(res, "[10,0,1,12,0,0,");
      if (temp_o > -100)
      setoutput(2,temp_o);
      if (temp_g> -100 || temp_u > -100 || temp_o > -100)
      {
      bad_reads=0;
      char date_time[100];
      sprintf(date_time,"%02d-%02d-%04d %02d:%02d:%02d",getday(current_time,1), getmonth(current_time,1), getyear(current_time,1), gethour(current_time,1), getminute(current_time,1), getsecond(current_time,1));
      setoutputtext(0, date_time);
      }
      else
      {
      bad_reads++;
      }

      //printf("end event\n");

      }
      sleep(100);
      }

      Kommentar

      • Gast

        #4
        Hi, thanks for your code and the link, I got it working on the FB, in plain C and using libcurl to handle the POST requests.

        Just in case this could be interesting to you, with "Freetz" you can compile your own programs for the Fritzbox and transfer them via SCP. You can even include whatever libraries you want into the firmware image, as long as it doesn't get too big for the flash of course. I had to learn the ropes of it, but I'm fascinated what I can do now with my "router"

        Kommentar

        • guido4096
          Dumb Home'r
          • 11.10.2015
          • 18

          #5
          Thanks for the update, great it worked!

          Kommentar

          Lädt...