Hi Libelium-dev;
i am still having problems with the noise and dust sensor, see my code below, which is trying to sending data to the gateway...
but the values looks not right, like:
-ID:wasp003, -x:46,y:-51,z:1044, -temp:25, -dust:0.15,-noise:0, -bat: 89%
i tried to convert the noise to char[] , and the value was 0.00.
also, i noticed that your previous post, with a sample code, i tried that, it was not work, as it doesn't send out anything, while i move the "SensorCities.setAudioGain(50,5);" into the "setup(){}" function, then i get the values, but seems not really right..
also, i tried without XBee, just sending the data via USB connection, it was the similar issue, if i put the "SensorCities.setAudioGain(50,5);" in the loop() , i could not receive anything, but if i put it in the setup() , then got the value, but seems values are not right either...
so
please see the code belowQuote:
packetXBee* paq_sent;
int8_t state=0;
long previous=0;
char aux[200];
char* macHigh=" ";
char* macLow=" ";
int aux_1 = 0;
int aux_2 = 0;
float dust;
float noise;
float tem;
#define key_access "LIBELIUM"
//uint8_t direccion[8]={0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF};
void setup(){
//switch on the smart city sensor board
SensorCities.setBoardMode(SENS_ON);
SensorCities.setAudioGain(50,5);
// Store key access in EEPROM
for(int i=0;i<8;i++){
Utils.writeEEPROM(i+107,key_access[i]);
}
RTC.ON();
ACC.ON();
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();
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 802.15.4 library
xbee802.init(XBEE_802_15_4,FREQ2_4G,NORMAL);
// Powers XBee
xbee802.ON();
// Get the XBee MAC address
delay(500);
int counter = 0;
while(xbee802.getOwnMac()==1&&counter<4){
xbee802.getOwnMac();
counter++;
}
Utils.hex2str(xbee802.sourceMacHigh,macHigh,4);
Utils.hex2str(xbee802.sourceMacLow,macLow,4);
}
void loop(){
tem = RTC.getTemperature();
SensorCities.setSensorMode(SENS_ON, SENS_CITIES_DUST);
dust = SensorCities.readValue(SENS_CITIES_DUST);
char dt[10];
Utils.float2String(dust,dt,2);
SensorCities.setSensorMode(SENS_OFF, SENS_CITIES_DUST);
SensorCities.setSensorMode(SENS_ON, SENS_CITIES_AUDIO);
//SensorCities.setAudioGain(50,5);
delay(5000);
noise = SensorCities.readValue(SENS_CITIES_AUDIO);
//char ns[10];
//Utils.float2String(noise,ns,2);
SensorCities.setSensorMode(SENS_OFF,SENS_CITIES_AUDIO);
sprintf(aux,"-ID:%s, -x:%d,y:%d,z:%d, -temp:%d, -dust:%s,-noise:%d, -bat: %d%c%c%c","wasp003",ACC.getX(),ACC.getY(),ACC.getZ(),(int)tem,dt,(int)noise,PWR.getBatteryLevel(),'%','\r','\n');
paq_sent=(packetXBee*) calloc(1,sizeof(packetXBee));
paq_sent->mode=UNICAST;
paq_sent->MY_known=0;
paq_sent->packetID=0x52;
paq_sent->opt=0;
xbee802.hops=0;
xbee802.setOriginParams(paq_sent,MAC_TYPE);
xbee802.setDestinationParams(paq_sent, "0013A200406938EA", aux, MAC_TYPE, DATA_ABSOLUTE);
xbee802.sendXBee(paq_sent);
free(paq_sent);
paq_sent = NULL;
delay(10000);
}