Development

Combined / Sensors + Radio:

» C 08: Sending smart parking values via 868

This example reads the status of a parking lot using the parking sensor board and sends its status via XBee 868.

Required Materials

1 x Waspmote
1 x Battery
1 x Coin battery
1 x Smart parking board
2 x XBee 868 module
1 x SD card

Notes

Socket 0 will be used to connect 868 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_08] - Sending smart parking values via 868 -------- 
 *  
 *  Explanation: This example reads the status of a parking lot using 
 *  the parking sensor board and sends its status via XBee 868.
 *  
 *  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 <WaspXBee868.h>
#include <WaspFrame.h>
#include <WaspSensorParking.h>

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

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

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

// Sensor variables
int temperature;
boolean status;

// define variable
uint8_t error;

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

  ////////////////////////////////////////////////
  // 1. Initial message composition
  ////////////////////////////////////////////////
  
  // 1.1 Set mote Identifier (16-Byte max)
  frame.setID(NODE_ID);	
  
  // 1.2 Set frame maximum size (Link encryp disabled, AES encryp disabled)
  frame.setFrameSize(XBEE_868, DISABLED, DISABLED);
  USB.print(F("\nframe size (XBee868, UNICAST_64B, XBee encryp Disabled, AES encryp Disabled):"));
  USB.println(frame.getFrameSize(),DEC);   
  
  // 1.3 Create new frame
  frame.createFrame(ASCII);  

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

  // 1.5 Print frame
  frame.showFrame();


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

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


  if( error == 0 ) 
  {
    USB.println(F("ok"));
  }
  else 
  {
    USB.println(F("error"));
  }

  // 2.3 Communication module to OFF
  xbee868.OFF();
  delay(100);
  
  
  ////////////////////////////////////////////////
  // 3. Parking calibration process
  ////////////////////////////////////////////////

  // Once "start calibration" command is received, calibration starts. 
  SensorParking.loadReference();
  SensorParking.ON();
  delay(100);
  SensorParking.calibration();  
  SensorParking.OFF();


}

void loop()
{

  ////////////////////////////////////////////////
  // 4. Measure corresponding values
  ////////////////////////////////////////////////
  USB.println(F("Measuring sensors..."));

  // 4.1 Turn on the sensor board
  SensorParking.setBoardMode(SENS_ON);
  delay(10);
  
  // 4.2 Prepare parking sensor
  SensorParking.readParkingSetReset();
  
  // 4.3 Read parking temperature
  temperature = SensorParking.readTemperature();
  
  // 4.4 calculate reference for status stimation
  SensorParking.calculateReference(temperature);
  
  // 4.5 Estimate parking lot status
  status = SensorParking.estimateState();

  // 4.6 Turn OFF parking sensor board.
  SensorParking.setBoardMode(SENS_OFF);

  // 4.7 Set RTC on and get time
  RTC.ON();
  RTC.getTime();

  ////////////////////////////////////////////////
  // 5. Message composition
  ////////////////////////////////////////////////

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

  // 5.2 Add frame fields
  frame.addSensor(SENSOR_PS, status);
  frame.addSensor(SENSOR_MF, SensorParking.valueX, SensorParking.valueY, SensorParking.valueZ);
  frame.addSensor(SENSOR_TIME, RTC.hour, RTC.minute, RTC.second );  
  frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel() );
  
  // 5.3 Print frame
  // Example: <=>€#35689722#N01#3#PS:1#MF:969;300;282#TIME:13-53-37#BAT:63#
  frame.showFrame();


  ////////////////////////////////////////////////
  // 6. Send message
  ////////////////////////////////////////////////

  // 6.1 Power XBee
  xbee868.ON();

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

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

  // 6.4 Communication module to OFF
  xbee868.OFF();
  delay(100);


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

Output

B#
C_08 Example

frame size (XBee868, UNICAST_64B, XBee encryp Disabled, AES encryp Disabled):100
===============================
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 30 38 20 45 78 61 6D 70 6C 65 23
String: <=>€#35689864#N01#0#STR:C_08 Example#
===============================
ok
Measuring sensors...
===============================
Current ASCII Frame:
Length: 59
Frame Type (decimal): 128
HEX: 3C 3D 3E 80 04 23 33 35 36 38 39 38 36 34 23 4E 30 31 23 31 23 50 53 3A 31 23 4D 46 3A 31 33 32 3B 31 33 38 3B 31 36 30 23 54 49 4D 45 3A 31 2D 30 2D 32 23 42 41 54 3A 31 33 23
String: <=>€#35689864#N01#1#PS:1#MF:132;138;160#TIME:1-0-2#BAT:13#
===============================
ok
Going to sleep...

Quick Publish: