Post a new topicPost a reply Page 1 of 1   [ 8 posts ]
Author Message
 Post subject: Wireless / sensor problem
PostPosted: Tue Jan 17, 2012 10:25 am 

Joined: Mon Jan 16, 2012 9:07 pm
Posts: 8
Hi,
i'm working with 5 Waspmote boards, i want to capture Sensirion's temperature and humidity values from 4 boards, and then send the messages through wireless Xbee module to a unic node (the other board).
This node need also to capture the temperature and humidity values too, and then save the messages in different *.txt files in a micro SD plugged to this.
Here are the codes both for the 4 slaves and for the master:


SLAVE (the same code for 4 boards)
packetXBee* paq_sent;
int8_t state=0;
long previous=0;
char* macHigh=" ";
char* macLow=" ";
int aux_1 = 0;
int aux_2 = 0;
uint8_t PANID[2]={0x12,0x34};
float value_temperature=0;
float value_humidity=0;
char svalue_temperature[100];
char svalue_humidity[100];
char aux[200];
char* MAC_sender =" ";

void setup()
{

RTC.ON();


SensorAgr.setBoardMode(SENS_ON);

//Set tinme
RTC.setTime("11:09:01:05:12:00:00");

XBee.setMode(XBEE_ON);
XBee.begin(38400);
delay(1000);
XBee.print("+++");
delay(2000);
XBee.println("ATBD5,AP2,WR,CN");
delay(150);

XBee.setMode(XBEE_OFF);
XBee.close();

// Inits the XBee 802.15.4 library
xbee.init(XBEE_802_15_4,FREQ2_4G,NORMAL);

// Powers XBee
xbee.ON();

// Get the XBee MAC address

delay(500);

int counter = 0;
while(xbee.getOwnMac()==1&&counter<4){
xbee.getOwnMac();
counter++;
}

// Get the XBee firmware version

xbee.getSoftVersion();

Utils.hex2str(xbee.sourceMacHigh,macHigh,4);

Utils.hex2str(xbee.sourceMacLow,macLow,4);

if (xbee.softVersion[0]==0x10){
if (xbee.softVersion[1]==0x02){
xbee.init(XBEE_900,FREQ900M,NORMAL);
}
if (xbee.softVersion[1]==0x20){
xbee.init(XBEE_XSC,FREQ900M,PRO);
}
if (xbee.softVersion[1]==0x25||xbee.softVersion[1]==0x27){
xbee.init(XBEE_868,FREQ868M,PRO);
}

if (xbee.softVersion[1]>=0x81){
xbee.init(XBEE_802_15_4,FREQ2_4G,NORMAL);
}
}
else
{
xbee.init(ZIGBEE,FREQ2_4G,NORMAL);
}
Utils.setLED(LED0, LED_ON);
Utils.setLED(LED1, LED_ON);
delay(5000);
Utils.setLED(LED0, LED_OFF);
Utils.setLED(LED1, LED_OFF);
for (int i=0;i<24;i++){
Utils.blinkLEDs(125);
}
}


void loop()
{

RTC.ON();
PWR.deepSleep("00:00:00:30",RTC_OFFSET,RTC_ALM1_MODE4,ALL_OFF);

if( intFlag & RTC_INT )
{
RTC.ON();

xbee.ON();

SensorAgr.setBoardMode(SENS_ON);

SensorAgr.setSensorMode(SENS_ON, SENS_AGR_SENSIRION);
delay(10000);
value_temperature=SensorAgr.readValue(SENS_AGR_SENSIRION,SENSIRION_TEMP);
delay(100);
value_humidity= SensorAgr.readValue(SENS_AGR_SENSIRION,SENSIRION_HUM);



Utils.float2String(value_temperature,svalue_temperature,2);
Utils.float2String(value_humidity,svalue_humidity,2);

sprintf(aux,"-mac:%s%s -time:%s -bat: %d -AgrTemp: %s -AgrHum: %s%c%c%c",macHigh,macLow,RTC.getTime(),PWR.getBatteryLevel(),svalue_temperature,svalue_humidity,'%','\r','\n');

sprintf(MAC_sender,"%s%s%c",macHigh,macLow,'/n');

paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
paq_sent->mode=BROADCAST;
paq_sent->MY_known=0;
paq_sent->packetID=0x52;
paq_sent->opt=0;
xbee.hops=0;
xbee.setOriginParams(paq_sent,MAC_sender,MAC_TYPE);// mac address sensore emittente
xbee.setDestinationParams(paq_sent,"0013A200406916C2", aux, MAC_TYPE, DATA_ABSOLUTE); // mac address sensore ricevente
xbee.sendXBee(paq_sent);

free(paq_sent);
paq_sent = NULL;

xbee.OFF();

delay(100);
}

}


MASTER
packetXBee* paq_sent;
long previous=0 ,time;
char buffer[200];
int n=0;
int packet = 0;
int i=1;
uint8_t rssi;
int g=0;
uint8_t PANID[2]={0x12,0x34};
const char* filename="Folder_1.txt";
const char* filename2="Folder_2.txt";
const char* filename3="Folder_3.txt";
const char* filename4="Folder_4.txt";
const char* filename5="Folder_5.txt";
char* macHigh2="0013A200";
char* macLow2= "406916C2";
float value_temperature2=0;
float value_humidity2=0;
char svalue_temperature2[100];
char svalue_humidity2[100];
char out_m[200];

void setup()
{
// Inits the XBee 802.15.4 library
xbee802.init(XBEE_802_15_4,FREQ2_4G,NORMAL);
// Powers XBee
XBee.setMode(XBEE_ON);
XBee.begin(9600);
delay(1000);
XBee.print("+++");
delay(2000);
XBee.println("ATBD5,AP2,WR,CN");
delay(150);
XBee.setMode(XBEE_OFF);
XBee.close();
delay(100);
SD.ON();
// resets the SD card memory
if (SD.isFile(filename))
{SD.del(filename);}
if (SD.isFile(filename2))
{SD.del(filename2);}
if (SD.isFile(filename3))
{SD.del(filename3);}
if (SD.isFile(filename4))
{SD.del(filename4);}
if (SD.isFile(filename5))
{SD.del(filename5);}
//Setting RTC
USB.println("Init RTC");
RTC.ON();
//Setting time where dow start from 1 (sunday)
RTC.setTime("11:09:01:05:12:00:00");

}

void wireless()
{
previous=millis();
while( (millis()-previous) < 20000 )
{
if( XBee.available() )
{
xbee802.treatData();
if( !xbee802.error_RX )
{
// Writing the parameters of the packet received
while(xbee802.pos>0)
{
if(xbee802.packet_finished[xbee802.pos-1]->data[20]=='8' || xbee802.packet_finished[xbee802.pos-1]->data[21]=='8')
SD.appendln(filename,xbee802.packet_finished[xbee802.pos-1]->data);
else if(xbee802.packet_finished[xbee802.pos-1]->data[20]=='A' || xbee802.packet_finished[xbee802.pos-1]->data[21]=='A')
SD.appendln(filename2,xbee802.packet_finished[xbee802.pos-1]->data);
else if(xbee802.packet_finished[xbee802.pos-1]->data[20]=='C' || xbee802.packet_finished[xbee802.pos-1]->data[21]=='C')
SD.appendln(filename3,xbee802.packet_finished[xbee802.pos-1]->data);
else SD.appendln(filename4,xbee802.packet_finished[xbee802.pos-1]->data);

free(xbee802.packet_finished[xbee802.pos-1]);
xbee802.packet_finished[xbee802.pos-1]=NULL;
xbee802.pos--;
}
if( millis()-previous < 0 ) previous=millis();
}
}
}
}

void sensor()
{
delay(3000);
value_temperature2=SensorAgr.readValue(SENS_AGR_SENSIRION,SENSIRION_TEMP);
delay(100);
value_humidity2= SensorAgr.readValue(SENS_AGR_SENSIRION,SENSIRION_HUM);
Utils.float2String(value_temperature2,svalue_temperature2,2);
Utils.float2String(value_humidity2,svalue_humidity2,2);
sprintf(out_m,"-mac:%s%s -time:%s -bat: %d -AgrTemp: %s -AgrHum: %s%c%c%c",macHigh2,macLow2,RTC.getTime(),PWR.getBatteryLevel(),svalue_temperature2,svalue_humidity2,'%','\r','\n');
SD.appendln(filename5,out_m);
}


void loop()
{
SD.ON();
SD.create(filename);
SD.create(filename2);
SD.create(filename3);
SD.create(filename4);
SD.create(filename5);
Utils.setLED(LED0, LED_ON);
Utils.setLED(LED1, LED_ON);
xbee.ON();
delay(3000);
wireless();
//USB.flush();
delay(2000);
xbee.OFF();
SensorAgr.setBoardMode(SENS_ON);
Utils.setLED(LED1, LED_OFF);
delay(1000);
sensor();
delay(1000);
SensorAgr.setBoardMode(SENS_OFF);
delay(1000);
SD.OFF();
Utils.setLED(LED0, LED_OFF);
delay(2000);
}

The problems i have are:
-if i use both wireless and sensor functions the only part of the code that runs correctly is the sensor one (only a file *.txt is correctly created and written);
-if i use only one of the two functions all works fine, i capture the values and save correctly in different *.txt files.

What i have to add or modify in the master code?
Regards,
FP


Top
 Profile  
 
 Post subject: Re: Wireless / sensor problem
PostPosted: Tue Jan 17, 2012 11:43 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
Dear Atomos,

Due to your design uses some of Waspmote module, a good desing tip is to test each module separately.

We mean, first test you obtain good values from sensors. Once You have right values try to send it through Xbee and deal with the networking issues. Then, when these parts works, try to save into SD files.

It would be easier to you to find where problems are coming from.

Try also using USB.print(variable); for debugging purposes.

Besides that, test the free Ram memory of micro controller with freeMemory() function.

Looking briefly into your code, place RTC.ON() just before setBoardMode(SENS_ON)

Please try to debug a bit more your code in order to make easy for us understand your code and try to help you.

Please let us know your comments. We will be glad to try solve your issues.

Kind regards.


Top
 Profile  
 
 Post subject: Re: Wireless / sensor problem
PostPosted: Tue Jan 17, 2012 12:00 pm 

Joined: Mon Jan 16, 2012 9:07 pm
Posts: 8
Thanks for the reply.
I tried using the println on various parts of the Master code, and the problem is in the wireless function xbee802.treatData();.
If i print the error variable that is inside this function, when the Xbee recieves the data it appears error 2, it means that the command has not been executed.
An interesting thing is that, however, the rssi led turned on while the data was sent.


Top
 Profile  
 
 Post subject: Re: Wireless / sensor problem
PostPosted: Tue Jan 17, 2012 1:12 pm 

Joined: Mon Jan 16, 2012 9:07 pm
Posts: 8
I also creted a Master that uses only one slave, here is the code:

MASTER
packetXBee* paq_sent;
long previous=0 ,time;
char buffer[100];
int8_t error =2;
int n=0;
int packet = 0;
int i=1;
uint8_t rssi;
int g=0;
uint8_t PANID[2]={0x12,0x34};
const char* nome = "Slave.txt";
const char* nome2 ="Master.txt";
char* macHigh2="0013A200";
char* macLow2= "406916C2";
float value_temperature2=0;
float value_humidity2=0;
char svalue_temperature2[100];
char svalue_humidity2[100];
char out_m[200];
#define Message1 "1- XBee ON"
#define Message2 "2- Txt files created"
#define Message3 "3- Board Power ON"
#define Message4 "4- Sensor data stored"
#define Message5 "5- Board,I2C,SD,RTC OFF - XBEE ON"
#define Message6 "6- Wireless data stored"
#define Message7 "7- Wireless terminated"
#define Message8 "8- Loop Restart"
#define Err1 "ERROR wireless"
#define Err2 "NOT available"

void setup()
{
// Inits the XBee 802.15.4 library
xbee802.init(XBEE_802_15_4,FREQ2_4G,NORMAL);
// Powers XBee
XBee.setMode(XBEE_ON);
XBee.begin(38400);
delay(1000);
XBee.print("+++");
delay(2000);
XBee.println("ATBD5,AP2,WR,CN");
delay(150);
XBee.setMode(XBEE_OFF);
XBee.close();
delay(100);
SD.begin();
SD.setMode(SD_ON);
// resets the SD card memory
if (SD.isFile(nome))
SD.del(nome);
if (SD.isFile(nome2))
SD.del(nome2);
SD.setMode(SD_OFF);
SD.close();
//Setting RTC
USB.begin();
USB.println("Init RTC");
RTC.ON();
//Setting time where dow start from 1 (sunday)
RTC.setTime("11:09:01:05:12:00:00");
RTC.OFF();
//xbee.ON();
}


void loop()
{
SD.ON();
RTC.ON();
USB.println(Message1);
SD.create(nome2);
USB.println(Message2);
SensorAgr.setBoardMode(SENS_ON);
SensorAgr.setSensorMode(SENS_AGR_SENSIRION,SENS_ON);
USB.println(Message3);
delay(10000);
value_temperature2=SensorAgr.readValue(SENS_AGR_SENSIRION,SENSIRION_TEMP);
delay(100);
value_humidity2= SensorAgr.readValue(SENS_AGR_SENSIRION,SENSIRION_HUM);
Utils.float2String(value_temperature2,svalue_temperature2,2);
Utils.float2String(value_humidity2,svalue_humidity2,2);
sprintf(out_m,"-mac:%s%s -time:%s -bat: %d -AgrTemp: %s -AgrHum: %s%c%c%c",macHigh2,macLow2,RTC.getTime(),PWR.getBatteryLevel(),svalue_temperature2,svalue_humidity2,'%','\r','\n');
SD.appendln(nome2,out_m);
USB.println(out_m);
USB.println(Message4);
SensorAgr.setBoardMode(SENS_OFF);
Utils.freeMemory;
Utils.clearBuffer();
USB.println("Memory freed");
Utils.setLED(LED0, LED_ON);
USB.close();
SD.OFF();
delay(1000);
SD.ON();
xbee.ON();
SD.create(nome);
XBee.println(Message5);
delay(4000);
previous=millis();
while( (millis()-previous) < 20000 )
{
if( XBee.available() )
{
xbee802.treatData();
XBee.println(error);
if( !xbee802.error_RX )
{
// Writing the parameters of the packet received
while(xbee802.pos>0)
{
SD.appendln(nome,xbee802.packet_finished[xbee802.pos-1]->data);
XBee.println(xbee802.packet_finished[xbee802.pos-1]->data);
delay(100);
XBee.println(Message6);

free(xbee802.packet_finished[xbee802.pos-1]);
xbee802.packet_finished[xbee802.pos-1]=NULL;
xbee802.pos--;
}
previous=millis();
}
else XBee.println(Err1);
}
else {XBee.println(Err2);
delay(1000);}
}
XBee.println(Message7);
XBee.println(Message8);
Utils.setLED(LED0, LED_OFF);
XBee.setMode(XBEE_HIBERNATE);
SD.OFF();
}

In this program, I introduced the println function in various part of the program.
The problem appears in the treatData function, and it's shown in this stamp:

[img]C:\Users\Administrator\Desktop\Cattura[/img]

Are there some variables I need to free before that point?


Top
 Profile  
 
 Post subject: Re: Wireless / sensor problem
PostPosted: Tue Jan 17, 2012 1:24 pm 

Joined: Mon Jan 16, 2012 9:07 pm
Posts: 8
Sorry, the image posted before won't be seen, here is the stamp of the serial monitor:

+++ATBD5,AP2,WR,CN
Init RTC
1- XBee ON
2- Txt files created
3- Board Power ON
-mac:0013A200406916C2 -time:Thursday, 11/09/01 ........
4- Sensor data stored
Memory freed
5- Board,I2C,SD,RTC OFF - XBEE ON
2
ERROR wireless
NOT available
NOT available
NOT available
NOT available
NOT available
NOT available
NOT available
NOT available
NOT available
2
ERROR wireless
NOT available
NOT available
NOT available
NOT available
NOT available
NOT available
NOT available
NOT available
NOT available
7- Wireless terminated
8- Loop restart

I don't know why the first "ERROR wireless" appears, the second one is related to the moment where the data is sent through Xbee module (and the rssi led are turned ON)


Top
 Profile  
 
 Post subject: Re: Wireless / sensor problem
PostPosted: Fri Jan 20, 2012 3:54 pm 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
Dear Atomos9317,

Sorry for delay.

Let us ask you some questions:
Did you try example codes for 802.15.4?
Are you able to make a Waspmote to Waspmote communication?
To carry out this, just upload...

- "WaspXBee802_2_sending_receiving" to --------->Waspmote_A;
- "WaspXBee802_2_sending_receivingB" to---------> Waspmote_B;

and see what happens.

Lets try with the example code first, and if it works we will go on your code.

Kind regards.


Top
 Profile  
 
 Post subject: Re: Wireless / sensor problem
PostPosted: Fri Jan 20, 2012 4:33 pm 

Joined: Mon Jan 16, 2012 9:07 pm
Posts: 8
I solved.
The program doesn't have any problem, i needed to update the board from wasp_019 to wasp_021.
wasp_022 doesn't work, there are compiling problems.


Top
 Profile  
 
 Post subject: Re: Wireless / sensor problem
PostPosted: Mon Jan 23, 2012 9:31 am 

Joined: Mon Sep 28, 2009 1:06 pm
Posts: 7440
Glad to hear that.

We recommend always use last version of API, with the exception op API 22 which is being studied due to some problems under windows.

Any other comments please tell us.

Regards


Top
 Profile  
 
Display posts from previous:  Sort by  
Post a new topicPost a reply Page 1 of 1   [ 8 posts ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:


Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Libelium theme based on 610nm Style by Daniel St. Jules of http://www.gamexe.net


© Libelium Comunicaciones Distribuidas S.L. | Terms of use