NLS not working

Questions about the Waspmote v15 and its modules
Post Reply
dario_espinoza
Posts: 9
Joined: Mon Jan 21, 2019 4:23 pm
Company: UDA

NLS not working

Post by dario_espinoza » Thu Oct 24, 2019 3:09 pm

Hi, we are having trouble with one of our NLSs.

Performing comparative tests between the NLS and a soundmeter it started to print wrong values for the NLS.

I will explain what the output means. We measure noise in slow mode, for a given time expressed in minutes and after that we read the values from the BME and finally we send the data using 4G.

Code: Select all

Nodo: SCP14 
*****************************
APN: internet.movistar.com.ec
LOGIN: movistar
PASSWORD: movistar
*****************************
Now: Wed, 19/10/23, 10:18:40 
Now plus 1 minutes: 19/10/23 10:19:40
>- Measuring noise (SLOW), 1 minutes... 
Numero de muestras: 58 
Promedio log ruido: 54.13 dB
Promedio ruido: -0.00 dB
>- Reading BME...
Temperatura: 18.50 C
Humedad: 57.26 %
Presion: 75624.04 Pa
The weird part of this output is that "Promedio log ruido" and "Promedio ruido" came from the same input values. The first is a logarithmic average and arithmetic average, respectively. This test was performed on a quiet and controlled environment.

So, we turned off the equipment, disconnected the NLS and let it rest for some minutes. After that, with a modification in the source code to show all the noise inputs, we started the test again and the output was this:

Code: Select all

Now: Wed, 19/10/23, 10:35:18 
Now plus 1 minutes: 19/10/23 10:36:18
>- Measuring noise (SLOW), 1 minutes... 
[CITIES PRO] Communication error. No response from the audio sensor (SLOW)
[CITIES PRO] Communication error. No response from the audio sensor (SLOW)
[CITIES PRO] Communication error. No response from the audio sensor (SLOW)
[CITIES PRO] Communication error. No response from the audio sensor (SLOW)
[CITIES PRO] Communication error. No response from the audio sensor (SLOW)
Muestra #1 78.35 dbA 
Muestra #2 -12.39 dbA 
Muestra #3 -0.00 dbA 
Muestra #4 -0.00 dbA 
Muestra #5 -0.00 dbA 
Muestra #6 -0.00 dbA 
Muestra #7 -0.00 dbA 
Muestra #8 -0.00 dbA 
Muestra #9 -0.00 dbA 
Muestra #10 -0.00 dbA 
Muestra #11 -0.00 dbA 
Muestra #12 -0.00 dbA 
Muestra #13 -0.00 dbA 
Muestra #14 -0.00 dbA 
Muestra #15 -0.00 dbA 
Muestra #16 -0.00 dbA 
Muestra #17 -0.00 dbA 
Muestra #18 -0.00 dbA 
Muestra #19 -0.00 dbA 
Muestra #20 -0.00 dbA 
Muestra #21 -0.00 dbA 
Muestra #22 -0.00 dbA 
Muestra #23 -0.00 dbA 
Muestra #24 -0.00 dbA 
Muestra #25 -0.00 dbA 
Muestra #26 -0.00 dbA 
Muestra #27 -0.00 dbA 
Muestra #28 -0.00 dbA 
Muestra #29 -0.00 dbA 
Muestra #30 -0.00 dbA 
Muestra #31 -0.00 dbA 
Muestra #32 -0.00 dbA 
Numero de muestras: 32 
Promedio log ruido: 63.30 dB
Promedio ruido: -0.00 dB
>- Reading BME...
Temperatura: 19.03 C
Humedad: 55.52 %
Presion: 75602.17 Pa
Now, we don't know what is happening with the NLS

Your help is appreciated

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: NLS not working

Post by libelium-dev » Fri Oct 25, 2019 8:47 am

Hi,

Could you please share the code used with us? We are going to check if it is correct.

What API version did you use to upload the code?

Regards

dario_espinoza
Posts: 9
Joined: Mon Jan 21, 2019 4:23 pm
Company: UDA

Re: NLS not working

Post by dario_espinoza » Fri Oct 25, 2019 3:22 pm

Hi again.

Shure, here:

Code: Select all

/*  
 * SCPxx - Octubre 2019
 * Codigo para realizar mediciones de ruido durante un tiempo especificado en minutos. Realizar
 * promedio aritmetrico y logaritmico con las muestras disponibles. Lectura de temperatura,
 * humedad y presion del sensor BME
 * 
 *  Version:           1.0
 *  Implementation:    Dario Espinoza S.
 */


#include <WaspSensorCities_PRO.h>
#include <WaspFrame.h>
#include <Wasp4G.h>
#include <math.h>

/* Instancia de sensor BME temp, hum, pres
* Colocar sonda 9370-P en el Socket-C de P&S
*/
bmeCitiesSensor  bme(SOCKET_C);
/* Variables para almacenar temp, hum, pres*/
float temperature;
float humidity;
float pressure;
float leqdBa;

/* Variables para tiempo*/
unsigned long  epochNow;
unsigned long  epochMnt;
/* Tiempo en minutos para mediciones de ruido*/
int mntAvg = 1;

/* Banderas para controlar procesamiento
* readBME: bandera para leer los datos BME (temp, hum, pres) y enviar los datos junto con noise
* doNoiseAvg: bandera para tomar muestras mientras se cumpla el tiempo de medicion
* checkTime: bandera para establecer el tiempo de medicion para tomar muestras de ruido
*/
boolean checkTime = true;
boolean doNoiseAvg = false;
boolean readBME = false;

/* Variables para controlar envio usando 4G
* sendAtt: numero de intentos para realizar envios de informacion
* waitAtt: tiempo en segundos para esperar entre intentos de reenvios
*/
uint16_t sendAtt = 5;
uint16_t waitAtt = 10;

/* Variables para promedio de muestras ruido*/
float sumdBlog = 0;
float sumdB = 0;
int cntdB = 0;

/* Identificador de nodo - EDITAR PARA CADA NODO */
// Waspmote identifier
char node_ID[] = "SCP14";

// Mobile operator paramenters
char apn[] = "internet.movistar.com.ec";
char login[] = "movistar";
char password[] = "movistar";
char pin[]= "xxxx";

// Debug flag, set to 1 if you want to see the complete process
#define debug_flag 0

// Server settings
char host[] = "xxx.xxx.xxx.xxx";
uint16_t port = 80;


/* First configuration of the unit, it is only executed once
* Parameters: void
* Return: void
*/
void setup(){
  USB.ON(); 
  USB.println("************************************************");
  USB.println("*       Universidad del Azuay - IERSE          *");
  USB.println("* Medicion de Ruido y Variables Meteorologicas *");
  USB.println("************************************************");
  USB.println("Promedio logaritmico de ruido durante x minutos");
  USB.println("Lectura de BME temp, hum y pres");
  USB.println("Envio de datos via 4G");
  USB.println("************************************************");
  
  /*Configure the noise sensor for UART communication*/
  noise.configure();

  /*Powers RTC up, init I2C bus and read initial values*/
  RTC.ON();

  //0.1 Sets operator paramenters
  _4G.set_APN(apn, login, password);

  //0.2 Show APN seetings
  _4G.show_APN();
  
  /*Setting time [yy:mm:dd:dow:hh:mm:ss]
  * Unica vez para establecer hora en RTC
  */
  //RTC.setTime("19:10:08:03:13:04:45");
}

/* Main loop
* Parameters: void
* Return: void
*/
void loop(){
  
  
  /*Importante para que transcurra el tiempo*/
  RTC.getTime();

  epochNow = RTC.getEpochTime((int)RTC.year, (int)RTC.month, (int)RTC.date, (int)RTC.hour, (int)RTC.minute, (int)RTC.second);

  /* Bandera para realizar el calculo desde NOW a mntAVG */
  if(checkTime){
    //USB.printf("Epoch Time from now: %lu", epochNow);
    USB.printf("Now: %s \n", RTC.getTime());
    epochMnt = addMinutesToNow(epochNow, mntAvg);

    /*Cambiar estado de banderas*/
    checkTime = false;
    doNoiseAvg = true;
    readBME =  false;

    USB.printf(">- Measuring noise (SLOW), %d minutes... \n", mntAvg);
    /*Configure the noise sensor for UART communication*/
    noise.configure();
    delay(1000);
  }

  /* Calcular Noise Logaritmo*/
  if(doNoiseAvg){

    /* Medir ruido siempre que el tiempo actual (epochNow) sea menor que (epochMnt)*/
    if(epochNow <= epochMnt){
      measureNoise();
    }else{
      /*Cambiar estado de banderas*/
      checkTime = false;
      doNoiseAvg = false;
      readBME = true;
    }
  }

  /* Leer sensor BME, calcular promedio ruido, enviar datos*/
  if (readBME){
    /* Mostrar promedios ruido
    * Si el contador cntdB es mayor a cero, entonces se han realizado mediciones
    */
    USB.printf("Numero de muestras: %d \n", cntdB);

    /* Calculo de promedio logaritmico y promedio aritmetrico*/
    if (cntdB > 0){
      leqdBa = 10*log10(sumdBlog/cntdB);
      USB.printf("Promedio log ruido: ");
      USB.printFloat(leqdBa, 2);
      USB.println(" dB");
      
      float leqdBar = sumdB/cntdB;
      USB.print("Promedio ruido: ");
      USB.printFloat(leqdBar, 2);
      USB.println(" dB");
    }else{
      USB.println("There are no noise data, f**k :|");
    }
    
    /* Sensor BME*/
    readSensorBME();

    /* Enviar datos via red GSM*/
    //sendData();

    /* Preparar y encerar variables para nueva iteracion*/
    sumdBlog = 0;
    sumdB = 0;
    cntdB = 0;
    checkTime = true;
    doNoiseAvg = false;
    readBME = false;

    USB.println("________________________________________");
  }
     
}


/* Funcion para suma de valores de ruido
* Si el sensor no esta disponible, establece 
* el valor en cero
*/
void measureNoise(){
  /* Get a new measure of the SPLA from the noise sensor*/
  int status = noise.getSPLA(SLOW_MODE);

  if (status == 0){
  
    // Suma aplicando logaritmos
    float dBAnow = roundf(noise.SPLA*100)/100;
    sumdBlog += pow(10, dBAnow/10); 
        
    /* Suma*/
    sumdB += dBAnow;

    /* Aumentar contador de mediciones*/
    cntdB++;
    
    //USB.printf("Muestra #%d ", cntdB);
    //USB.printFloat(dBAnow, 2);
    //USB.printf(" dbA \n");
    
  }else{
    USB.println(F("[CITIES PRO] Communication error. No response from the audio sensor (SLOW)"));
    sumdBlog += 0;
    sumdB += 0;
  }
}

/* Funcion para leer los valores de Temp, Hum y Pres
* Enciende el sensor BME y al finalizar la lectura lo apaga
*/
void readSensorBME(){
  USB.println(F(">- Reading BME..."));

  /*Encender sensor*/
  bme.ON();
  
  /*Leer valores temp, hum, pres*/
  temperature = bme.getTemperature();
  humidity = bme.getHumidity();
  pressure = bme.getPressure();

  /*And print the values via USB*/
  USB.printf("Temperatura: ");
  USB.printFloat(temperature, 2);
  USB.println(" C");
  USB.printf("Humedad: ");
  USB.printFloat(humidity, 2);
  USB.println(" %");
  USB.printf("Presion: ");
  USB.printFloat(pressure, 2);
  USB.println(" Pa");

  /*Apagar sensor*/
  bme.OFF();
}

/* Funcion que retorna el tiempo actual en formato epoch
* y sumando los minutos especificados en la la variable
* global [mntAvg]
*/
unsigned long addMinutesToNow(unsigned long myEpoch, int minutes){

  /* Aumentar el tiempo de ahora mas minutos */
  unsigned long epochR = epochNow + 60 * minutes;
  timestamp_t   time;
  
  //USB.printf("Epoch Time from now plus %d minutes: %lu", minutes, epochR);

  // Break Epoch time into UTC time
  RTC.breakTimeAbsolute(epochR, &time); 
  USB.printf("Now plus %d minutes: %d/%d/%d %d:%d:%d\n", minutes, time.year, time.month, time.date, time.hour, time.minute, time.second);
 

  return epochR;
}

/* Send the data collected from the sensors using the 4G module
* Parameters: void
* Return: void
*/
void sendData(){

  /* Create frame */
  USB.println(F(">- Create frame..."));
  
  /* Set the Waspmote ID */
  frame.setID(node_ID);

  /* Create new frame (ASCII) */
  frame.createFrame(ASCII);

  /* Add Battery */
  frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel());

  /* Add Board Sensors fields */
  frame.addSensor(SENSOR_CITIES_PRO_NOISE, leqdBa);
  frame.addSensor(SENSOR_CITIES_PRO_TC, temperature);
  frame.addSensor(SENSOR_CITIES_PRO_HUM, humidity);
  frame.addSensor(SENSOR_CITIES_PRO_PRES, pressure);
  
  /* Print frame */
  frame.showFrame();

  // 3.2 HTTP Request
  HTTPRequest();
}

/* Send the composed frame using HTTP Post method
* Parameters: void
* Return: void
*/
void HTTPRequest(){

  boolean tryAtt = true;
  uint16_t attNow = 0;
  
  USB.println(">- Sending data using 4G...");
  uint8_t error;
  
  /* Encender modulo 4G*/
  error = _4G.ON();
  
  /* Comprobar si se prende el modulo 4G */
  if (error == 0){
    
    /* Intentar por las veces especificadas en la variable global [sendAtt] */
    while(tryAtt){
      /* Send the request - HTTP POST */
      error = _4G.sendFrameToMeshlium(host, port, frame.buffer, frame.length);
      
      /* Check the answer of HTTP POST */
      if(error == 0){
        /* Envio realizado, salir de loop*/
        USB.printf("Envio exitoso. HTTP code: ");
        USB.println(_4G._httpCode);
        USB.printf("Server response: ");
        USB.println(_4G._buffer, _4G._length);

        tryAtt = false;
        //break;
      }else{
        /* El envio no pudo ser realizado, proceso de reenvio
        * Apagar modulo 4G
        * Esperar segundos especificados en variable global [waitAtt]
        * Encender modulo 4G
        * Aumentar contador de intento de reenvios [tryAtt]
        */

        USB.printf("Fallo envio, reintentando en %d segundos... \n", waitAtt);
        
        _4G.OFF();
        delay(1000*waitAtt);
        _4G.ON();
        attNow ++;

        /* Si se ha superado el numero de intentos de envio terminar bucle*/
        if(attNow >= sendAtt){
          tryAtt = false;
          //break;
        }

        // If debug mode print error flag
        #if debug_flag != 0
          USB.print(F("[DEBUG] error code: "));
          USB.println(error, DEC);
        #endif
      }
    }
  }else{
    USB.println("[CITIES PRO] Error switching ON the module");
    // If debug mode print error flag
    #if debug_flag != 0
      USB.print("[DEBUG] error code: ");
      USB.println(error, DEC);
    #endif
  }

  /* Apagar modulo 4G*/
  _4G.OFF();
}
As you can see, is very simple, i'm using Waspmote-pro-ide v06.16.
Your comments would be welcome.

dario_espinoza
Posts: 9
Joined: Mon Jan 21, 2019 4:23 pm
Company: UDA

Re: NLS not working

Post by dario_espinoza » Sat Oct 26, 2019 12:14 am

Update

I replaced the NLS and the code is working well

What could be wrong with the other NLS?

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: NLS not working

Post by libelium-dev » Mon Oct 28, 2019 9:21 am

Hi,

Please try to add the following function at the beginning of the measureNoise() function to make sure the communication of the sensor is configured properly.

Code: Select all

    /*Configure the noise sensor for UART communication*/
    noise.configure();
In addition, please test the senor using the following code. Does it work?

Code: Select all

#include <WaspSensorCities_PRO.h>

void setup()
{
  USB.ON(); 
  USB.println(F("Reading Noise Level Sensor"));
  // Configure the noise sensor for UART communication
  noise.configure(); 
}


void loop()
{

  // Get a new measure of the SPLA from the noise sensor
  int status = noise.getSPLA(SLOW_MODE);

  if (status == 0) 
  {
    USB.print(F("Sound Pressure Level with A-Weighting (SLOW): "));
    USB.print(noise.SPLA);
    USB.println(F(" dBA"));
  }
  else
  {
    USB.println(F("[CITIES PRO] Communication error. No response from the audio sensor (SLOW)"));
  }

  delay(5);
  
}
Regards

dario_espinoza
Posts: 9
Joined: Mon Jan 21, 2019 4:23 pm
Company: UDA

Re: NLS not working

Post by dario_espinoza » Mon Oct 28, 2019 2:31 pm

Hi again, i tried the default code for measure noise.

Here is the output:

Code: Select all

Reading Noise Level Sensor
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Sound Pressure Level with A-Weighting (SLOW): -0.0000000000 dBA
Also, i'm adding the noise.configure(); function. Is it well used considering the measureNoise() is executed every second? Could be any trouble in the future?

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: NLS not working

Post by libelium-dev » Tue Oct 29, 2019 9:17 am

Hi,

Please try to power the NLS sensor using another AC/DC adapter and USB cable. Power the NLS, wait a few minutes and turn ON the P&S to read the NLS sensor. If it still doesn't work, please fill the RMA form and out tech support team will contact you to solve the issue.
https://www.libelium.com/contact/#rma

Regards

dario_espinoza
Posts: 9
Joined: Mon Jan 21, 2019 4:23 pm
Company: UDA

Re: NLS not working

Post by dario_espinoza » Tue Oct 29, 2019 1:56 pm

Hi, I've tried now with another travel adapter... and same results again, incorrect noise measuring.

I'm filling the RMA.

Regards

libelium-dev
Posts: 27967
Joined: Mon Sep 28, 2009 1:06 pm

Re: NLS not working

Post by libelium-dev » Wed Oct 30, 2019 9:47 am

Hi,

It seems that the NLS is damaged, please fill the RMA form and our colleagues will contact you to solve the issue.

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest