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 PRO
1 x Battery
1 x MiniUSB wire

Code

/*  
 *  ------ FRAME_01_ascii_simple - WaspFrame Ascii simple -------- 
 *  
 *  Explanation: This example Creates a simple ASCII 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 & RTC
  USB.ON();    
  RTC.ON();
  
  // 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, (char*) "this_is_a_string");
  // set frame fields (Battery sensor - uint8_t)
  frame.addSensor(SENSOR_BAT, (uint8_t) PWR.getBatteryLevel());
  // set frame fields (Temperature in Celsius sensor - float)
  frame.addSensor(SENSOR_IN_TEMP, (float) RTC.getTemperature());

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

Output

E#
Creating an ASCII frame
===============================
Current ASCII Frame:
Length: 69
Frame Type (decimal): 128
Number of fields: 3
HEX: 3C 3D 3E 80 03 23 33 38 37 32 32 37 31 35 34 23 6E 6F 64 65 5F 30 31 23 30 23 53 54 52 3A 74 68 69 73 5F 69 73 5F 61 5F 73 74 72 69 6E 67 23 42 41 54 3A 31 30 30 23 49 4E 5F 54 45 4D 50 3A 32 39 2E 30 30 23
String: <=>€#387227154#node_01#0#STR:this_is_a_string#BAT:100#IN_TEMP:29.00#
===============================
Creating an ASCII frame
===============================
Current ASCII Frame:
Length: 69
Frame Type (decimal): 128
Number of fields: 3
HEX: 3C 3D 3E 80 03 23 33 38 37 32 32 37 31 35 34 23 6E 6F 64 65 5F 30 31 23 31 23 53 54 52 3A 74 68 69 73 5F 69 73 5F 61 5F 73 74 72 69 6E 67 23 42 41 54 3A 31 30 30 23 49 4E 5F 54 45 4D 50 3A 32 39 2E 30 30 23
String: <=>€#387227154#node_01#1#STR:this_is_a_string#BAT:100#IN_TEMP:29.00#
===============================
Creating an ASCII frame
===============================
Current ASCII Frame:
Length: 69
Frame Type (decimal): 128
Number of fields: 3
HEX: 3C 3D 3E 80 03 23 33 38 37 32 32 37 31 35 34 23 6E 6F 64 65 5F 30 31 23 32 23 53 54 52 3A 74 68 69 73 5F 69 73 5F 61 5F 73 74 72 69 6E 67 23 42 41 54 3A 31 30 30 23 49 4E 5F 54 45 4D 50 3A 32 39 2E 30 30 23
String: <=>€#387227154#node_01#2#STR:this_is_a_string#BAT:100#IN_TEMP:29.00#
===============================

Quick Publish: