Development

General / Frame:

» Frame 02: ASCII multiple

This example creates an ASCII frame with a multiple-field sensor value (GPS in this case) and shows it.

Required Materials

1 x Waspmote PRO
1 x Battery
1 x MiniUSB wire

Code

/*  
 *  ------ FRAME_02_ascii_multiple - WaspFrame Ascii multiple -------- 
 *  
 *  Explanation: This example Creates an ASCII frame with a 
 *  multiple-field sensor data 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";

// hypothetical GPS values
float latitude  = 1.4465431234;
float longitude = -0.8842734321;


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

void loop()
{
  // Create new frame (ASCII)
  frame.createFrame(ASCII); 

  // set frame fields (multiple)
  frame.addSensor(SENSOR_ACC, (int) ACC.getX(), (int) ACC.getY(), (int) ACC.getZ());
  
  // set frame fields (multiple)
  frame.addSensor(SENSOR_GPS, latitude, longitude);
  
  // Print frame
  frame.showFrame();
  delay(5000);
}

Output

E#
===============================
Current ASCII Frame:
Length: 65
Frame Type (decimal): 128
Number of fields: 2
HEX: 3C 3D 3E 80 02 23 33 38 37 32 32 37 31 35 34 23 6E 6F 64 65 5F 30 31 23 30 23 41 43 43 3A 31 30 3B 2D 36 30 3B 31 30 33 31 23 47 50 53 3A 31 2E 34 34 36 35 34 33 3B 2D 30 2E 38 38 34 32 37 33 23
String: <=>€#387227154#node_01#0#ACC:10;-60;1031#GPS:1.446543;-0.884273#
===============================
===============================
Current ASCII Frame:
Length: 64
Frame Type (decimal): 128
Number of fields: 2
HEX: 3C 3D 3E 80 02 23 33 38 37 32 32 37 31 35 34 23 6E 6F 64 65 5F 30 31 23 31 23 41 43 43 3A 39 3B 2D 37 32 3B 31 30 32 31 23 47 50 53 3A 31 2E 34 34 36 35 34 33 3B 2D 30 2E 38 38 34 32 37 33 23
String: <=>€#387227154#node_01#1#ACC:9;-72;1021#GPS:1.446543;-0.884273#
===============================

Quick Publish: