Appending concentration in the SD card - Smart Environment Pro

Everything about programming the platform and using the Waspmote API
Post Reply
cyril_dewez_hzs
Posts: 3
Joined: Fri Nov 29, 2019 5:42 pm
Company: HZS Antwerpen

Appending concentration in the SD card - Smart Environment Pro

Post by cyril_dewez_hzs » Wed Dec 04, 2019 11:15 pm

Dear Libelium users,

I'm a beginner student of the Libelium Plug and Sense Smart Environment Pro V15. My goal is to put the Libelium Plug & Sense on board a ship to measure the air quality. As there is no internet connection, I have to store all my concentrations value into the SD card to then recover the device and get the data from the SD card.

Until now, I am able to collect all the concentrations from my CO, SO2, O3, NO2, particule matter, temperature, humidity and pressure sensors. My issue is about the SD card programming. I would like to store those values separated with ";" in a text file, to be able then to make an USB print of all the value, to copy-paste it into an Excel and then to convert this kind of CSV file to an usable Excel file.

I give you thereafter the useful part of my code: part of the beginning, part of the setup and the SD writing part of the loop.

Code: Select all

#include <WaspSensorGas_Pro.h>      //Libraries pour tous les sensors

  Gas CO_PRO_sensor(SOCKET_A);
  Gas SO2_PRO_sensor(SOCKET_F);
  Gas O3_PRO_sensor(SOCKET_B);
  Gas NO2_PRO_sensor(SOCKET_C);
  bmeGasesSensor  bme;              //Température sur SOCKET_E

  float CO_concentration;           //Probes gaz
  float O3_concentration;
  float NO2_concentration;
  float SO2_concentration;
  float temperature;                //Probe température
  float humidity;
  float pressure;
  float PM_1;                       //Probe Particule matter
  float PM_2_5;
  float PM_10;

//SD writing
  int data_number;
  uint8_t sd_answer;
  #define filename "test_1.TXT"     //Should be short

//SD read
  char output[101];

//Data converting
  char number[20];

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////SETUP///////////////////////////////SETUP////////////////////////////////////SETUP///////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


void setup()
{

//SD card  

  SD.ON();
SD.showFile(filename);	//Easy way to read the data and send it through the USB to be then
					//copy-paste in Excel by shutting off and on the Libelium

USB.print(F("Creating the file...                    "));
   sd_answer = SD.create(filename);
   if( sd_answer == 1 )
      {
        USB.println(F("file created"));
      }
      else 
      {
        USB.println(F("file NOT created")); 
      } 

 
}
 

   
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////LOOP///////////////////////////////LOOP////////////////////////////////////LOOP//////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void loop()
{

//Read the concentrations from the sensors
    CO_concentration = CO_PRO_sensor.getConc();
    O3_concentration = O3_PRO_sensor.getConc();
    NO2_concentration = NO2_PRO_sensor.getConc();
    SO2_concentration = SO2_PRO_sensor.getConc();
    temperature = bme.getTemperature();
    humidity = bme.getHumidity();
    pressure = bme.getPressure();

//Write data on the SD Card

  SD.append(filename,RTC.getTime());
  SD.appendln(filename,";");
  
  SD.append(filename,CO_concentration);
  SD.append(filename,";");
  
  SD.append(filename,O3_concentration);
  SD.append(filename,";");
  
  SD.append(filename,NO2_concentration);
  SD.append(filename,";");
  
  SD.append(filename,SO2_concentration);
  SD.append(filename,";");
  
  SD.append(filename,PM_1);
  SD.append(filename,";");
  
  SD.append(filename,PM_2_5);
  SD.append(filename,";");
  
  SD.append(filename,PM_10);
  SD.append(filename,";");
  
  SD.append(filename,temperature);
  SD.append(filename,";");
  
  SD.append(filename,humidity);
  SD.append(filename,";");
  
  SD.append(filename,pressure);
  SD.appendln(filename,";");

}

I got many errors from the Waspnote PRO IDE, as "overload of the SD.append function", problem with the variable (I have tried "float", "char", and anything works).

I then tried to convert my data from float to string doing like this:

Code: Select all

  SD.append(filename,RTC.getTime());
  SD.appendln(filename,";");
  
  SD.append(filename,Utils.float2String(CO_concentration, number, 3)); // Convert ... to string (3 decimals) 
  SD.append(filename,";");
  
  SD.append(filename,Utils.float2String(O3_concentration, number, 3));
  SD.append(filename,";");
  
  SD.append(filename,Utils.float2String(NO2_concentration, number, 3));
  SD.append(filename,";");
  
  SD.append(filename,Utils.float2String(SO2_concentration, number, 3));
  SD.append(filename,";");
  
  SD.append(filename,Utils.float2String(PM_1, number, 3));
  SD.append(filename,";");
  
  SD.append(filename,Utils.float2String(PM_2_5, number, 3));
  SD.append(filename,";");
  
  SD.append(filename,Utils.float2String(PM_10, number, 3));
  SD.append(filename,";");
  
  SD.append(filename,Utils.float2String(temperature, number, 3));
  SD.append(filename,";");
  
  SD.append(filename,Utils.float2String(humidity, number, 3));
  SD.append(filename,";");
  
  SD.append(filename,Utils.float2String(pressure, number, 3));
  SD.appendln(filename,";");
...but I also get some warning message from the IDE.

Could someone help me please?

Thankfully,

Cyril Dewez

PS: If you need the full part to try by yourself: https://docs.google.com/document/d/1bRq ... sp=sharing

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

Re: Appending concentration in the SD card - Smart Environment Pro

Post by libelium-dev » Thu Dec 05, 2019 10:53 am

Hi,

We recommend you to formate a string using snprintf() function. You can see some examples in the following link
http://www.libelium.com/development/was ... d-strings/

Code: Select all

  char data[200];
  char format_str[] = "%s;%s;%s;%s;%s;%s;%s;%s;%s;%s;%s";

  char CO_concentration_str[10];           //Probes gaz
  char O3_concentration_str[10];
  char NO2_concentration_str[10];
  char SO2_concentration_str[10];
  char temperature_str[10];                //Probe température
  char humidity_str[10];
  char pressure_str[15];
  char PM_1_str[15];                       //Probe Particule matter
  char PM_2_5_str[15];
  char PM_10_str[15];

  // convert from float to string
  dtostrf( CO_concentration, 1, 3, CO_concentration_str);
  dtostrf( O3_concentration, 1, 3, O3_concentration_str);
  dtostrf( NO2_concentration, 1, 3, NO2_concentration_str);
  dtostrf( SO2_concentration, 1, 3, SO2_concentration_str);
  dtostrf( temperature, 1, 3, temperature_str);
  dtostrf( humidity, 1, 3, humidity_str);
  dtostrf( pressure, 1, 3, pressure_str);
  dtostrf( PM_1, 1, 3, PM_1_str);
  dtostrf( PM_2_5, 1, 3, PM_2_5_str);
  dtostrf( PM_10, 1, 3, PM_10_str);

  snprintf( data, sizeof(data), format_str, RTC.getTime(), CO_concentration_str, O3_concentration_str, 
            NO2_concentration_str, SO2_concentration_str, temperature_str, humidity_str, pressure_str, 
            PM_1_str, PM_2_5_str, PM_10_str);

  //Write data on the SD Card
  SD.appendln(filename, data);
Hope this helps.
Regards

cyril_dewez_hzs
Posts: 3
Joined: Fri Nov 29, 2019 5:42 pm
Company: HZS Antwerpen

Re: Appending concentration in the SD card - Smart Environment Pro

Post by cyril_dewez_hzs » Sun Dec 15, 2019 4:56 pm

Madam, Mister,

Thank you very much for your reply. My Libelium SD Card is now writing and reading correctly.

See you maybe soon in this forum,

Cyril

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

Re: Appending concentration in the SD card - Smart Environment Pro

Post by libelium-dev » Mon Dec 16, 2019 11:38 am

Glad to hear that the problem was solved! :D

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest