Compatibility problem between different sensors and sound level sensor

Everything about programming the platform and using the Waspmote API
Post Reply
essj
Posts: 6
Joined: Fri Jun 07, 2019 12:32 pm
Company: HEIA-FR iCoSys

Compatibility problem between different sensors and sound level sensor

Post by essj » Tue Aug 20, 2019 11:49 am

Hi,

My company has a Libelium Smart Cities Pro (4G) platform with different sensors (luminosity, temperature, humidity, pressure, sound level, N2, NO2, O3).
We developped a little sketch that works well, except for getting the sound level. We do recover it, but it is stock with the same value.

Here is the main part (not all of it) of the code :

Code: Select all

void setup()
{
    USB.ON();
    _4G.set_APN(apn, login, password);
    noise.configure(); 
}

void getSensorsValues(struct Sensors_values* val)
{
  if (noise.getSPLA(SLOW_MODE) == 0) 
  {
    val->noisedBA = noise.SPLA;
  }

  bme.ON();
  val->temperature = bme.getTemperature();
  val->humidity = bme.getHumidity();
  val->pressure = bme.getPressure();
  bme.OFF();

  luxes.ON();
  val->luminosity = luxes.getLuminosity();
  luxes.OFF();
  
  gas_sensorB.ON();
  val->concentrationNO2 = gas_sensorB.getConc(val->temperature);
  gas_sensorB.OFF();

  gas_sensorC.ON();
  val->concentrationO3 = gas_sensorC.getConc(val->temperature);
  gas_sensorC.OFF();

  int statusPM = OPC_N2.ON();
  
  if (statusPM == 1)
  {
    int measure = OPC_N2.getPM(5000, 5000);
    
    if (measure == 1)
    {      
      val->N2_PM1 = OPC_N2._PM1;
      val->N2_PM2_5 = OPC_N2._PM2_5;
      val->N2_PM10 = OPC_N2._PM10;      
    }
    else
    {
      USB.print(F("Error performing the measure. Error code:"));
      USB.println(measure, DEC);
    }
  }

  OPC_N2.OFF();
  
}
When we display the data (every 60 seconds), everything is good except that sound level.
I can post all the code if needed (the part missing are only function used to print/push values into or database).

Do you have any idea ?

Regards,

Matthieu

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

Re: Compatibility problem between different sensors and sound level sensor

Post by libelium-dev » Tue Aug 20, 2019 3:20 pm

Hi,

Which output do you gent from the NLS?

Did you test the sensor with the example code?

http://www.libelium.com/development/was ... l-sensorg/

Did you put the noise.configure(); function somewhere in your code to configure the sensor as in the example?

Regards

essj
Posts: 6
Joined: Fri Jun 07, 2019 12:32 pm
Company: HEIA-FR iCoSys

Re: Compatibility problem between different sensors and sound level sensor

Post by essj » Wed Aug 21, 2019 8:16 am

The output from the NLS is a constant value (in our case 50).
No problem with the example code which work well, we got correct value every sec.
The noise.configure() is in the setup function.

Here is the all code :

Code: Select all

#include <Wasp4G.h>
#include <WaspSensorCities_PRO.h>
#include <WaspOPC_N2.h>

///////////////////////////////////////
// APN / SIM settings
///////////////////////////////////////
char apn[] = "N/A";
char login[] = "N/A";
char password[] = "N/A";
char pin[] = "N/A";

///////////////////////////////////////
// SERVER settings
///////////////////////////////////////
char host[] = "N/A";
uint16_t port = N/A;


///////////////////////////////////////
// SSL settings
///////////////////////////////////////
uint8_t socketId = Wasp4G::CONNECTION_1;

char http_format[] =
  "POST /push_to_bbdata HTTP/1.1\r\n"\
  "Host: %s\r\n"\
  "Content-Type: application/json\r\n"\
  "Content-Length: %i\r\n\r\n%s";
char data[500]; 

// char measure_format_string[] = "{\"objectId\":%i,\"timestamp\":\"%s\",\"value\":\"%s\",\"token\":\"%s\"}";
char measure_format_float[] = "{\"id\":%i,\"value\":\"%s\",\"token\":\"%s\"}";
char measure_format_uint32[] = "{\"id\":%i,\"value\":\"%lu\",\"token\":\"%s\"}";
char body[200];


///////////////////////////////////////
// SENSORS
///////////////////////////////////////
#define SENSOR_COUNT 10
bmeCitiesSensor  bme(SOCKET_E);
luxesCitiesSensor  luxes(SOCKET_F);
Gas gas_sensorB(SOCKET_B);
Gas gas_sensorC(SOCKET_C);

int sensors_bbid[SENSOR_COUNT];
const char *sensors_bbtoken[SENSOR_COUNT];

enum Sensors_BBID {
  LUMINOSITY,
  TEMPERATURE,
  HUMIDITY,
  PRESSURE,
  NOISE,
  PM1,
  PM2_5,
  PM10,
  NO2,
  O3
  };

// variable
struct Sensors_values{
  uint32_t luminosity; // Stores the luminosity in luxes
  float temperature;  // Stores the temperature in ºC
  float humidity;   // Stores the realitve humidity in %RH
  float pressure;   // Stores the pressure in Pa
  uint32_t noisedBA; // Stores the noise in dBA
  float N2_PM1; // Stores the N2_PM1 in ug/m3
  float N2_PM2_5; // Stores the N2_PM2.5 in ug/m3
  float N2_PM10; // Stores the N2_PM10 in ug/m3
  float concentrationNO2;  // Stores the concentration level in ppm
  float concentrationO3;  // Stores the concentration level in ppm
} sensors;

void initBBDATAInfos()
{
    // N/A

}

void setup()
{
    USB.ON();
    _4G.set_APN(apn, login, password);
    noise.configure(); 
    initBBDATAInfos();
}

void getSensorsValues(struct Sensors_values* val)
{
  if (noise.getSPLA(SLOW_MODE) == 0) 
  {
    val->noisedBA = noise.SPLA;
  }

  bme.ON();
  val->temperature = bme.getTemperature();
  val->humidity = bme.getHumidity();
  val->pressure = bme.getPressure();
  bme.OFF();

  luxes.ON();
  val->luminosity = luxes.getLuminosity();
  luxes.OFF();
  
  gas_sensorB.ON();
  val->concentrationNO2 = gas_sensorB.getConc(val->temperature);
  gas_sensorB.OFF();

  gas_sensorC.ON();
  val->concentrationO3 = gas_sensorC.getConc(val->temperature);
  gas_sensorC.OFF();

  int statusPM = OPC_N2.ON();
  
  if (statusPM == 1)
  {
    int measure = OPC_N2.getPM(5000, 5000);
    
    if (measure == 1)
    {      
      val->N2_PM1 = OPC_N2._PM1;
      val->N2_PM2_5 = OPC_N2._PM2_5;
      val->N2_PM10 = OPC_N2._PM10;      
    }
    else
    {
      USB.print(F("Error performing the measure. Error code:"));
      USB.println(measure, DEC);
    }
  }

  OPC_N2.OFF();
  
}

void printValues(struct Sensors_values* val)
{
  USB.print(F("Sound Pressure Level with A-Weighting (SLOW): "));
  USB.print(val->noisedBA);
  USB.println(F(" dBA"));


  USB.print(F("Temperature: "));
  USB.printFloat(val->temperature, 2);
  USB.println(F(" Celsius degrees"));
  USB.print(F("RH: "));
  USB.printFloat(val->humidity, 2);
  USB.println(F(" %"));
  USB.print(F("Pressure: "));
  USB.printFloat(val->pressure, 2);
  USB.println(F(" Pa"));

  USB.print(F("Luminosity: "));
  USB.print(val->luminosity);
  USB.println(F(" luxes"));


  USB.println(F("Measure performed"));
  USB.print(F("PM 1: "));
  USB.printFloat(val->N2_PM1, 3);
  USB.println(F(" ug/m3"));
  USB.print(F("PM 2.5: "));
  USB.printFloat(val->N2_PM2_5, 3);
  USB.println(F(" ug/m3"));
  USB.print(F("PM 10: "));
  USB.printFloat(val->N2_PM10, 3);
  USB.println(F(" ug/m3"));
  

  USB.print(F("Gas concentration NO2: "));
  USB.printFloat(val->concentrationNO2, 3);
  USB.println(F(" ppm"));

  USB.print(F("Gas concentration O3: "));
  USB.printFloat(val->concentrationO3, 3);
  USB.println(F(" ppm"));
}

void sendData(enum Sensors_BBID sensor, void* value) 
{
  switch(sensor) 
  {
    case LUMINOSITY:
    case NOISE:
      snprintf(body, sizeof(body), measure_format_uint32, sensors_bbid[sensor], *((uint32_t*)value), sensors_bbtoken[sensor]);
      break;
    default:
      char float_str[10];
      dtostrf(*((float*)value), 1, 3, float_str);
      snprintf(body, sizeof(body), measure_format_float, sensors_bbid[sensor], float_str, sensors_bbtoken[sensor]);
      break;
  };

  snprintf( data, sizeof(data), http_format, host, strlen(body), body);

  uint8_t error = _4G.send(socketId, data);
  if (error != 0)
  {
    USB.print(F("2.3. Error sending data. Code: "));
    USB.println(error, DEC);
    return;
  }

  error = _4G.receive(socketId, 60000);

  if (error != 0) {
    USB.print(F("2.3. Error receiving data. Code: "));
    USB.println(error, DEC);
  }
  
}

void pushValues(struct Sensors_values* val)
{
  uint8_t error = _4G.ON();
  if(error == 0) { 
    unlockSIM();
    
    error = _4G.openSocketClient(socketId, Wasp4G::TCP, host, port);
 
    // Check the answer
    if (error == 0)
    {
      sendData(LUMINOSITY, &val->luminosity);
      sendData(TEMPERATURE, &val->temperature);
      sendData(HUMIDITY, &val->humidity);
      sendData(PRESSURE, &val->pressure);
      sendData(NOISE, &val->noisedBA);
      sendData(PM1, &val->N2_PM1);
      sendData(PM2_5, &val->N2_PM2_5);
      sendData(PM10, &val->N2_PM10);
      sendData(NO2, &val->concentrationNO2);
      sendData(O3, &val->concentrationO3);
    }
    else
    {
      USB.print(F("2. Error opening socket. Error code: "));
      USB.println(error, DEC);
    }
    _4G.OFF();
    
  } else {
     USB.print(F("Failed. Error code: "));
     USB.println(error, DEC);
  }
}

void loop()
{
  getSensorsValues(&sensors);
  pushValues(&sensors);
  delay(60);
}

//PRE: 4G module started
bool unlockSIM()
{
  
  uint8_t PIN_status;
  
  while( (PIN_status = _4G.checkPIN()) != 1) {
    delay(1);
  }
  
  if (_4G.enterPIN(pin) == 0) 
  {
    USB.println(F("sim unlocked"));
    return true;
  }
  else
  {
    USB.println(F("error unlocking sim"));
  }
  return false;
}

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

Re: Compatibility problem between different sensors and sound level sensor

Post by libelium-dev » Wed Aug 21, 2019 2:54 pm

Hi,

Please, try to recode your program to read the NLS in the same way as the example.

Regards

essj
Posts: 6
Joined: Fri Jun 07, 2019 12:32 pm
Company: HEIA-FR iCoSys

Re: Compatibility problem between different sensors and sound level sensor

Post by essj » Thu Aug 29, 2019 7:27 am

We can only recover the NSL under certain circunstances.
Everything works fine if we remove the other sensors and/or if we do not use the 4G module to send the data over the internet.
It seems that the 4G module/other sensors are interfering with the sound sensor (still have a constant value).
Any ideas?

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

Re: Compatibility problem between different sensors and sound level sensor

Post by libelium-dev » Thu Aug 29, 2019 8:19 am

Hi,

Please add the noise.configure() function before reading the noise sensor (noise.getSPLA(SLOW_MODE) function). That function configures the UART to be able to communicate to the sensor. If noise.configure() function isn't run before reading the sensor, the UART will be misconfigured due to it is shared with the 4G module which uses another configuration.

Code: Select all

  noise.configure();
  if (noise.getSPLA(SLOW_MODE) == 0) 
  {
    val->noisedBA = noise.SPLA;
  }

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest