Ag xtr 19: frame class utility
This is the basic code to create frames with all sensors used in the Agriculture Board v30

Required Materials

- 1 Waspmote Plug & Sense! Smart Agriculture Xtreme - several Smart Agriculture Xtreme sensors

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
----------- [Ag_xtr_20] - Frame class utility --------------------
3
4
Explanation: This is the basic code to create a frame with some
5
Smart Agriculture Xtreme sensors.
6
7
Measured parameters:
8
- Multiple
9
10
Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L.
11
http://www.libelium.com
12
13
This program is free software: you can redistribute it and/or modify
14
it under the terms of the GNU General Public License as published by
15
the Free Software Foundation, either version 3 of the License, or
16
(at your option) any later version.
17
18
This program is distributed in the hope that it will be useful,
19
but WITHOUT ANY WARRANTY; without even the implied warranty of
20
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
GNU General Public License for more details.
22
23
You should have received a copy of the GNU General Public License
24
along with this program. If not, see .
25
26
Version: 3.1
27
Design: David Gascón
28
Implementation: J.Siscart, V.Boria
29
*/
30
31
#include <WaspSensorXtr.h>
32
#include <WaspFrame.h>
33
34
//Uncomment the next line if the GMX includes GPS
35
//#define GMX_GPS_OPTION
36
37
38
char node_ID[] = "Node_01";
39
40
//[Sensor Class] [Sensor Name] [Selected socket]
41
bme myBME280_A(XTR_SOCKET_A);
42
leafWetness myPhytos31_B;
43
Decagon_5TE my5TE_C(XTR_SOCKET_C);
44
luxes myTSL2561_D(XTR_SOCKET_D);
45
weatherStation myGMX240_E;
46
Apogee_SP510 mySP510_F(XTR_SOCKET_F);
47
48
49
void setup()
50
{
51
USB.println(F("Frame utility example for Smart Agriculture Xtreme"));
52
53
// set the Plug & Sense! node ID
54
frame.setID(node_ID);
55
56
// Weather station is turned ON on setup() and is not turned OFF
57
myGMX240_E.ON();
58
}
59
60
void loop()
61
{
62
///////////////////////////////////////////
63
// 1. Read the sensors
64
///////////////////////////////////////////
65
66
// Socket A sensor
67
// Turn ON the sensor
68
myBME280_A.ON();
69
// Read the sensor. Store parameters in variables
70
float temperature_A = myBME280_A.getTemperature();
71
float humidity_A = myBME280_A.getHumidity();
72
float pressure_A = myBME280_A.getPressure();
73
// Turn off the sensor
74
myBME280_A.OFF();
75
76
// Socket B sensor
77
// Turn ON the sensor
78
myPhytos31_B.ON();
79
// Read the sensor
80
myPhytos31_B.read();
81
// Turn off the sensor
82
myPhytos31_B.OFF();
83
84
// Socket C sensor
85
// Turn ON the sensor
86
my5TE_C.ON();
87
// Read the sensor
88
my5TE_C.read();
89
// Turn off the sensor
90
my5TE_C.OFF();
91
92
// Socket D sensor
93
// Turn ON the sensor
94
myTSL2561_D.ON();
95
// Read the sensor. Store parameter in variable
96
uint32_t luminosity_D = myTSL2561_D.getLuminosity();
97
// Turn off the sensor
98
myTSL2561_D.OFF();
99
100
// Socket E sensor
101
// Read the sensor
102
myGMX240_E.read();
103
104
// Socket F sensor
105
// Turn ON the sensor and the heater and wait some time
106
mySP510_F.ON();
107
delay(10000);
108
// Read the sensor
109
mySP510_F.read();
110
// Turn off the sensor and the heater
111
mySP510_F.OFF();
112
113
114
///////////////////////////////////////////
115
// 2. Create ASCII frame
116
///////////////////////////////////////////
117
118
// Create new frame (ASCII)
119
frame.createFrame(ASCII);
120
121
// It is mandatory to specify the Smart Agriculture Xtreme type
122
frame.setFrameType(INFORMATION_FRAME_AGR_XTR);
123
124
// add Socket A sensor values
125
frame.addSensor(AGRX_TC_A, temperature_A);
126
frame.addSensor(AGRX_HUM_A, humidity_A);
127
frame.addSensor(AGRX_PRES_A, pressure_A);
128
129
// add Socket B sensor values
130
frame.addSensor(AGRX_LW, myPhytos31_B.wetness);
131
132
// add Socket C sensor values
133
frame.addSensor(AGRX_5TE_DP2_C, my5TE_C.sensor5TE.dielectricPermittivity);
134
frame.addSensor(AGRX_5TE_EC2_C, my5TE_C.sensor5TE.electricalConductivity);
135
frame.addSensor(AGRX_5TE_TC4_C, my5TE_C.sensor5TE.temperature);
136
137
// add Socket D sensor values
138
frame.addSensor(AGRX_LUXES_D, luminosity_D);
139
140
// add Socket E sensor values
141
frame.addSensor(AGRX_GMX_AWD, myGMX240_E.gmx.avgWindDirection);
142
frame.addSensor(AGRX_GMX_AWS, myGMX240_E.gmx.avgWindSpeed);
143
frame.addSensor(AGRX_GMX_PI, myGMX240_E.gmx.precipIntensity);
144
frame.addSensor(AGRX_GMX_PT, myGMX240_E.gmx.precipTotal);
145
146
// add Socket F sensor values
147
frame.addSensor(AGRX_SR_F, mySP510_F.radiation);
148
149
// Show the frame
150
frame.showFrame();
151
152
153
///////////////////////////////////////////
154
// 3. Sleep
155
///////////////////////////////////////////
156
157
// Go to deepsleep
158
// After 30 seconds, Waspmote wakes up thanks to the RTC Alarm
159
PWR.deepSleep("00:00:00:30", RTC_OFFSET, RTC_ALM1_MODE1, ALL_OFF);
160
161
}
Copied!

Output

1
H#
2
Frame utility example for Smart Agriculture Xtreme
3
===============================
4
Current ASCII Frame:
5
Length: 178
6
Frame Type: 135
7
frame (HEX): 3C3D3E870D2330423541373836334439333734324446234E6F64655F303123302354435F413A2D313030302E30302348554D5F413A2D313030302E3023505245535F413A2D313030302E3030234C573A312E34393834234450325F433A302E3030234543325F433A302E3030235443345F433A302E30234C55585F443A34323934393637323935234157443A30234157533A302E30302350493A302E30302350543A302E30302353525F463A32362E333123
8
frame (STR): <=>�
9
#0B5A7863D93742DF#Node_01#0#TC_A:27.24#HUM_A:46.2#PRES_A:98942.52#LW:0.0184#DP2_C:0.15#EC2_C:5.12#TC4_C:26.5#LUX_D:95#AWD:0#AWS:0.00#PI:0.00#PT:0.00#SR_F:26.31#
10
===============================
Copied!
Last modified 1yr ago