Development v12

Warning - Product Update

All the resources present on this section belong to Waspmote v12, Waspmote Plug & Sense! v12 and Meshlium v3.8.

If you have a Waspmote v15, Waspmote Plug & Sense! v15 or Meshlium v4.0 please go to the new Development Section.

Check what is your version and what are the differences between the old and the new one in this document.

» C 16: Sending basic values via 802.15.4

This example sends Waspmote basic sensors values (Temperature, humidity and luminosity) via XBee module with 802.15.4 protocol

Required Materials

1 x Waspmote
1 x Battery
1 x Coin battery
1 x 802.15.4 XBee module
1 x Temperature sensor
1 x Humidity sensor
1 x Luminosity sensor
1 x SD card

Notes

Socket 0 will be used to connect Xbee 802.15.4 module.
It is recommended to set RTC time to your actual time.
Never unplug modules or sensor boards while Waspmote is ON.
The battery must be connected in ANY example.

Code

/*  
 *  ------ [C_16] - Sending basic values via 802.15.4 -------- 
 *  
 *  Explanation:  This example sends Waspmote basic sensors values 
 *  via XBee module with 802.15.4 protocol
 *
 *
 *  
 *  Copyright (C) 2015 Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details. 
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 *  
 *  Version:           0.2 
 *  Design:            David Gascón 
 *  Implementation:    Javier Siscart
 */

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

// Node identifier
char NODE_ID[]="N01";

// Destination MAC address
char MAC_ADDRESS[]="0013A20040B4DCDB";

// Sleeping time DD:hh:mm:ss
char sleepTime[] = "00:00:01:00";    

// Sensor variables
float temperature = 0.0;
float light = 0;
float humidity = 0;

// define variable
uint8_t error;

void setup()
{
  // 0. Init USB port for debugging
  USB.ON();
  USB.println(F("C_16 Example"));


  ////////////////////////////////////////////////
  // 1. Initial message composition
  ////////////////////////////////////////////////

  // 1.1 Set mote Identifier (16-Byte max)
  frame.setID(NODE_ID);	

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

  // 1.3 Set frame fields (String - char*)
  frame.addSensor(SENSOR_STR, (char*) "C_16 Example");

  // 1.4 Print frame
  frame.showFrame();


  ////////////////////////////////////////////////
  // 2. Send initial message
  ////////////////////////////////////////////////

  // 2.1 Switch on the XBee module
  xbee802.ON();  

  // 2.2 Set destination XBee parameters to packet
  error = xbee802.send( MAC_ADDRESS, frame.buffer, frame.length );

  // 2.3 Check TX flag
  if( error == 0 ) 
  {
    USB.println(F("ok"));
  }
  else 
  {
    USB.println(F("error"));
  }

  // 2.4 Communication module to OFF
  xbee802.OFF();
  delay(100);
  
  // 2.5 set up RTC 
  RTC.ON();
  
}
 
void loop()
{
   ////////////////////////////////////////////////
  // 3. Measure corresponding values
  ////////////////////////////////////////////////
  USB.println(F("Measuring sensors..."));

  temperature = Utils.readTemperature();
  humidity = Utils.readHumidity();
  light = Utils.readLight();  
  RTC.getTime();


  ////////////////////////////////////////////////
  // 4. Message composition
  ////////////////////////////////////////////////

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

  // 4.2 Add frame fields
  frame.addSensor(SENSOR_TCA, temperature);
  frame.addSensor(SENSOR_HUMA, humidity);
  frame.addSensor(SENSOR_LUM, light);
  frame.addSensor(SENSOR_TIME, RTC.hour, RTC.minute, RTC.second );
  frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel());
  
  // 4.3 Print frame
  // Example: <=>€#35689391#N01#1#TCA:20.64#HUMA:39.0#LUM:75.000#TIME:16-17-16#BAT:52#
  frame.showFrame();


  ////////////////////////////////////////////////
  // 5. Send message
  ////////////////////////////////////////////////

  // 5.1 Switch on the XBee module
  xbee802.ON();  

  // 5.2 Set destination XBee parameters to packet
  error = xbee802.send( MAC_ADDRESS, frame.buffer, frame.length );

  // 5.3 Check TX flag
  if( error == 0 ) 
  {
    USB.println(F("ok"));
  }
  else 
  {
    USB.println(F("error"));
  }

  // 5.4 Communication module to OFF 
  xbee802.OFF();

  ////////////////////////////////////////////////
  // 6. Entering Deep Sleep mode
  ////////////////////////////////////////////////
  USB.ON();
  USB.println(F("Going to sleep..."));
  
  PWR.deepSleep(sleepTime, RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
 
  USB.ON();
  RTC.ON();
  USB.println(F("wake"));
  
}

Output

****************************************************
Waspmote output
****************************************************
B#
C_16 Example
===============================
Current ASCII Frame:
Length: 38
Frame Type (decimal): 128
HEX: 3C 3D 3E 80 01 23 33 35 36 38 39 38 36 34 23 4E 30 31 23 30 23 53 54 52 3A 43 5F 31 36 20 45 78 61 6D 70 6C 65 23
String: <=>€#35689864#N01#0#STR:C_16 Example#
===============================
ok
Measuring sensors...
===============================
Current ASCII Frame:
Length: 73
Frame Type (decimal): 128
HEX: 3C 3D 3E 80 05 23 33 35 36 38 39 38 36 34 23 4E 30 31 23 31 23 54 43 41 3A 2D 33 33 2E 35 34 23 48 55 4D 41 3A 31 33 2E 30 23 4C 55 4D 3A 31 36 2E 30 30 30 23 54 49 4D 45 3A 31 2D 32 32 2D 31 33 23 42 41 54 3A 31 36 23
String: <=>#35689391#N01#1#TCA:24.19#HUMA:36.0#LUM:77.000#TIME:0-50-39#BAT:60#
===============================
ok
Going to sleep...

****************************************************
Gateway output
****************************************************
<=>#35689391#N01#0#STR:C_16 Example#
<=>#35689391#N01#1#TCA:24.19#HUMA:36.0#LUM:77.000#TIME:0-50-39#BAT:60#
<=>#35689391#N01#2#TCA:23.22#HUMA:35.0#LUM:74.000#TIME:0-51-55#BAT:56#
<=>#35689391#N01#3#TCA:22.90#HUMA:35.0#LUM:76.000#TIME:0-53-12#BAT:53#

Quick Publish: