From f3295bd150079984d115faad0a5a9de10c6d6de0 Mon Sep 17 00:00:00 2001 From: Ebus-at-dockstar Date: Tue, 16 Sep 2014 01:36:38 +0200 Subject: ersatzwerte --- ebus-racket/inserter.rkt | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'ebus-racket/inserter.rkt') diff --git a/ebus-racket/inserter.rkt b/ebus-racket/inserter.rkt index d72d2ea..b234ad9 100755 --- a/ebus-racket/inserter.rkt +++ b/ebus-racket/inserter.rkt @@ -19,19 +19,22 @@ ;; Send field and value to database server (define (insert-field sensor-name datatype value) - (define url (format "~a/~a" (baseurl?) sensor-name)) - (define raw-value - (cond ((member datatype '(data1c data2b data2c)) (real->decimal-string value)) - ((member datatype '(bit byte data1b word bcd)) (format "~s" value)) - ((member datatype '(byteEnum)) value) - (else (error 'invalid-datatype)))) - (define input-port (put-impure-port (string->url url) (string->bytes/utf-8 raw-value))) - (define server-response (read-line input-port)) - (close-input-port input-port) - (cond ((string=? (list-ref (string-split server-response) 1) "200") - (log-inserter-info "OK: ~a : ~a" url raw-value)) - (else - (error "server-error" url raw-value server-response)))) + (if (layer7-ersatzwert? value) + (log-inserter-info "Skipping Ersatzwert for ~a/~a" sensor-name datatype) + (let () + (define url (format "~a/~a" (baseurl?) sensor-name)) + (define raw-value + (cond ((member datatype '(data1c data2b data2c)) (real->decimal-string value)) + ((member datatype '(bit byte data1b word bcd)) (format "~s" value)) + ((member datatype '(byteEnum)) value) + (else (error 'invalid-datatype)))) + (define input-port (put-impure-port (string->url url) (string->bytes/utf-8 raw-value))) + (define server-response (read-line input-port)) + (close-input-port input-port) + (cond ((string=? (list-ref (string-split server-response) 1) "200") + (log-inserter-info "OK: ~a : ~a" url raw-value)) + (else + (error "server-error" url raw-value server-response)))))) (define (handle-packet packet) (for ([field packet]) -- cgit v1.2.1