Reading Smart Water sensor values for Waspmote v12

Post Reply
josemaria
Posts: 59
Joined: Thu Sep 15, 2016 10:57 am

Reading Smart Water sensor values for Waspmote v12

Post by josemaria » Thu Jul 27, 2017 10:06 am

Hi!

Firstly, thanks for your support. The following example is valid only for Waspmote v15:

http://www.libelium.com/development/was ... s-utility/

Sorry, what is the equivalent code for Waspmote v12?. That is my version of Libelium's Plug & Sense! Smart Water waspmote.

Thank you. Regards,

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

Re: Reading Smart Water sensor values for Waspmote v12

Post by libelium-dev » Thu Jul 27, 2017 11:39 am

Hi,

You can find the example for v12 in the following link, the changes are in the sensor fields for the frame.
http://www.libelium.com/v12/development ... class-v12/

On the other hand, if you are using last API, you have to use

Code: Select all

Water.[function];
but if you are using API v023, you have to use

Code: Select all

SensorSW.[function];
Don't hesitate to ask if you have any doubt.

Regards

josemaria
Posts: 59
Joined: Thu Sep 15, 2016 10:57 am

Re: Reading Smart Water sensor values for Waspmote v12

Post by josemaria » Thu Jul 27, 2017 11:28 pm

Hi!

Firstly, thanks for your support. Sorry, I do not understand. My Waspmote IDE configuration is as follows:

Waspmote PRO IDE v05
API v26

In addition, the version of my Waspmote sensor node is v12. Then, what is the correct code to read the Smart Water sensor values?. Please, could you help me?

Thank you. Regards,

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

Re: Reading Smart Water sensor values for Waspmote v12

Post by libelium-dev » Fri Jul 28, 2017 8:51 am

Hi,

It's a bit confusing but in that case you have to use the example for v15 but if you create frames you have to use the sensors fields for v12. For example,

Code: Select all

...
...
  ///////////////////////////////////////////
  // 1. Turn on the board
  /////////////////////////////////////////// 

  Water.ON();
  delay(2000);

  ///////////////////////////////////////////
  // 2. Read sensors
  ///////////////////////////////////////////  

  // Read the ph sensor
  value_pH = pHSensor.readpH();
  // Read the temperature sensor
  value_temp = TemperatureSensor.readTemperature();
  // Convert the value read with the information obtained in calibration
  value_pH_calculated = pHSensor.pHConversion(value_pH,value_temp);  
  // Reading of the ORP sensor
  value_orp = ORPSensor.readORP();
  // Apply the calibration offset
  value_orp_calculated = value_orp - calibration_offset;
  // Reading of the DI sensor
  value_di = DISensor.readDI();
  // Reading of the ORP sensor
  value_do = DOSensor.readDO();
  // Conversion from volts into dissolved oxygen percentage
  value_do_calculated = DOSensor.DOConversion(value_do);
  // Reading of the Conductivity sensor
  value_cond = ConductivitySensor.readConductivity();
  // Conversion from resistance into ms/cm
  value_cond_calculated = ConductivitySensor.conductivityConversion(value_cond);  
  
  ///////////////////////////////////////////
  // 3. Turn off the sensors
  /////////////////////////////////////////// 

   Water.OFF();
  ///////////////////////////////////////////
  // 4. Create ASCII frame
  /////////////////////////////////////////// 

  // Create new frame (ASCII)
  frame.createFrame(ASCII);
  
  // Add temperature
  frame.addSensor(SENSOR_WT, value_temp);
  // Add PH
  frame.addSensor(SENSOR_PH, value_pH_calculated);
  // Add ORP value
  frame.addSensor(SENSOR_ORP, value_orp_calculated);
    // Add DO value
  frame.addSensor(SENSOR_DO, value_do_calculated);
  // Add conductivity value
  frame.addSensor(SSENSOR_COND, value_cond_calculated);
...
...
Here you can see all sensor fields for Waspmote v12,
http://www.libelium.com/downloads/docum ... ide.pdf#10

Regards

josemaria
Posts: 59
Joined: Thu Sep 15, 2016 10:57 am

Re: Reading Smart Water sensor values for Waspmote v12

Post by josemaria » Fri Jul 28, 2017 9:12 am

Hi!

Firstly, thanks for your support. I followed your instructions. Within my conditions of versions I commented you, the following code would be the correct? Thank you. Regards.

#include <WaspXBee802.h>
#include <WaspFrame.h>
#include <WaspSensorSW.h>

float value_pH;
float value_temp;
float value_pH_calculated;
float value_orp;
float value_orp_calculated;
float value_di;
float value_do;
float value_do_calculated;
float value_cond;
float value_cond_calculated;

// Calibration values
#define cal_point_10 1.985
#define cal_point_7 2.070
#define cal_point_4 2.227
// Temperature at which calibration was carried out
#define cal_temp 23.7
// Offset obtained from sensor calibration
#define calibration_offset 0.0
// Calibration of the sensor in normal air
#define air_calibration 2.65
// Calibration of the sensor under 0% solution
#define zero_calibration 0.0
// Value 1 used to calibrate the sensor
#define point1_cond 10500
// Value 2 used to calibrate the sensor
#define point2_cond 40000
// Point 1 of the calibration
#define point1_cal 197.00
// Point 2 of the calibration
#define point2_cal 150.00

// PAN (Personal Area Network) Identifier
uint8_t panID[2] = {0x12,0x34};

// Define Freq Channel to be set:
// Center Frequency = 2.405 + (CH - 11d) * 5 MHz
// Range: 0x0B - 0x1A (XBee)
// Range: 0x0C - 0x17 (XBee-PRO)
uint8_t channel = 0x0F;

// Define the Encryption mode: 1 (enabled) or 0 (disabled)
uint8_t encryptionMode = 0;

// Define the AES 16-byte Encryption Key
char encryptionKey[] = "WaspmoteLinkKey!";

// Define BROADCAST MAC address
//////////////////////////////////////////
char RX_ADDRESS[] = "000000000000FFFF";
//////////////////////////////////////////

// Define the Waspmote ID
char WASPMOTE_ID[] = "SW_3";

// define variable
uint8_t error;
uint8_t value_battery;

pHClass pHSensor;
ORPClass ORPSensor;
DIClass DISensor;
DOClass DOSensor;
conductivityClass ConductivitySensor;
pt1000Class TemperatureSensor;

void setup()
{
// open USB port
USB.ON();

USB.println(F("-------------------------------"));
USB.println(F("Configuration XBee 802.15.4"));
USB.println(F("-------------------------------"));

// init XBee
xbee802.ON();

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

/////////////////////////////////////
// 1. set channel
/////////////////////////////////////
xbee802.setChannel( channel );

// check at commmand execution flag
if( xbee802.error_AT == 0 )
{
USB.print(F("1. Channel set OK to: 0x"));
USB.printHex( xbee802.channel );
USB.println();
}
else
{
USB.println(F("1. Error calling 'setChannel()'"));
}


/////////////////////////////////////
// 2. set PANID
/////////////////////////////////////
xbee802.setPAN( panID );

// check the AT commmand execution flag
if( xbee802.error_AT == 0 )
{
USB.print(F("2. PAN ID set OK to: 0x"));
USB.printHex( xbee802.PAN_ID[0] );
USB.printHex( xbee802.PAN_ID[1] );
USB.println();
}
else
{
USB.println(F("2. Error calling 'setPAN()'"));
}

/////////////////////////////////////
// 3. set encryption mode (1:enable; 0:disable)
/////////////////////////////////////
xbee802.setEncryptionMode( encryptionMode );

// check the AT commmand execution flag
if( xbee802.error_AT == 0 )
{
USB.print(F("3. AES encryption configured (1:enabled; 0:disabled):"));
USB.println( xbee802.encryptMode, DEC );
}
else
{
USB.println(F("3. Error calling 'setEncryptionMode()'"));
}

/////////////////////////////////////
// 4. set encryption key
/////////////////////////////////////
xbee802.setLinkKey( encryptionKey );

// check the AT commmand execution flag
if( xbee802.error_AT == 0 )
{
USB.println(F("4. AES encryption key set OK"));
}
else
{
USB.println(F("4. Error calling 'setLinkKey()'"));
}

/////////////////////////////////////
// 5. write values to XBee module memory
/////////////////////////////////////
xbee802.writeValues();

// check the AT commmand execution flag
if( xbee802.error_AT == 0 )
{
USB.println(F("5. Changes stored OK"));
}
else
{
USB.println(F("5. Error calling 'writeValues()'"));
}

// Configure the calibration values
pHSensor.setCalibrationPoints(cal_point_10,
cal_point_7,
cal_point_4,
cal_temp);
DOSensor.setCalibrationPoints(air_calibration, zero_calibration);
ConductivitySensor.setCalibrationPoints(point1_cond,
point1_cal,
point2_cond,
point2_cal);
}

void loop()
{
///////////////////////////////////////////
// 6. Turn on the board
///////////////////////////////////////////

Water.ON();
delay(2000);

///////////////////////////////////////////
// 7. Read sensors
///////////////////////////////////////////

// Read the ph sensor
value_pH = pHSensor.readpH();
// Read the temperature sensor
value_temp = TemperatureSensor.readTemperature();
// Convert the value read with the information obtained in calibration
value_pH_calculated = pHSensor.pHConversion(value_pH,value_temp);
// Reading of the ORP sensor
value_orp = ORPSensor.readORP();
// Apply the calibration offset
value_orp_calculated = value_orp - calibration_offset;
// Reading of the DI sensor
value_di = DISensor.readDI();
// Reading of the ORP sensor
value_do = DOSensor.readDO();
// Conversion from volts into dissolved oxygen percentage
value_do_calculated = DOSensor.DOConversion(value_do);
// Reading of the Conductivity sensor
value_cond = ConductivitySensor.readConductivity();
// Conversion from resistance into ms/cm
value_cond_calculated = ConductivitySensor.conductivityConversion(value_cond);

///////////////////////////////////////////
// 8. Turn off the sensors
///////////////////////////////////////////

Water.OFF();
///////////////////////////////////////////
// 9. Create ASCII frame
///////////////////////////////////////////

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

frame.addSensor(SENSOR_STR, "new_sensor_frame_sent_IEEE_802.15.4");

// Add temperature
frame.addSensor(SENSOR_WT, value_temp);
// Add PH
frame.addSensor(SENSOR_PH, value_pH_calculated);
// Add ORP value
frame.addSensor(SENSOR_ORP, value_orp_calculated);
// Add DO value
frame.addSensor(SENSOR_DO, value_do_calculated);
// Add conductivity value
frame.addSensor(SENSOR_COND, value_cond_calculated);
// Add battery value
value_battery=PWR.getBatteryLevel();
frame.addSensor(SENSOR_BAT, value_battery);

// Show the frame
frame.showFrame();

//wait 2 seconds
delay(2000);

xbee802.ON();

/////////////////////////////////////
// 10. get channel
/////////////////////////////////////
xbee802.getChannel();
USB.print(F("channel: "));
USB.printHex(xbee802.channel);
USB.println();

/////////////////////////////////////
// 11. get PANID
/////////////////////////////////////
xbee802.getPAN();
USB.print(F("pan id: "));
USB.printHex(xbee802.PAN_ID[0]);
USB.printHex(xbee802.PAN_ID[1]);
USB.println();

/////////////////////////////////////
// 12. get encryption mode (1:enable; 0:disable)
/////////////////////////////////////
xbee802.getEncryptionMode();
USB.print(F("encryption mode: "));
USB.printHex(xbee802.encryptMode);
USB.println();

USB.println(F("-------------------------------"));

delay(2000);

///////////////////////////////////////////
// 13. Send packet
///////////////////////////////////////////

// send XBee packet
error = xbee802.send( RX_ADDRESS, frame.buffer, frame.length );

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

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

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

// wait for five seconds
delay(2000);
}

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

Re: Reading Smart Water sensor values for Waspmote v12

Post by libelium-dev » Fri Jul 28, 2017 9:42 am

Hi,

Your code looks good but keep in mind that the maximum payload is 100 bytes. We think that the frames will exceed the maximum payload because just new_sensor_frame_sent_IEEE_802.15.4 take up 35 bytes.
http://www.libelium.com/downloads/docum ... ide.pdf#24

In this case, you can try to send two frames

Code: Select all

//First frame
frame.createFrame(ASCII);
frame.addSensor(SENSOR_STR, "new_sensor_frame_sent_IEEE_802.15.4");
// Add temperature
frame.addSensor(SENSOR_WT, value_temp);
// Add PH
frame.addSensor(SENSOR_PH, value_pH_calculated);
// Show the frame
frame.showFrame();
error = xbee802.send( RX_ADDRESS, frame.buffer, frame.length );

//Second frame
frame.createFrame(ASCII);
// Add ORP value
frame.addSensor(SENSOR_ORP, value_orp_calculated);
// Add DO value
frame.addSensor(SENSOR_DO, value_do_calculated);
// Add conductivity value
frame.addSensor(SENSOR_COND, value_cond_calculated);
// Add battery value
value_battery=PWR.getBatteryLevel();
frame.addSensor(SENSOR_BAT, value_battery);
// Show the frame
frame.showFrame();
error = xbee802.send( RX_ADDRESS, frame.buffer, frame.length );
Regards

josemaria
Posts: 59
Joined: Thu Sep 15, 2016 10:57 am

Re: Reading Smart Water sensor values for Waspmote v12

Post by josemaria » Fri Jul 28, 2017 1:03 pm

Hi!

Thank you.

Regards,

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

Re: Reading Smart Water sensor values for Waspmote v12

Post by libelium-dev » Fri Jul 28, 2017 2:31 pm

You're welcome, Jose Maria!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest