sir i m working on monitoring and control system for wsn using telosb
mote....... i have 2 motes and 1 base station.... these 2 motes monitor
temperature and humidity and sent to base station ...... my monitoring part is
complete and i m getting values of temperature and humidity in java
application now i want to send my these coming temperature and humidity
values to relays through parallel interface......
mye code is written below i need parallel interface code where i write
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/* need parallel interface code to send these temperature and humidty
values to relays( external hardware)
*/
*////////////////////////////////////////////////////////
code of oscilloscope apllication is
public class Oscilloscope implements MessageListener
{
MoteIF mote;
Data data;
Window window;
int interval = Constants.DEFAULT_INTERVAL;
int version = -1;
/* Main entry point */
void run() {
data = new Data(this);
window = new Window(this);
window.setup();
mote = new MoteIF(PrintStreamMessenger.err);
mote.registerListener(new OscilloscopeMsg(), this);
}
/* The data object has informed us that nodeId is a previously unknown
mote. Update the GUI. */
void newNode(int nodeId) {
window.newNode(nodeId);
}
public synchronized void messageReceived(int dest_addr,
Message msg) {
if (msg instanceof OscilloscopeMsg) {
OscilloscopeMsg omsg = (OscilloscopeMsg)msg;
/* Update interval and mote data */
periodUpdate(omsg.get_version(), omsg.get_interval());
int[] readings = omsg.get_readings();
double avg = 0, total = 0, temp = 0;
for (int i =0; i < readings.length; i++)
{
total += readings[i];
}
avg = (total*1.0)/readings.length;
if (omsg.get_id() == 1)
{
temp = -38.4 + 0.0098 * avg;
temp = temp*100;
int t = (int)temp;
temp = t/100.0;
System.out.println("Room Temperature = " + temp + "°C From Node 1");
}
double temp1= 0;
if (omsg.get_id() == 3)
{
temp1 = -38.4 + 0.0098 * avg;
temp1 = temp1*100;
int t1 = (int)temp1;
temp1 = t1/100.0;
System.out.println("Room Temperature = " + temp1 + "°C From Node 2");
}
double hum = 0;
if (omsg.get_id() == 2)
{
hum = -0.0000028*avg*avg + 0.0405*avg-4;
hum = hum*100;
int h = (int)hum;
hum = h/100.0;
System.out.println("Room Humidity = " + hum + "% From Node 1");
}
double hum1 = 0;
if (omsg.get_id() == 4)
{
hum1 = -0.0000028*avg*avg + 0.0405*avg-4;
hum1 = hum1*100;
int h1 = (int)hum1;
hum1 = h1/100.0;
System.out.println("Room Humidity = " + hum1 + "% From Node 2");
}
/*\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
/* need parallel interface code to send these temperature and humidty
values to relays( external hardware)
*/
*////////////////////////////////////////////////////////
data.update(omsg.get_id(), omsg.get_count(), omsg.get_readings());
/* Inform the GUI that new data showed up */
window.newData();
}
}
/* A potentially new version and interval has been received from the
mote */
void periodUpdate(int moteVersion, int moteInterval) {
if (moteVersion > version) {
/* It's new. Update our vision of the interval. */
version = moteVersion;
interval = moteInterval;
window.updateSamplePeriod();
}
else if (moteVersion < version) {
/* It's old. Update the mote's vision of the interval. */
sendInterval();
}
}
/* The user wants to set the interval to newPeriod. Refuse bogus values
and return false, or accept the change, broadcast it, and return
true */
synchronized boolean setInterval(int newPeriod) {
if (newPeriod < 1 || newPeriod > 65535) {
return false;
}
interval = newPeriod;
version++;
sendInterval();
return true;
}
/* Broadcast a version+interval message. */
void sendInterval() {
OscilloscopeMsg omsg = new OscilloscopeMsg();
omsg.set_version(version);
omsg.set_interval(interval);
try {
mote.send(MoteIF.TOS_BCAST_ADDR, omsg);
}
catch (IOException e) {
window.error("Cannot send message to mote");
}
}
/* User wants to clear all data. */
void clear() {
data = new Data(this);
}
public static void main(String[] args) {
Oscilloscope me = new Oscilloscope();
me.run();
}
}
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help