plant sensing update & wireless tests
This commit is contained in:
parent
610762c1ee
commit
811274f7e3
6 changed files with 196 additions and 0 deletions
37
xylem/xylem_serial/serial->xmpp.scm
Executable file
37
xylem/xylem_serial/serial->xmpp.scm
Executable file
|
@ -0,0 +1,37 @@
|
|||
;; send sensor data via xmpp
|
||||
|
||||
|
||||
(module serial->xmpp scheme
|
||||
|
||||
(require (planet zzkt/xmpp))
|
||||
(provide (all-defined-out))
|
||||
|
||||
(define serial (open-input-file "/dev/tty.usbserial-A9007Lgy"))
|
||||
|
||||
(define (read-serial)
|
||||
(process (read-line serial))
|
||||
;(read-serial)
|
||||
)
|
||||
|
||||
(define (scale b t n)
|
||||
(/ (- t (/ (string->number n) 1024.0)) (- t b)))
|
||||
|
||||
(define (process str)
|
||||
(let ([data (regexp-split #rx"," str)])
|
||||
(format "vrob light-level=n:~a soil-moisture=n:~a"
|
||||
(scale 0.9 1 (list-ref data 1))
|
||||
(scale 0 1.0 (list-ref data 2)))))
|
||||
|
||||
;; send via xmpp
|
||||
|
||||
(define (send-data)
|
||||
(with-xmpp-session "plant0000005@fo.am" "plant0000005"
|
||||
(let sendrec ()
|
||||
(begin (send (message "plant0000003@fo.am" (read-serial)))
|
||||
(sleep 0.5)
|
||||
(sendrec)))))
|
||||
|
||||
)
|
||||
|
||||
|
||||
|
56
xylem/xylem_serial/xylem_serial.pde
Normal file
56
xylem/xylem_serial/xylem_serial.pde
Normal file
|
@ -0,0 +1,56 @@
|
|||
///////////// part of the groworld HPI prototype
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define lightpin 1 // light sensor on analog pin 1
|
||||
#define temppin 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
|
||||
|
||||
|
||||
///////////// set up & send
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(power, OUTPUT);
|
||||
pinMode(temppin, INPUT);
|
||||
pinMode(lightpin, INPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int lightlevel ()
|
||||
{
|
||||
int light = 0;
|
||||
light = (analogRead(lightpin));
|
||||
return light;
|
||||
}
|
||||
|
||||
int templevel ()
|
||||
{
|
||||
int temp = 0;
|
||||
temp = (analogRead(temppin));
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
|
||||
///////////// main loop. sends data to pachube and prints values to serial line
|
||||
|
||||
char display[64];
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - then > interval*1000) {
|
||||
then = millis();
|
||||
sprintf(display, "%u,%u,%u\n", (unsigned int)then, lightlevel(), templevel());
|
||||
Serial.print(display);
|
||||
}
|
||||
}
|
||||
|
||||
/////////////
|
||||
|
29
xylem/xylem_wireless_recv/xylem_wireless_recv.pde
Normal file
29
xylem/xylem_wireless_recv/xylem_wireless_recv.pde
Normal file
|
@ -0,0 +1,29 @@
|
|||
///////////// part of the groworld HPI prototype
|
||||
|
||||
///////////// serial -> wireless setup
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define rxPin 0
|
||||
#define txPin 1
|
||||
|
||||
// set up a new serial port
|
||||
SoftwareSerial wireless = SoftwareSerial(rxPin, txPin);
|
||||
|
||||
void setup()
|
||||
{
|
||||
// wireless serial
|
||||
pinMode(rxPin, INPUT);
|
||||
pinMode(txPin, OUTPUT);
|
||||
wireless.begin(4800);
|
||||
|
||||
// wired serial output
|
||||
Serial.begin(9600);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// read, then write
|
||||
char someChar = wireless.read();
|
||||
Serial.print(someChar);
|
||||
}
|
74
xylem/xylem_wireless_sense/xylem_wireless_sense.pde
Normal file
74
xylem/xylem_wireless_sense/xylem_wireless_sense.pde
Normal file
|
@ -0,0 +1,74 @@
|
|||
///////////// part of the groworld HPI prototype
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#define lightpin 1 // light sensor on analog pin 1
|
||||
#define temppin 0 // humidity sensor on analog pin 0
|
||||
#define power 8 // power for humidity sensor
|
||||
|
||||
unsigned long then = 0; // timer which will run for < 50 days
|
||||
unsigned long interval = 1; // interval between reads in seconds
|
||||
|
||||
///////////// serial -> wireless setup
|
||||
|
||||
#include <SoftwareSerial.h>
|
||||
|
||||
#define rxPin 0
|
||||
#define txPin 1
|
||||
|
||||
// set up a new serial port
|
||||
SoftwareSerial wireless = SoftwareSerial(rxPin, txPin);
|
||||
byte pinState = 0;
|
||||
|
||||
|
||||
///////////// set up & send
|
||||
|
||||
void setup()
|
||||
{
|
||||
// analogue sensors
|
||||
pinMode(power, OUTPUT);
|
||||
pinMode(temppin, INPUT);
|
||||
pinMode(lightpin, INPUT);
|
||||
|
||||
Serial.begin(9600);
|
||||
|
||||
// wireless serial
|
||||
pinMode(rxPin, INPUT);
|
||||
pinMode(txPin, OUTPUT);
|
||||
wireless.begin(4800);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int lightlevel ()
|
||||
{
|
||||
int light = 0;
|
||||
light = (analogRead(lightpin));
|
||||
return light;
|
||||
}
|
||||
|
||||
int templevel ()
|
||||
{
|
||||
int temp = 0;
|
||||
temp = (analogRead(temppin));
|
||||
return temp;
|
||||
}
|
||||
|
||||
|
||||
///////////// main loop. sends data to pachube and prints values to serial line
|
||||
|
||||
char display[64];
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - then > interval*1000) {
|
||||
then = millis();
|
||||
sprintf(display, "%u,%u,%u\n", (unsigned int)then, lightlevel(), templevel());
|
||||
wireless.print (display);
|
||||
Serial.print(".");
|
||||
}
|
||||
}
|
||||
|
||||
/////////////
|
||||
|
Loading…
Reference in a new issue