summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEbus-at-dockstar <ebus@dockstar>2015-05-10 00:22:11 +0200
committerEbus-at-dockstar <ebus@dockstar>2015-05-10 00:22:11 +0200
commitd123678766b26b553c72a4c6e8d255afdd90ebe8 (patch)
tree3f4e63c3cb644a61db48e05ffea249a70bf8d4ef
parenta21f4f23e847e09d801c44c16772191a8f1e35b1 (diff)
downloadebus-alt-d123678766b26b553c72a4c6e8d255afdd90ebe8.tar.gz
ebus-alt-d123678766b26b553c72a4c6e8d255afdd90ebe8.zip
insert influxdb
-rwxr-xr-xebus-racket/inserter.rkt14
1 files changed, 14 insertions, 0 deletions
diff --git a/ebus-racket/inserter.rkt b/ebus-racket/inserter.rkt
index b234ad9..c4a693b 100755
--- a/ebus-racket/inserter.rkt
+++ b/ebus-racket/inserter.rkt
@@ -15,6 +15,7 @@
(define connect-port? (make-parameter null))
(define insert? (make-parameter #f))
(define baseurl? (make-parameter "http://localhost:8080/api/value"))
+(define influxurl? (make-parameter "http://db.2.localnet.cc:8001/write/ZQYZHSLWEIWCMXIYQSKAOCFCFWEVFK"))
;; Send field and value to database server
@@ -36,6 +37,18 @@
(else
(error "server-error" url raw-value server-response))))))
+(define (insert-influxdb sensor-name datatype value)
+ (if (layer7-ersatzwert? value)
+ (log-inserter-info "Skipping Ersatzwert for ~a/~a" sensor-name datatype)
+ (let ([data (hash 'database "ebus"
+ 'points (list (hash 'name sensor-name
+ 'fields (hash 'value value
+ 'type (symbol->string datatype)))))])
+ (log-inserter-info (format "influxdb: ~a~n" (jsexpr->string data)))
+ (define input-port (post-impure-port (string->url (influxurl?)) (string->bytes/utf-8 (jsexpr->string data))))
+ (define server-response (read-line input-port))
+ (log-inserter-info "Response: ~a" server-response))))
+
(define (handle-packet packet)
(for ([field packet])
(when (insert?)
@@ -45,6 +58,7 @@
(log-inserter-error "TCP Read exception ~a" exn))]
[exn:fail:network? (lambda (exn)
(log-inserter-error "TCP Exception ~a" exn))])
+ (apply insert-influxdb field)
(apply insert-field field)))))
(define-namespace-anchor repl-ns-anchor)