Ag xtr 15: Weather station sensor reading
Basic example that turns on, reads and turn off the sensor. Measured parameters are stored in the corresponding class variables and printed by the serial monitor.

Required Materials

- 1 Waspmote Plug & Sense! Smart Agriculture Xtreme - 1 GMX240 sensor

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
----------- [Ag_xtr_15] - Weather station sensor reading --------------------
3
4
Explanation: Basic example that turns on, reads and turn off the
5
sensor. Measured parameters are stored in the corresponding class
6
variables and printed by the serial monitor.
7
8
Measured parameters for GMX541 (depends on the model)
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.3
27
Design: David Gascón
28
Implementation: J.Siscart, V.Boria
29
*/
30
31
#include <WaspSensorXtr.h>
32
33
/*
34
SELECT THE RIGHT SOCKET FOR EACH SENSOR.
35
36
Possible sockets for this sensor are:
37
- XTR_SOCKET_E _________
38
|---------|
39
| A B C |
40
|_D__E__F_|
41
42
43
Example: a 5TM sensor on socket A will be
44
[Sensor Class] [Sensor Name] [Selected socket]
45
Decagon_5TM mySensor (XTR_SOCKET_A);
46
47
Refer to the technical guide for information about possible combinations.
48
www.libelium.com/downloads/documentation/smart_agriculture_xtreme_sensor_board.pdf
49
*/
50
51
52
//Uncomment the next line if the GMX includes GPS
53
//#define GMX_GPS_OPTION
54
55
56
// [Sensor Class] [Sensor Name]
57
weatherStation mySensor;
58
59
uint8_t response = 0;
60
61
void setup()
62
{
63
USB.println(F("Weather station example"));
64
65
// 1. Turn ON the sensor
66
mySensor.ON();
67
68
//Recommended waiting time since power on
69
delay(10000);
70
}
71
72
void loop()
73
{
74
75
// 2. Read the sensor
76
response = mySensor.read();
77
78
if (response == 1)
79
{
80
// 4. Print information
81
USB.println(F("---------------------------"));
82
USB.println(F("GMX"));
83
84
USB.print(F("Wind direction: "));
85
USB.print(mySensor.gmx.windDirection);
86
USB.println(F(" degrees"));
87
88
USB.print(F("Avg. wind dir: "));
89
USB.print(mySensor.gmx.avgWindDirection);
90
USB.println(F(" degrees"));
91
92
USB.print(F("Cor. wind dir: "));
93
USB.print(mySensor.gmx.correctedWindDirection);
94
USB.println(F(" degrees"));
95
96
USB.print(F("Avg. cor. wind dir:"));
97
USB.print(mySensor.gmx.avgCorrectedWindDirection);
98
USB.println(F(" degrees"));
99
100
USB.print(F("Avg. wind gust dir: "));
101
USB.print(mySensor.gmx.avgWindGustDirection);
102
USB.println(F(" degrees"));
103
104
USB.print(F("Wind speed: "));
105
USB.printFloat(mySensor.gmx.windSpeed, 2);
106
USB.println(F(" m/s"));
107
108
USB.print(F("Avg. wind speed: "));
109
USB.printFloat(mySensor.gmx.avgWindSpeed, 2);
110
USB.println(F(" m/s"));
111
112
USB.print(F("Avg. wind gust speed:"));
113
USB.printFloat(mySensor.gmx.avgWindGustSpeed, 2);
114
USB.println(F(" m/s"));
115
116
USB.print(F("Wind sensor status: "));
117
USB.println(mySensor.gmx.windSensorStatus);
118
119
USB.print(F("Precip. total: "));
120
USB.printFloat(mySensor.gmx.precipTotal, 3);
121
USB.println(F(" mm"));
122
123
USB.print(F("Precip. int: "));
124
USB.printFloat(mySensor.gmx.precipIntensity, 3);
125
USB.println(F(" mm"));
126
127
USB.print(F("Precip. status: "));
128
USB.println(mySensor.gmx.precipStatus, DEC);
129
130
USB.print(F("Solar radiation: "));
131
USB.print(mySensor.gmx.solarRadiation);
132
USB.println(F(" W/m^2"));
133
134
USB.print(F("Sunshine hours: "));
135
USB.printFloat(mySensor.gmx.sunshineHours, 2);
136
USB.println(F(" hours"));
137
138
USB.print(F("Sunrise: "));
139
USB.print(mySensor.gmx.sunriseTime);
140
USB.println(F(" (h:min)"));
141
142
USB.print(F("Solar noon: "));
143
USB.print(mySensor.gmx.solarNoonTime);
144
USB.println(F(" (h:min)"));
145
146
USB.print(F("Sunset: "));
147
USB.print(mySensor.gmx.sunsetTime);
148
USB.println(F(" (h:min)"));
149
150
USB.print(F("Sun position: "));
151
USB.print(mySensor.gmx.sunPosition);
152
USB.println(F(" (degrees:degrees)"));
153
154
USB.print(F("Twilight civil: "));
155
USB.print(mySensor.gmx.twilightCivil);
156
USB.println(F(" (h:min)"));
157
158
USB.print(F("Twilight nautical: "));
159
USB.print(mySensor.gmx.twilightNautical);
160
USB.println(F(" (h:min)"));
161
162
USB.print(F("Twilight astronomical: "));
163
USB.print(mySensor.gmx.twilightAstronom);
164
USB.println(F(" (h:min)"));
165
166
USB.print(F("Barometric pressure: "));
167
USB.printFloat(mySensor.gmx.pressure, 1);
168
USB.println(F(" hPa"));
169
170
USB.print(F("Pressure at sea level: "));
171
USB.printFloat(mySensor.gmx.pressureSeaLevel, 1);
172
USB.println(F(" hPa"));
173
174
USB.print(F("Pressure at station: "));
175
USB.printFloat(mySensor.gmx.pressureStation, 1);
176
USB.println(F(" hPa"));
177
178
USB.print(F("Relative humidity: "));
179
USB.print(mySensor.gmx.relativeHumidity);
180
USB.println(F(" %"));
181
182
USB.print(F("Air temperature: "));
183
USB.printFloat(mySensor.gmx.temperature, 1);
184
USB.println(F(" Celsius degrees"));
185
186
USB.print(F("Dew point: "));
187
USB.printFloat(mySensor.gmx.dewpoint, 1);
188
USB.println(F(" degrees"));
189
190
USB.print(F("Absolute humidity: "));
191
USB.printFloat(mySensor.gmx.absoluteHumidity, 2);
192
USB.println(F(" g/m^3"));
193
194
USB.print(F("Air density: "));
195
USB.printFloat(mySensor.gmx.airDensity, 1);
196
USB.println(F(" Kg/m^3"));
197
198
USB.print(F("Wet bulb temperature: "));
199
USB.printFloat(mySensor.gmx.wetBulbTemperature, 1);
200
USB.println(F(" Celsius degrees"));
201
202
USB.print(F("Wind chill: "));
203
USB.printFloat(mySensor.gmx.windChill,1);
204
USB.println(F(" Celsius degrees"));
205
206
USB.print(F("Heat index: "));
207
USB.print(mySensor.gmx.heatIndex);
208
USB.println(F(" Celsius degrees"));
209
210
USB.print(F("Compass: "));
211
USB.print(mySensor.gmx.compass);
212
USB.println(F(" degrees"));
213
214
USB.print(F("X tilt: "));
215
USB.printFloat(mySensor.gmx.xTilt, 0);
216
USB.println(F(" degrees"));
217
218
USB.print(F("Y tilt: "));
219
USB.printFloat(mySensor.gmx.yTilt, 0);
220
USB.println(F(" degrees"));
221
222
USB.print(F("Z orient: "));
223
USB.printFloat(mySensor.gmx.zOrient, 0);
224
USB.println();
225
226
USB.print(F("Timestamp: "));
227
USB.println(mySensor.gmx.timestamp);
228
229
USB.print(F("Voltage: "));
230
USB.printFloat(mySensor.gmx.supplyVoltage, 1);
231
USB.println(F(" V"));
232
233
USB.print(F("Status: "));
234
USB.println(mySensor.gmx.status);
235
236
USB.println(F("---------------------------\n"));
237
}
238
else
239
{
240
USB.println(F("Sensor not connected or invalid data"));
241
}
242
243
delay(5000);
244
245
}
Copied!

Output

1
H#
2
Weather station example
3
---------------------------
4
Node letter: Q
5
Wind direction: 61 degrees
6
Avg. wind dir: 0 degrees
7
Cor. wind dir: 208 degrees
8
Avg. cor. wind dir: 0 degrees
9
Avg. wind gust dir: 0 degrees
10
Wind speed: 000.02 m/s
11
Avg. wind speed: 000.00 m/s
12
Avg. wind gust speed: 000.00 m/s
13
Wind sensor status: 0100
14
Precip. total: 00000.000 mm
15
Precip. int: 000.000 mm
16
Precip. status: N
17
Compass: 147
18
X tilt: +00
19
Y tilt: +02
20
Z orient: -1
21
Timestamp: 2015-01-27T05:59:45.5
22
Voltage: 11.8 V
23
Status: 0000
24
---------------------------
Copied!
Last modified 1yr ago