Last active
February 25, 2019 16:43
-
-
Save windymelt/a35ccd04dd930cf378c3333080731d5a to your computer and use it in GitHub Desktop.
GROVE dirt humidity sensor example code in golang
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"github.com/JGrotex/GrovePi/Software/Go/grovepi" | |
"fmt" | |
) | |
func runDirt() string { | |
var g grovepi.GrovePi | |
g = *grovepi.InitGrovePi(0x04) | |
defer g.CloseDevice() | |
i, err := g.AnalogRead(grovepi.A0) | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Humidity: %d\n", i) | |
return "done" | |
} | |
func main() { | |
runDirt() | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
#|-*- mode:lisp -*-|# | |
#| | |
exec ros -Q -- $0 "$@" | |
|# | |
(progn ;;init forms | |
(ros:ensure-asdf) | |
#+quicklisp (ql:quickload '(:jsown :local-time :dexador) :silent t) | |
) | |
(defpackage :ros.script.post-humidity.3760098712 | |
(:use :cl)) | |
(in-package :ros.script.post-humidity.3760098712) | |
(defparameter *mackerel-api-key* ".....") | |
(defmethod to-mackerel-time ((time local-time:timestamp)) | |
(local-time:timestamp-to-unix time)) | |
(defun build-service-metrics-object (metric-name metric-time metric-val) | |
(list (list | |
:obj | |
(cons "name" metric-name) | |
(cons "time" (to-mackerel-time metric-time)) | |
(cons "value" metric-val)))) | |
(defun post-service-metrics (service-name metric-name metric-time metric-val) | |
(dex:post (format nil "https://mackerel.io/api/v0/services/~A/tsdb" service-name) | |
:headers `(("x-api-key" . ,*mackerel-api-key*) | |
("content-type" . "application/json")) | |
:content (jsown:to-json (build-service-metrics-object metric-name metric-time metric-val)))) | |
(defun main (&rest argv) | |
(declare (ignorable argv)) | |
(post-service-metrics "bacuralis" "soil.humidity" (local-time:now) (parse-integer (car argv)))) | |
;;; vim: set ft=lisp lisp: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment