Frame 06: Set Frame Type

This example shows how to set the frame Type. This field is included inside the frame's header in order to distinguish between different sort of frames

Required Materials

1 x Waspmote 1 x Battery 1 x MiniUSB wire

Notes

This example can be executed in Waspmote v12 and Waspmote v15

Code

/*  
 *  ------ FRAME_06 - set Frame Type -------- 
 *  
 *  Explanation: This example shows how to set the frame Type. This field
 *  is included inside the frame's header in order to distinguish between
 *  different sort of frames
 *
 *  Copyright (C) 2016 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:           3.0
 *  Design:            David Gascón 
 *  Implementation:    Yuri Carmona
 */

#include <WaspFrame.h>

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

  
void setup()
{
  // Init USB port & Accelerometer
  USB.ON();    
  USB.println(F("FRAME_06 example")); 
  
  // set the Waspmote ID
  frame.setID(moteID);  
}


void loop()
{
  /////////////////////////////////////////////
  // 1. create a TIMEOUT frame type
  /////////////////////////////////////////////
  
  // Create new frame (ASCII)
  frame.createFrame(ASCII);
 
  // set frame type 
  frame.setFrameType(TIMEOUT_FRAME);

  // Prints frame
  frame.showFrame();
  
  delay(500);
  
  
  /////////////////////////////////////////////
  // 2. create a EVENT frame type
  /////////////////////////////////////////////
  
  // Create new frame (ASCII)
  frame.createFrame(ASCII);
 
  // set frame type 
  frame.setFrameType(EVENT_FRAME);

  // Prints frame
  frame.showFrame();
  
  delay(500);  
  
    
  /////////////////////////////////////////////
  // 3. create a ALARM frame type
  /////////////////////////////////////////////
  
  // Create new frame (ASCII)
  frame.createFrame(ASCII);
 
  // set frame type 
  frame.setFrameType(ALARM_FRAME);

  // Prints frame
  frame.showFrame();
  
  delay(500);
    
    
  /////////////////////////////////////////////
  // 4. create a SERVICE1 frame type
  /////////////////////////////////////////////
  
  // Create new frame (ASCII)
  frame.createFrame(ASCII);
 
  // set frame type 
  frame.setFrameType(SERVICE1_FRAME);

  // Prints frame
  frame.showFrame();
  
  delay(500);
  
    
    
  /////////////////////////////////////////////
  // 5. create a SERVICE2 frame type
  /////////////////////////////////////////////
  
  // Create new frame (ASCII)
  frame.createFrame(ASCII);
 
  // set frame type 
  frame.setFrameType(SERVICE2_FRAME);

  // Prints frame
  frame.showFrame();
  
  delay(500);

  USB.println(F("\n\n\n"));

  delay(5000);
}

Output

H#
FRAME_06 example
===============================
Current ASCII Frame:
Length: 26
Frame Type (decimal): 129
Number of fields: 0
HEX: 3C 3D 3E 81 00 23 33 38 37 32 32 37 31 35 34 23 6E 6F 64 65 5F 30 31 23 30 23
String: <=> #387227154#node_01#0#
===============================
===============================
Current ASCII Frame:
Length: 26
Frame Type (decimal): 130
Number of fields: 0
HEX: 3C 3D 3E 82 00 23 33 38 37 32 32 37 31 35 34 23 6E 6F 64 65 5F 30 31 23 31 23
String: <=>‚

Last updated