Tuesday, 22 October 2013

TinyOS - Data Reading from Sensor on the MOTE SH11


Reading SH11C Sensor Data [Temperature and Humidity] from MDA300CA DAB Sensor

Sensor Programs

/*
Author : Bipin. Kunjumon

*/

SenseC.nc

#include "Timer.h"
#include "Wireless.h"
module SenseC
{
uses {
interface Boot;
interface Leds;
interface Timer<TMilli>;
interface Read<uint16_t> as TempRead;
interface Read<uint16_t> as HumRead;
interface AMSend;
interface SplitControl as AMControl;
interface Packet;
}
}
implementation
{
message_t packet;
bool locked;
wireless_msg_t rcm;
uint16_t temp;
uint16_t hum;
uint16_t counter=0;
// sampling frequency in binary milliseconds
#define SAMPLING_FREQUENCY 100
event void Boot.booted()
{
call AMControl.start();
call Timer.startPeriodic(5000);
}

event void AMControl.startDone(error_t err)
{
if (err == SUCCESS)
{
call Timer.startPeriodic(250);
}
else
{
call AMControl.start();
}
}
event void AMControl.stopDone(error_t err)
{
// nstall micaz mib510,/dev/ttyUSB0do nothing
}


event void Timer.fired()
{
call TempRead.read();
call HumRead.read();
counter++;
if (locked) {
return;
}
else {
wireless_msg_t* rcm = (wireless_msg_t*)call Packet.getPayload(&packet, sizeof(wireless_msg_t));
if (rcm == NULL) {
return;
}

rcm->counter = counter;
rcm->HumData=hum;
rcm->TempData=temp;
if (call AMSend.send(AM_BROADCAST_ADDR, &packet, sizeof(wireless_msg_t)) == SUCCESS) {
locked = TRUE;
}
}

}

/*
Temperature Sensor Reading … SensirionSht11C
*/

event void TempRead.readDone(error_t result, uint16_t data)
{
if (result == SUCCESS){
if (data & 0x0004)
call Leds.led2On();
else
call Leds.led2Off();
if (data & 0x0002)
call Leds.led1On();
else
call Leds.led1Off();
if (data & 0x0001)
call Leds.led0On();
else
call Leds.led0Off();
temp=data;
}
else
temp=0xffff;
}


/*
Humidity Sensor Reading … SensirionSht11C
*/

event void HumRead.readDone(error_t result, uint16_t data)
{
if (result == SUCCESS){
if (data & 0x0004)
call Leds.led2On();
else
call Leds.led2Off();
if (data & 0x0002)
call Leds.led1On();
else
call Leds.led1Off();
if (data & 0x0001)
call Leds.led0On();
else
call Leds.led0Off();

hum=data;

}
else
hum=0xffff;
}

event void AMSend.sendDone(message_t* bufPtr, error_t error) {
if (&packet == bufPtr) {
locked = FALSE;
}
}

}





*********************************************************************************


SenseAppC.nc
configuration SenseAppC
{

}
implementation
{
components SenseC, MainC, LedsC, new TimerMilliC(), new SensirionSht11C() as TempSensor;
components new SensirionSht11C() as HumSensor;
SenseC.Boot -> MainC;
SenseC.Leds -> LedsC;
SenseC.Timer -> TimerMilliC;
SenseC.TempRead -> TempSensor.Temperature;
SenseC.HumRead -> HumSensor.Humidity;
components new AMSenderC(AM_WIRELESS_MSG);
SenseC.AMSend->AMSenderC;
SenseC.Packet->AMSenderC;
components ActiveMessageC;
SenseC.AMControl->ActiveMessageC;
}


Header file
Wireless.h



************************************************************************************





Makefile

COMPONENT=SenseAppC
SENSORBOARD=mda300
include $(MAKERULES)


**********************************************************************************


Compile

make install micaz mib510,devicename

**********************************************************************************
We can receive this data by setup a Base station Receiver wireless mote device and read the data from its serial port

Serial Data Reading

java net.tinyos.tools.Listen -comm serial@devicename:platform



No comments:

Post a Comment