diff options
author | Ebus-at-dockstar <ebus@dockstar> | 2013-04-30 17:49:26 +0200 |
---|---|---|
committer | Ebus-at-dockstar <ebus@dockstar> | 2013-04-30 17:49:26 +0200 |
commit | 5e002f200691d5fd9c46ff645668b82e17c2261b (patch) | |
tree | 25f100549ac72fd1edf66c457b63aa43704e9c93 /ebus-racket/inserter.rkt | |
parent | 8810ba02335d60b2afda0a2d1efb101461dac891 (diff) | |
download | ebus-alt-5e002f200691d5fd9c46ff645668b82e17c2261b.tar.gz ebus-alt-5e002f200691d5fd9c46ff645668b82e17c2261b.zip |
ebus-racket: inserter adaption; remove tcp-repl
Diffstat (limited to 'ebus-racket/inserter.rkt')
-rwxr-xr-x | ebus-racket/inserter.rkt | 22 |
1 files changed, 7 insertions, 15 deletions
diff --git a/ebus-racket/inserter.rkt b/ebus-racket/inserter.rkt index cd05ad9..a5a7ac8 100755 --- a/ebus-racket/inserter.rkt +++ b/ebus-racket/inserter.rkt @@ -1,11 +1,10 @@ #! /usr/bin/env racket #lang racket/base (require racket/cmdline - racket/tcp racket/stream + racket/tcp net/url "ebus/layer7.rkt" - "util/tcp-repl.rkt" "util/json.rkt") (define logger (make-logger 'ebus-inserter (current-logger))) @@ -13,7 +12,7 @@ (define connect-host? (make-parameter null)) (define connect-port? (make-parameter null)) (define insert? (make-parameter #f)) -(define baseurl? (make-parameter "http://localhost:8000/sensor")) +(define baseurl? (make-parameter "http://localhost:8080/api")) ;; Send field and value to database server (define (insert-field sensor-name datatype offset value) @@ -21,19 +20,14 @@ ((member datatype (list "bit" "byte" "data1b" "word" "bcd")) "int") ((member datatype (list "byteEnum")) "string"))) (set! value (cond ((string=? type "float") (real->decimal-string value)) + ((string=? type "int") (number->string value)) (else value))) - (define response - (read-line (put-pure-port - (string->url (format "~a/~a" (baseurl?) sensor-name)) - (string->bytes/utf-8 (format "value=~a&type=~a" value type))))) - (define responseJson (string->jsexpr response)) - (cond ((eq? (json-null) (hash-ref responseJson 'error)) - (log-message logger 'debug (format "Successful insert: type=~a value=~a" - type value) #t)) - (else (log-message logger 'error (format "Error: type=~a value=~a ERROR:~a" - type value response) #t)))) + (put-pure-port + (string->url (format "~a/value/~a" (baseurl?) sensor-name)) + (string->bytes/utf-8 value))) (define (handle-packet packet) + (for ([field packet]) (log-message logger 'info (format "Field: ~a" field) #t) (when (insert?) @@ -54,8 +48,6 @@ [("-c" "--connect") host port "Connect to server <host> <port>" (connect-host? host) (connect-port? (string->number port))] - ["--tcp-repl" port "Open REPL on TCP <port>" - (tcp-repl-run (namespace-anchor->namespace repl-ns-anchor) (string->number port))] ["--insert" "Do Insert into Database" (insert? #t)] ["--baseurl" url "Database server http url" |