;; interface to the pachube API ;; http://community.pachube.com/?q=node/127 ;; http://community.pachube.com/api ; ; ; ; ; 36.2 ; ; ; (module pachube scheme (require net/url) (provide (all-defined-out)) (define source (string->url "http://www.pachube.com/api/1951.xml")) (define api-key "") (define (format-data l m) (string-append " " l "" m "")) (define serial (open-input-file "/dev/cu.usbserial-A6004bp0")) (define (read-serial) (process (read-line serial)) (read-serial)) (define (process str) (let ([data (regexp-split #rx"," str)]) (printf "light: ~a, moisture: ~a~n" (list-ref data 1) (list-ref data 2)) (send-data (list-ref data 1) (list-ref data 2)))) ;; retrive data ;; curl --request GET --header "X-PachubeApiKey: YOUR_API_KEY" "http://www.pachube.com/api/504.csv" (define (get-test) (get-pure-port source (list (string-append "X-PachubeApiKey: " api-key)))) ;; update the values from a feed ;; curl --request PUT --header "X-PachubeApiKey: YOUR_API_KEY" --data "test" "http://www.pachube.com/api/504.csv" (define (send-data l m) (display-pure-port (put-impure-port source (string->bytes/utf-8 (format-data l m)) (list (string-append "X-PachubeApiKey: " api-key))))) )