Code examples and extended information
In the Waspmote Development section you can find complete examples:
Example:
1
#include <WaspXBee900HP.h>
2
#include <WaspFrame.h>
3
// Destination MAC address
4
//////////////////////////////////////////
5
char RX_ADDRESS[] =0013A20040A63E21”;
6
//////////////////////////////////////////
7
// Define the Waspmote ID
8
char WASPMOTE_ID[] = “node_01”;
9
// define variable
10
uint8_t error;
11
void setup()
12
{
13
// init USB port
14
USB.ON();
15
USB.println(F(“Sending packets example”));
16
// store Waspmote identifier in EEPROM memory
17
frame.setID( WASPMOTE_ID );
18
// init XBee
19
xbee900HP.ON();
20
}
21
void loop()
22
{
23
///////////////////////////////////////////
24
// 1. Create ASCII frame
25
///////////////////////////////////////////
26
// create new frame
27
frame.createFrame(ASCII);
28
29
// add frame fields
30
frame.addSensor(SENSOR_STR, “new_sensor_frame”);
31
frame.addSensor(SENSOR_BAT, PWR.getBatteryLevel());
32
33
// show frame to send
34
frame.showFrame();
35
///////////////////////////////////////////
36
// 2. Send packet
37
///////////////////////////////////////////
38
// send XBee packet
39
error = xbee900HP.send( RX_ADDRESS, frame.buffer, frame.length );
40
41
// check TX flag
42
if( error == 0 )
43
{
44
USB.println(F(“send ok”));
45
}
46
else
47
{
48
USB.println(F(“send error”));
49
}
50
51
// wait for five seconds
52
delay(5000);
53
}
Copied!
Last modified 1yr ago
Copy link