summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)