Merge branch 'master' of ssh://dave@fo.am/var/git/groworld

This commit is contained in:
Dave Griffiths 2009-06-12 09:58:45 +01:00
commit 72e6024a76
4 changed files with 118 additions and 1 deletions

View file

@ -12,7 +12,7 @@
start(_Host, _Opt) -> start(_Host, _Opt) ->
?DEBUG("MYCELIUM LOADING...", []). ?DEBUG("MYCELIUM LOADING...", []).
stop(_Host) -> stop(Host) ->
?DEBUG("MYCELIUM UNLOADING...", []). ?DEBUG("MYCELIUM UNLOADING...", []).
%%-define(PROCNAME, ejabberd_mycelium). %%-define(PROCNAME, ejabberd_mycelium).

14
xylem/README.txt Normal file
View file

@ -0,0 +1,14 @@
Basic plant sensor kit which currently outputs;
- soil humidity
- light levels
- human presence
Hardware interface based loosly on recollection of Martin Howse's
experiements with the Wheatstone Bridge[1] and incorporates parts of a
design published by Rob Faludi[2] which was in turn based on a design
by Forrest Mims, with nods to L. George Lawrence, Botanicalls and the
long and tangled path from Jagdish Chandra Bose.
[1] during piskel08
[2] http://www.faludi.com/2006/11/02/moisture-sensor-circuit/

55
xylem/serial->pachube.scm Executable file
View file

@ -0,0 +1,55 @@
;; interface to the pachube API
;; http://community.pachube.com/?q=node/127
;; http://community.pachube.com/api
;<?xml version="1.0" encoding="UTF-8"?>
;<eeml xmlns="http://www.eeml.org/xsd/005">
; <environment>
; <data id="0">
; <value>36.2</value>
; </data>
; </environment>
;</eeml>
(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 "<?xml version='1.0' encoding='UTF-8'?><eeml xmlns='http://www.eeml.org/xsd/005'>
<environment><data id='0'><value>" l "</value></data><data id='1'><value>" m "</value></data></environment></eeml>"))
(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)))))
)

48
xylem/xylem.pde Normal file
View file

@ -0,0 +1,48 @@
// part of the groworld HPI prototype
#include <stdio.h>
#define lightpin 1 // light sensor on analog pin 1
#define humidpin 0 // humidity sensor on analog pin 0
#define power 8 // power for sensors
unsigned long then = 0; // timer which will run for < 50 days
unsigned long interval = 1; // interval between reads in seconds
void setup()
{
pinMode(power, OUTPUT);
pinMode(humidpin, INPUT);
pinMode(lightpin, INPUT);
Serial.begin(9600);
}
int lightlevel ()
{
int light = 0;
light = (analogRead(lightpin));
return light;
}
int moisturelevel ()
{
int moist = 0;
digitalWrite(power, HIGH);
moist = (analogRead(humidpin));
digitalWrite(power, LOW);
return moist;
}
char display[64];
void loop()
{
if (millis() - then > interval*1000) {
then = millis();
sprintf(display, "%u,%u,%u\n", (unsigned int)then, lightlevel(), moisturelevel());
Serial.print(display);
}
}