Development

General / Frame:

» Frame 01: ASCII simple

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

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_01_ascii_simple - WaspFrame Ascii simple -------- 
 *  
 *  Explanation: This example Creates a simple ASCII frame and shows it. 
 *  
 *  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:    Joaquín Ruiz, Yuri Carmona
 */ 
 
#include <WaspFrame.h>
  
// define the Waspmote ID 
char moteID[] = "node_01";


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

void loop()
{
  USB.println(F("Creating an ASCII frame"));

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

  // set frame fields (String - char*)
  frame.addSensor(SENSOR_STR, "this_is_a_string");
  // set frame fields (Battery sensor - uint8_t)
  frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel());

  // Prints frame
  frame.showFrame();
  
  // Wait for five seconds
  delay(5000);
  
}

Output

H#
Start program
Creating an ASCII frame
===============================
Current ASCII Frame:
Length: 61
Frame Type: 134
frame (HEX): 3C3D3E86022334443343373036334439333734324634236E6F64655F30312330235354523A746869735F69735F615F737472696E67234241543A393623
frame (STR): <=>�#4D3C7063D93742F4#node_01#0#STR:this_is_a_string#BAT:96#
===============================

Quick Publish: