Ich habe eine funktionierende Lösung mit dem EHZ Lesekopf von Volkszähler, einfach an die serielle Schnittstelle von einem Arduino Ethernet bzw. Itead Iboard anschließen und der stellt dann eine HTML Seite mit dem aktuellen Verbrauch und dem Zählerstand. Ich Werte das dann mit meinem Gira HS aus.
Vielleicht hilft es auch Oldie eine direkte Anbindung mit dem LPC auf KNX zu zaubern

Gruss
Norbert
Code:
/**
* Copyright (c) 2012 Volker Wegert <ehzy@volker-wegert.de>
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Volker Wegert - initial implementation
* Norbert Schnitzler - EMH EHZ and HTML modifications
*/
#include <stdarg.h>
#include <stdio.h>
#include <avr/pgmspace.h>
#include <SPI.h>
#include <Ethernet.h>
/***************************************************************************************************
* CONSTANTS
***************************************************************************************************/
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};
byte ip[] ={
192,168,178,50};
byte gateway[]={
192,168,178,1};
byte subnet[] = {
255, 255, 255, 0 };
EthernetServer server(80);
/**
* size of the SML message buffer = meximum number of bytes that can be received
*/
#define SML_MSG_BUFFER_SIZE 500
/**
* maximum time to wait for the end of a data packet received via IR
*/
#define SERIAL_READ_TIMEOUT_MS 100
/***************************************************************************************************
* MESSAGES
***************************************************************************************************/
/**
* maximum length of a message (entire text after variable substitution!)
*/
#define MAX_MESSAGE_LENGTH 50
/**
* message numbers
*/
#define MSG_PROGRAM_STOPPED 0
#define MSG_NEXT_FILENAME 1
#define MSG_NO_FILE_NAMES_LEFT 2
#define MSG_INIT_HARDWARE 3
#define MSG_INIT_SD_CARD 4
#define MSG_INIT_SD_CARD_ERROR 5
#define MSG_BYTE_READ 6
#define MSG_BUFFER_OVERFLOW 7
#define MSG_SERIAL_OVERFLOW 8
#define MSG_INVALID_HEADER 9
#define MSG_FILE_OPEN_FAILED 10
#define MSG_FILE_WRITTEN 11
#define MSG_FREE_MEMORY 12
#define MSG_NUM_BYTES_READ 13
/**
* actual message texts - caution, adapt MAX_MESSAGE_LENGTH if required!
* ....+....1....+....2....+....3....+....4....+....5
*/
prog_char msgText00[] PROGMEM = "Program stopped.";
prog_char msgText01[] PROGMEM = "Next output file name is '%s'";
prog_char msgText02[] PROGMEM = "No more file names left";
prog_char msgText03[] PROGMEM = "Initializing Hardware...";
prog_char msgText04[] PROGMEM = "Initializing SD Card...";
prog_char msgText05[] PROGMEM = "SD Card initialization failed";
prog_char msgText06[] PROGMEM = "Read byte %02hhu from IR receiver";
prog_char msgText07[] PROGMEM = "Message buffer overflow";
prog_char msgText08[] PROGMEM = "Serial buffer overflow";
prog_char msgText09[] PROGMEM = "Invalid escape sequence";
prog_char msgText10[] PROGMEM = "Unable to open output file";
prog_char msgText11[] PROGMEM = "%u bytes of data written to file '%s'";
prog_char msgText12[] PROGMEM = "%u bytes of memory available";
prog_char msgText13[] PROGMEM = "%u bytes read";
/**
* table for easier access to the message texts
*/
PROGMEM const char *msgTextTable[] = {
msgText00,
msgText01,
msgText02,
msgText03,
msgText04,
msgText05,
msgText06,
msgText07,
msgText08,
msgText09,
msgText10,
msgText11,
msgText12,
msgText13
};
/***************************************************************************************************
* GLOBAL VARIABLES (YUCK!)
***************************************************************************************************/
/**
* the global buffer to store the SML message currently being read
*/
unsigned char buffer[SML_MSG_BUFFER_SIZE];
unsigned char Aktuell[4];
float aktuell;
unsigned char Stand[4];
unsigned char Akt[4];
/***************************************************************************************************
* SUBROUTINES
***************************************************************************************************/
/**
* printMessage - reads a message text from the PROGMEM, performs variable substitution and
* writes the resulting text to the serial console. Use MSG_* constants for
* messageNumber.
*/
void printMessage(int messageNumber, ...) {
va_list args;
char format[MAX_MESSAGE_LENGTH];
char buffer[MAX_MESSAGE_LENGTH];
va_start(args, messageNumber);
strncpy_P(format, (char*)pgm_read_word(&(msgTextTable[messageNumber])), MAX_MESSAGE_LENGTH);
vsnprintf(buffer, MAX_MESSAGE_LENGTH, format, args);
Serial.println(buffer);
va_end(args);
}
void PrintHex8(uint8_t *data, uint8_t length) // prints 8-bit data in hex with leading zeroes
{
char tmp[16];
for (int i=0; i<length; i++) {
sprintf(tmp, "0x%.2X",data[i]);
Serial.print(tmp);
Serial.print(" ");
}
}
/**
* stop - stops program execution in a controlled fashion (endless loop).
*/
void stop() {
printMessage(MSG_PROGRAM_STOPPED);
while(1);
}
/**
* isValidHeader - returns true if the global message buffer begins with a valid SML escape sequence.
*/
inline boolean isValidHeader() {
return ((buffer[0] == 0x1b) ||
(buffer[1] == 0x1b) ||
(buffer[2] == 0x1b) ||
(buffer[3] == 0x1b) ||
(buffer[4] == 0x01) ||
(buffer[5] == 0x01) ||
(buffer[6] == 0x01) ||
(buffer[7] == 0x01));
}
/***************************************************************************************************
* MAIN ROUTINES
***************************************************************************************************/
/**
* setup - initialization routine run once after the device is powered up.
*/
void setup() {
// set the serial console speed
Serial.begin(9600);
// set the pin configuration
printMessage(MSG_INIT_HARDWARE);
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.println(Ethernet.localIP());
}
/**
* loop - main program, run in an endless loop
*/
void loop() {
unsigned int nextBufferPosition = 0;
unsigned long lastReadTime = 0;
// clear the message buffer
memset(buffer, 0, sizeof(buffer));
// wait until actual data is available
while (!Serial.available());
// keep reading data until either the message buffer is filled or no more data was
// received for SERIAL_READ_TIMEOUT_MS ms
lastReadTime = millis();
while (millis() - lastReadTime < SERIAL_READ_TIMEOUT_MS) {
if (Serial.available()) {
buffer[nextBufferPosition] = Serial.read();
lastReadTime = millis();
if (nextBufferPosition >= SML_MSG_BUFFER_SIZE) {
printMessage(MSG_BUFFER_OVERFLOW);
return;
}
nextBufferPosition += 1;
}
}
// check the header
printMessage(MSG_NUM_BYTES_READ, nextBufferPosition + 1);
if (!isValidHeader()) {
// not a valid header - notify the user...
printMessage(MSG_INVALID_HEADER);
// ...and empty the receiver buffer (wait for the end of the current data stream
while (Serial.available() > 0) {
Serial.read();
}
}
else {
for(int i=3;i>=0;i--){
Stand[3-i]=(buffer[143+i]);
Aktuell[3-i]=buffer[205+i];
}
}
unsigned long result = *((unsigned long *)(& Stand[0]));
double Result = result/10000;
int Rest = long(result)%10000;
float Ergebnis=(result/10000)+(float(long(result)%10000)/10000);
Serial.println(Ergebnis);
unsigned long aktuell = *((unsigned long *)(& Aktuell[0]));
float Verbrauch=(aktuell/10)+(float(long(aktuell)%10)/10);
Serial.println(Verbrauch);
EthernetClient client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<head/><meta http-equiv=\"refresh\" content=\"10\"/></head/>");
client.print("Verbrauch: ");
client.println(Verbrauch, DEC%3);
client.println("<br />");
client.print("Zaehler: ");
client.println(Ergebnis, DEC%3);
client.println("<br />");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
}