I am still making changes to adapt (I am using only 6 of the available 9 sensors).
My current code is:
Quote:
long previous=0;
packetXBee* paq_sent;
int8_t state=0;
char A[10]; // Temperature
char B[10]; // Barometric Pressure
char C[10]; // Carbon Monoxide
char D[10]; // Carbon Dioxide
char E[10]; // Oxygen
char F[10]; // Ozone
char G[10]; // Air Contaminants Gases I
char H[10]; // Air Contaminants Gases II
char I[10]; // Waspmote Battery
char aux[200];
char* macLow=" ";
// Resistor (1 - 100 KOhms) and Gain (1 - 101)
#define CO_GAIN 1
#define CO_RESISTOR 50
#define CO2_GAIN 1
#define O2_GAIN 100
#define O3_GAIN 1
#define O3_RESISTOR 10
#define ACS1_GAIN 1
#define ACS1_RESISTOR 10
#define ACS2_GAIN 1
#define ACS2_RESISTOR 10
#define key_access "WaspmoteKey"
float value_T=0.0;
float value_Air=0.0;
float value_CO=0.0;
float value_CO2=0.0;
float value_O2=0.0;
float value_O3=0.0;
float value_ACS1=0.0;
float value_ACS2=0.0;
float value=0;
uint8_t batt;
uint8_t counter=0;
void setup()
{
// Store key access in EEPROM
for(int i=0;i<8;i++){
Utils.writeEEPROM(i+107,key_access[i]);
}
XBee.setMode(XBEE_ON);
XBee.begin(9600);
delay(1000);
XBee.print("+++");
delay(2000);
XBee.println("ATBD5,AP2,WR,CN");
delay(150);
xbeeZB.writeValues();
delay(500);
XBee.setMode(XBEE_OFF);
XBee.close();
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);
}
// Inits the XBee XSC library
xbeeZB.init(ZIGBEE,FREQ2_4G,NORMAL);
// Powers XBee
xbeeZB.ON();
delay(100000);
// Get the XBee MAC address
int counter = 0;
while(xbeeZB.getOwnMac()==1&&counter<4){
xbeeZB.getOwnMac();
counter++;
}
Utils.hex2str(xbeeZB.sourceMacLow,macLow,4);
}
void loop()
{
SensorGas.setBoardMode(SENS_ON);
delay(50);
RTC.ON();
delay(500);
XBee.setMode(XBEE_OFF);
delay(500);
PWR.deepSleep("00:00:05:00",RTC_OFFSET,RTC_ALM1_MODE2,ALL_OFF);
if( intFlag & RTC_INT )
{
Utils.blinkLEDs(1000);
Utils.blinkLEDs(1000);
Utils.blinkLEDs(1000);
intFlag &= ~(RTC_INT);
}
getData();
sendData();
}
// gets values from sensors
void getData()
{
SensorGas.setBoardMode(SENS_ON);
RTC.ON();
delay(100);
value=0;
for(int g=0;g<5;g++){
value_T = SensorGas.readValue(SENS_TEMPERATURE);
value_T = (value_T - 0.5) * 100;
value = value_T + value;
delay(100);
}
value = value/5;
Utils.float2String(value,A,1);
// Barometric pressure (Atmospheric Pressure Sensor; hPa – MPXAZ6115A)
SensorGas.setSensorMode(SENS_ON, SENS_PRESSURE);
delay(100);
value_Air = SensorGas.readValue(SENS_PRESSURE);
value_Air = (value_Air - 1.28) * 1000;
Utils.float2String(value_Air,B,1);
SensorGas.setSensorMode(SENS_OFF, SENS_PRESSURE);
// CO (Carbon Monoxide Sensor; ppm – Socket 3B; TGS2442); Rs=R0 at 100 ppm, 25°, 40%RH
SensorGas.configureSensor(SENS_SOCKET3B, CO_GAIN, CO_RESISTOR);
delay(1000);
value_CO = 100*pow ((((5*10/ SensorGas.readValue(SENS_SOCKET3B))-10)/1101),-0.7925);
Utils.float2String(value_CO,C,1);
// CO2 (Carbon Dioxide Sensor; ppm - Socket 1A; TGS4161); y = p1*x + p2 / (value_CO2 + 3.6973) / 0.011992??
SensorGas.configureSensor(SENS_CO2, CO2_GAIN);
SensorGas.setSensorMode(SENS_ON, SENS_CO2);
delay(30000);
value_CO2 = 350* pow (10, SensorGas.readValue(SENS_CO2));
Utils.float2String(value_CO2,D,1);
SensorGas.setSensorMode(SENS_OFF, SENS_CO2);
// O2 (%; Socket 1B; Sensor – SK-25)
SensorGas.configureSensor(SENS_O2, O2_GAIN);
delay(1000);
value_O2 = ((SensorGas.readValue(SENS_O2)*10)-0.5)/0.3;
Utils.float2String(value_O2,E,1);
// Waspmote Battery
batt = PWR.getBatteryLevel();
Utils.long2array(batt,I);
}
// sends a message
void sendData()
{
sprintf(aux,",%s,%s,%s,%s,%s,%s,%s,",macLow,A,B,C,D,E,I);
xbeeZB.ON();
delay(10000);
do
{
XBee.print("waiting for association ");
XBee.println(xbeeZB.associationIndication,HEX);
delay(1000);
xbeeZB.getAssociationIndication();
}
while(xbeeZB.associationIndication!=0);
paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
paq_sent->mode=UNICAST;
paq_sent->MY_known=0;
paq_sent->packetID=0x52;
paq_sent->opt=0;
xbeeZB.hops=0;
xbeeZB.setOriginParams(paq_sent, "0013A20040714C00", MAC_TYPE);
xbeeZB.setDestinationParams(paq_sent, "0013A200406B094A", aux, MAC_TYPE, DATA_ABSOLUTE);
xbeeZB.sendXBee(paq_sent);
while( counter<1 ){
state=xbeeZB.sendXBee(paq_sent);
counter++;
}
counter=0;
if(!state)
{
XBee.println("OK");
}
free(paq_sent);
paq_sent = NULL;
delay(1000);
}
Since I have introduced the do/while loop with
Code:
xbeeZB.getAssociationIndication();
connection between the end device and the coordinator always works.
The trouble I have is that when using wirless datalogging stops after three data transfers even if I run the mote the whole night:
Quote:
38,~ • }3¢ @qL ÜóBÜó }3¢ @qL Á
38,~ • }3¢ @qL DEBDE }3¢ @qL Áš
72,~ B }3¢ @qL DEAR# }3¢ @qL ,00000000,22.5,1032.9,100.2,355.2,14.6,98,Î
72,~ B }3¢ @qL DEAR# }3¢ @qL ,00000000,22.5,1032.9,100.2,355.2,14.6,98,Î
38,~ • }3¢ @qL ˆÁBˆÁ }3¢ @qL Á
71,~ A }3¢ @qL ˆÁAR# }3¢ @qL ,00000000,23.6,1032.9,94.5,365.9,14.5,98,&
71,~ A }3¢ @qL ˆÁAR# }3¢ @qL ,00000000,23.6,1032.9,94.5,365.9,14.5,98,&
38,~ • }3¢ @qL Ô7BÔ7 }3¢ @qL Á–
142,~ A }3¢ @qL Ô7AR# }3¢ @qL ,00000000,24.0,1032.9,94.5,357.8,14.5,98,i~ A }3¢ @qL Ô7AR# }3¢ @qL ,00000000,24.0,1032.9,94.5,357.8,14.5,98,i
38,~ • }3¢ @qL q4Bq4 }3¢ @qL Áb
71,~ A }3¢ @qL q4AR# }3¢ @qL ,00000000,23.5,1029.6,88.6,357.8,14.6,98,Ã
71,~ A }3¢ @qL q4AR# }3¢ @qL ,00000000,23.5,1029.6,88.6,357.8,14.6,98,Ã
If I run the same code connecting to the USB I do get a continuing data transfer between the end device and the coordinator.