Español      English

Navigation


Software specifically written for Water4Bits

Program for arduino (squidbee) that read sensor data from the serial port

/*
Programa para SquidBee
*/
// variables declaration

int sens0 = 0; //sensors
int sens1 = 1;
int sens2 = 2;

int val0 = 0; //aux var
int val1 = 0;
int val2 = 0;

int count = 0;

void setup(){
Serial.begin(19200); //inicializa el puerto serie
}

// function to send data

void sendData(int id,int num, int luminosidad,int humedad,int temperatura){

float l, h, t;

Serial.print("@");
Serial.print(id);
Serial.print("|");

Serial.print(num);

Serial.print("|luminosidad-");
l = (100.0 / 950.0) * luminosidad;
Serial.print((int)l);

Serial.print("|humedad-");
h = (humedad * 5.0 / 1024.0) * 32.25 - 25.81;
Serial.print((int)h);

Serial.print("|temperatura-");
t = (temperatura * 5.0 / 1024.0) / 0.01;
Serial.print((int)t);

Serial.println("#\r"); // end of message
}SQUIDBEE

void loop(){
while (count <= 10000){
val0 = analogRead(sens0);
val1 = analogRead(sens1);
val2 = analogRead(sens2);

sendData(1,count, val0,val1,val2);

delay(5000);
count++;
}

count = 0;

}

Program that sends data from the serial port (sensor) to an ftp server

#!/usr/bin/ruby

require 'net/ftp'
require "serialport"

def leerarduino
puerto = "/dev/ttyUSB0" #may be different for you
baudios = 19200
data_bits = 8
stop_bits = 1
paridad = SerialPort::NONE
sp = SerialPort.new(puerto, baudios, data_bits, stop_bits, paridad)
sleep 1
cadena = sp.gets
sp.close
return cadena
end

def subearchivo
print "> Conectando FTP...\n"
ftp = Net::FTP.new('ladecadence.net', 'davpel', 'monochrome')
print "> Accediendo...\n"
files = ftp.chdir('ladecadence.net')
print "> Subiendo archivo...\n"
files = ftp.puttextfile("datos.txt", "datos.txt")

ftp.close
print "> OK.\n"
end

############################ Principal

while true
datos = nil
while datos == nil
datos = leerarduino
end

print datos

print "> Escribiendo archivo...\n"
archivo = File.new("datos.txt", "w")
archivo.puts(datos)
archivo.close
print "> OK.\n"

subearchivo

sleep 10
end

Program that reads the ftp server and visualizes temperature and luminic sensor data on OpenSim (color and alpha channle), LSL (Linden Scripting Language)

key http_id;

// convertir la temperatura en un vector de colores SL.
vector colorTemp(integer temp)
{
float intermedio;

if(temp < 15) return <0.0,0.0,0.0>;
if(temp > 30) return <1.0,0.0,0.0>;

intermedio = (temp-15.0)/15.0;

return ;
}

default
{

state_entry()
{
llSetTimerEvent(10.0); // ponemos el timer a 10 segundos

}

//funcion llamada por el timer
timer()
{
//hacemos la peticion http;
http_id = llHTTPRequest("http://ladecadence.net/datos.txt", HTTP_METHOD, "GET","");
}

//funcion que se llama automaticamente cuando recibe la respuesta del HTTP
http_response(key request_id, integer status, list metadata, string body)
{
if (request_id == http_id)
{
string temperatura, luminosidad, humedad;

list listavalores = llParseString2List(body," ",".");

luminosidad = llList2String(listavalores, 0);
humedad = llList2String(listavalores, 1);
temperatura = llList2String(listavalores, 2);

llSay(0, "Luminosidad: " + luminosidad);
llSay(0, "Humedad: " + humedad);
llSay(0, "Temperatura: " + temperatura);

vector color = colorTemp((int)temperatura); //convertimos la temperatura en vector de color

llSetColor(color, ALL_SIDES); // ponemos el color del objeto

integer lum = (int) luminosidad;
if (lum == 0) lum = 1;

float lumf = lum / 100.0;

llSetAlpha(lumf, ALL_SIDES);
}
}

}


Proyecto producido para la BIACS 3
WWB Soc. Coop. And. 2008 hackitectura.net