local database not storing sensor data from waspmote v1.5

Development questions: create new plugins, add new features...
Post Reply
FIU Grad
Posts: 81
Joined: Wed Nov 16, 2016 10:37 pm

local database not storing sensor data from waspmote v1.5

Post by FIU Grad » Sun Jun 23, 2019 5:05 am

Hello,

I have one waspmote v1.2 and 4 waspmote 1.5. The meshlium is v3.2.9.
I am currently sending sensor data from all the waspmotes and I am able to see the logs on the sensor and frames log on the manager system for all of them. However, the only frames that gets stored/synched in the local database are the frame that is coming from waspmote v1.2.
I am not sure why the frames coming from all the waspmote v1.5 are not pushed to the local database.

The sensor/frame logs in the manager system: https://drive.google.com/open?id=1cjCFl ... xpahKCENms
The capturer looks like this: https://drive.google.com/open?id=1yoCYw ... xRmbbaqpwc

Bravo is the waspmote v1.2 and the only one being captured in the local database.
Zulu, Charlie, Delta, and echo send frames but are not being captured in the local database.

Thanks for the help.

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

Re: local database not storing sensor data from waspmote v1.5

Post by libelium-dev » Mon Jun 24, 2019 7:52 am

Hi,

We are sorry but Meshlium 3 isn't compatible with Waspmote v15. It can't parse the frames received from Waspmote v15.

Regards

FIU Grad
Posts: 81
Joined: Wed Nov 16, 2016 10:37 pm

Re: local database not storing sensor data from waspmote v1.5

Post by FIU Grad » Mon Jun 24, 2019 4:26 pm

Why was this not communicated to me when I was making the four waspmote purchase?
The sales rep very much knew I had a meshlium 3 and failed to let me know this issue. We had previously made an order of two waspmote v12 and a meshlium 3 before the purchase of the newer versions. These issues should have been addressed before leading the customer to make another purchase. Ok, what now?

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

Re: local database not storing sensor data from waspmote v1.5

Post by libelium-dev » Tue Jun 25, 2019 9:20 am

Hi,

Apologies for the inconvenience. Please contact your sales agent to try to find a solution.

Regards

FIU Grad
Posts: 81
Joined: Wed Nov 16, 2016 10:37 pm

Re: saving agriv20 frames on SD card

Post by FIU Grad » Wed Jul 17, 2019 7:59 pm

I am trying to store agriculture v20 frames on an SD card since I can't send them to the meshlium.
However, I am having a problem in creating a file and appending it. It was working fine at the beginning but when I put together everything in the code I am getting an error. I just modified the SD_07 example to my need.
The sequence of the code is as follow; create a file, read and measure sensor data, create a frame, save it on the SD card and send frames to meshlium via XBee (even though meshlium doesn't save it, I want to see the frame on the log).

As I stated, the problem is with file path, filename and appending . This is what I am getting on the usb port

Code: Select all

 
 H#
Zulu SD_07 frame
mkdir failed
file NOT deleted
file not created
===============================
Current ASCII Frame:
Length: 80
Frame Type:  134
frame (HEX): 3C3D3E86052335453333333730353743313035343345235A756C75233023534F494C313A35322E3030234C573A3023534F494C54433A32332E3834234241543A3938235241443A342E31383930303023
frame (STR): <=>†#5E3337057C10543E#Zulu#0#SOIL1:52.00#LW:0#SOILTC:23.84#BAT:98#RAD:4.189000#
===============================
Frame to be stored:3C3D3E86052335453333333730353743313035343345235A756C75233023534F494C313A35322E3030234C573A3023534F494C54433A32332E3834234241543A3938235241443A342E31383930303023
Append failed
Get previously stored frame:à 
This is the whole code, and can you please go through it and tell me the problem? Thanks

Code: Select all

#include <WaspFrame.h>
#include <WaspSensorAgr_v30.h>
#include <WaspXBeeZB.h>
#include <BME280.h>

// define folder and file to store data
char path[]="/zuludata";
char filename[]="/zuludata/log.txt";

// buffer to write into Sd File
char toWrite[200];

// define variables to read stored frames 
uint8_t frameSD[MAX_FRAME+1];
uint16_t lengthSD;
int32_t numLines;

// variables to define the file lines to be read
int startLine;
int endLine;

// define variable
uint8_t sd_answer;
uint8_t sd_ansDel;
uint8_t sd_ansMake;

// define variable
uint8_t error;

// Define the Waspmote ID
char node_ID[] = "Zulu";
// Destination MAC address

//////////////////////////////////////////
char RX_ADDRESS[] = "0013A20040F3C62F";
//////////////////////////////////////////

//Instance sensor object
leafWetnessClass lwSensor;
watermarkClass wmSensor1(SOCKET_1);
pt1000Class pt1000Sensor;

//variables to store sensors readings
float temperature;
float watermark1;
uint8_t wetness;
float pt1000Temperature;
float radiation;

void setup()
{

  // Checks if we come from a normal reset or an hibernate reset
  PWR.ifHibernate();
  
  // open USB port
  USB.ON();
  USB.println(F("Zulu SD_07 frame"));

  // Create a directory and initial data and send log file
  createFile();

   RTC.ON();

  // Set SD ON
  SD.ON();

  // Turn on the sensor board
  Agriculture.ON();

   // store Waspmote identifier in EEPROM memory
  frame.setID( node_ID );
 
}

void loop()
{    

  // If Hibernate has been captured, execute the associated function
  if( intFlag & HIB_INT )
  {
    USB.println(F("---------------------"));
    USB.println(F("Hibernate Interruption captured"));
    USB.println(F("---------------------"));
    intFlag &= ~(HIB_INT);
    delay(5000);
  }

  // 2. measure sensors
   measureSensors();

  // save data to SD
   dataSave(); 
    
  // 4. init XBee
   xbeeZB.ON();
   delay(1000);

   // 4. check XBee's network parameters
  checkNetworkParams();

  ////////////////////////////////////////////
  // 5. Send packet
  ////////////////////////////////////////////////

   // 5.2 Send XBee packet
  error = xbeeZB.send( RX_ADDRESS, frame.buffer, frame.length ); 

   // 5.3 check TX flag
  if( error == 0 )
  {
    USB.println(F("send ok"));

    // blink green LED
    Utils.blinkGreenLED();
  }
  else
  {
    USB.println(F("send error"));

    // blink red LED
    Utils.blinkRedLED();
  }

    // 5.4 Communication module to OFF
   xbeeZB.OFF();
  
    // wait for five seconds
   delay(5000);

   //Turn off RTC
   RTC.OFF ();
       
   USB.println(F("enter hibernate mode"));

  // Set Waspmote to Hibernate, waking up after 10 seconds
  PWR.hibernate("00:12:00:00",RTC_OFFSET,RTC_ALM1_MODE2);

}

  //////////////////////////////////////////////
  //1. Create a file to save data to
  //////////////////////////////////////////////
void createFile()
{
 
 // 1.1 create path
  sd_answer = SD.mkdir(path);
  
  if( sd_answer == 1 )
  { 
    USB.println(F("path created"));
  }
  else
  {
    USB.println(F("mkdir failed"));
  }

  // Delete file for Waspmote Frames
  sd_answer = SD.del(filename);

  if( sd_answer == 1 )
  {
  USB.println(F("file deleted"));
  }
  else 
  {
  USB.println(F("file NOT deleted")); 
  }
  
  // 1.2 Create file for Waspmote Frames
  sd_answer = SD.create(filename);
  
  if( sd_answer == 1 )
  { 
    USB.println(F("file created"));
  }
  else
  {
   USB.println(F("file not created"));
  }

  // Turn off the SD
  SD.OFF();
}

void measureSensors()
{
  //////////////////////////////////////////
  // 2.1 Read sensors
  ///////////////////////////////////////////  
  
  // Read the watermark 1 sensor 
   watermark1 = wmSensor1.readWatermark();
  // Read the leaf wetness sensor 
   wetness = lwSensor.getLeafWetness();
  // Read the PT1000 sensor 
   pt1000Temperature = pt1000Sensor.readPT1000();

   // 2.2 Turn OFF the sensor board
  Agriculture.OFF();

  // 2.3 Create new frame (ASCII)
  frame.createFrame(ASCII, "Zulu");

 // Add watermark 1
  frame.addSensor(SENSOR_AGR_SOIL1, watermark1);
  // Add wetness
  frame.addSensor(SENSOR_AGR_LW, wetness);
  // Add PT1000
  frame.addSensor(SENSOR_AGR_SOILTC, pt1000Temperature);
  // Add battery level
  frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel());
  //Add battery Volts
  frame.addSensor(SENSOR_RADIATION, PWR.getBatteryVolts());

  // Show the frame
  frame.showFrame();
     
   memset(toWrite, 0x00, sizeof(toWrite) ); 

  // 2.4 Conversion from Binary to ASCII
  Utils.hex2str( frame.buffer, toWrite, frame.length);

  USB.print(F("Frame to be stored:"));
  USB.println(toWrite);

  //wait 2 seconds
  delay(2000);
}

void dataSave()
{
   ///////////////////////////////////////////////////////   
  // 3. Append data into file
  /////////////////////////////////////////////////////  
  
  sd_answer = SD.appendln(filename, toWrite);
  
  if( sd_answer == 1 )
  {
    USB.println(F("Frame appended to file"));
  }
  else 
  {
    USB.println(F("Append failed"));
  }

  /////////////////////////////////////////////////////
  // 3.1 Get information from File
  /////////////////////////////////////////////////////  

  // 3.2 get number of lines in file
  numLines = SD.numln(filename);
  
  // get specified lines from file
  // get only the last file line
  startLine = numLines-1; 
  endLine = numLines;
  
  // iterate to get the File lines specified
  for( int i=startLine; i<endLine ; i++ )
  {  
    // Get 'i' line -> SD.buffer
    SD.catln( filename, i, 1); 
    
    // initialize frameSD
    memset(frameSD, 0x00, sizeof(frameSD) ); 
    
    // conversion from ASCII to Binary 
    lengthSD = Utils.str2hex(SD.buffer, frameSD );

    // Conversion from ASCII to Binary 
    USB.print(F("Get previously stored frame:"));
    for(int j=0; j<lengthSD; j++)
    {    
      USB.print(frameSD[j],BYTE);
    }
    USB.println();
    
    /************************************************
    * At this point 'frameSD' and 'lengthSD' can be 
    * used as 'frame.buffer' and 'frame.length' to 
    * send information via some communication module 
    *************************************************/
  }
  
  USB.println();
  delay(2000);
}

void checkNetworkParams()
{
  // 4.1 get operating 64-b PAN ID
  xbeeZB.getOperating64PAN();

  // 4.2 wait for association indication
  xbeeZB.getAssociationIndication();

  while( xbeeZB.associationIndication != 0 )
  {   
    //printAssociationState();

    delay(2000);

    // 4.4 get operating 64-b PAN ID
    xbeeZB.getOperating64PAN();

    USB.print(F("operating 64-b PAN ID: "));
    USB.printHex(xbeeZB.operating64PAN[0]);
    USB.printHex(xbeeZB.operating64PAN[1]);
    USB.printHex(xbeeZB.operating64PAN[2]);
    USB.printHex(xbeeZB.operating64PAN[3]);
    USB.printHex(xbeeZB.operating64PAN[4]);
    USB.printHex(xbeeZB.operating64PAN[5]);
    USB.printHex(xbeeZB.operating64PAN[6]);
    USB.printHex(xbeeZB.operating64PAN[7]);
    USB.println();     

    xbeeZB.getAssociationIndication();
  }

  USB.println(F("\nJoined a network!"));

  // 4.5 get network parameters 
  xbeeZB.getOperating16PAN();
  xbeeZB.getOperating64PAN();
  xbeeZB.getChannel();

  USB.print(F("operating 16-b PAN ID: "));
  USB.printHex(xbeeZB.operating16PAN[0]);
  USB.printHex(xbeeZB.operating16PAN[1]);
  USB.println();

  USB.print(F("operating 64-b PAN ID: "));
  USB.printHex(xbeeZB.operating64PAN[0]);
  USB.printHex(xbeeZB.operating64PAN[1]);
  USB.printHex(xbeeZB.operating64PAN[2]);
  USB.printHex(xbeeZB.operating64PAN[3]);
  USB.printHex(xbeeZB.operating64PAN[4]);
  USB.printHex(xbeeZB.operating64PAN[5]);
  USB.printHex(xbeeZB.operating64PAN[6]);
  USB.printHex(xbeeZB.operating64PAN[7]);
  USB.println();

  USB.print(F("channel: "));
  USB.printHex(xbeeZB.channel);
  USB.println();

}

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

Re: local database not storing sensor data from waspmote v1.5

Post by libelium-dev » Thu Jul 18, 2019 8:13 am

Hi,

The mkdir(), del() and create() functions don't work because the SD is OFF. The SD is turned ON before the createFile() function.

The same problem occurs in the dataSave() function. The SD is turned ON in the setup but it will be turned OFF when PWR.hibernate() function is executed, so you will need to turn it ON again.

Regards

FIU Grad
Posts: 81
Joined: Wed Nov 16, 2016 10:37 pm

Re: local database not storing sensor data from waspmote v1.5

Post by FIU Grad » Thu Jul 18, 2019 10:27 pm

Thanks, that worked.
However, I have other questions.
1. Based on my understanding the code above is supposed to take the measurement and store the frame appending it to the last frame stored. This is supposed to happen on the same file I have declared on the code. Right? But when I read the SD card, I only see one frame stored. I have changed hibernate mode to 1 min to take measurement & store as many times as possible. But I don't see the other frames. Why is that ? is it something on my code?

2. The stored frame appear in Hex, I want them to be saved in this format to make it easier to export to other applications

Code: Select all

frame (STR): <=>†#5E3337057C10543E#Zulu#0#SOIL1:51.80#LW:0#SOILTC:23.20#BAT:90#RAD:4.119000#
how can I achieve this?

3. I will be using python to do data analysis, so a CSV file will be ideal. Is there a way that I can save the files as a CSV?

Thanks again for your help & prompt responses.

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

Re: local database not storing sensor data from waspmote v1.5

Post by libelium-dev » Fri Jul 19, 2019 8:27 am

Hi,

How do you read the file? The code reads the last frame stored, you can use SD.showFile(filename) function to read the file

The code converts from ascii to hex, you can comment those line of code to avoid that

Code: Select all

  memset(toWrite, 0x00, sizeof(toWrite) ); 
  memcpy(toWrite, frame.buffer, frame.length);

//  // Conversion from Binary to ASCII
//  Utils.hex2str( frame.buffer, toWrite, frame.length);
  USB.print(F("Frame to be stored:"));
  USB.println(toWrite);

Code: Select all

    // initialize frameSD
    memset(frameSD, 0x00, sizeof(frameSD) ); 
    memcpy(frameSD, frame.buffer, sizeof(frameSD));
    
    // conversion from ASCII to Binary 
    //lengthSD = Utils.str2hex(SD.buffer, frameSD );

    // Conversion from ASCII to Binary 
    USB.print(F("Get previously stored frame:"));
    for(int j=0; j<sizeof(frameSD); j++)
    {    
      USB.print(frameSD[j],BYTE);
    }
    USB.println();
There aren't functions to save data in cvs format. You can develop that creating your own format using snprintf() function. You can find some example in the following link.
http://www.libelium.com/development/was ... d-strings/

Regards

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest