Development

General / Frame:

» Frame 03: Binary simple

This example creates a BINARY frame with simple data (only one field per sensor value) and shows it.

Required Materials

1 x Waspmote PRO
1 x Battery
1 x MiniUSB wire

Code

/*  
 *  ------ FRAME_03_binary_simple - WaspFrame Binary simple -------- 
 *  
 *  Explanation: This example creates a simple binary frame and shows it. 
 *  
 *  Copyright (C) 2014 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:    Joaquín Ruiz, Yuri Carmona
 */

#include <WaspFrame.h>

// define the Waspmote ID 
char moteID[] = "node_01";

  
void setup()
{
  // Init USB port & Accelerometer
  USB.ON();    
  RTC.ON();
  
  // set the Waspmote ID
  frame.setID(moteID);
}

void loop()
{
  // Create new frame (BINARY)
  frame.createFrame(BINARY);
  
  // set frame fields (single)
  frame.addSensor(SENSOR_STR, (char*) "this_is_a_string");
  frame.addSensor(SENSOR_BAT, (uint8_t) PWR.getBatteryLevel());
  frame.addSensor(SENSOR_IN_TEMP, (float) RTC.getTemperature());

  // Print frame
  frame.showFrame();

  delay(5000);
}

Output

E#
===============================
Current BINARY Frame:
Length: 43
Frame Type (decimal): 0
Number of fields: 3
HEX: 3C 3D 3E 00 26 12 9E 14 17 6E 6F 64 65 5F 30 31 23 00 41 10 74 68 69 73 5F 69 73 5F 61 5F 73 74 72 69 6E 67 34 64 3E 00 00 E8 41
String: <=>&žnode_01#Athis_is_a_string4d>
===============================
===============================
Current BINARY Frame:
Length: 43
Frame Type (decimal): 0
Number of fields: 3
HEX: 3C 3D 3E 00 26 12 9E 14 17 6E 6F 64 65 5F 30 31 23 01 41 10 74 68 69 73 5F 69 73 5F 61 5F 73 74 72 69 6E 67 34 64 3E 00 00 E8 41
String: <=>

Quick Publish: