Ag v30 08: Weather station
Turn on the Agriculture v30 board and read the Weather station every minute. Every time a new pluviometer pulse is generated the interrruption is captured and stored

Required Materials

1 x Waspmote 1 x Agriculture Board v30 1 x Weather station

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
* --[Ag_v30_08] - Weather Station sensor reading
3
*
4
* Explanation: Turn on the Agriculture v30 board and read the
5
* Weather station every minute. Every time a new pluviometer
6
* pulse is generated the interrruption is captured and stored
7
*
8
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
9
* http://www.libelium.com
10
*
11
* This program is free software: you can redistribute it and/or modify
12
* it under the terms of the GNU General Public License as published by
13
* the Free Software Foundation, either version 3 of the License, or
14
* (at your option) any later version.
15
*
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
20
*
21
* You should have received a copy of the GNU General Public License
22
* along with this program. If not, see <http://www.gnu.org/licenses/>.
23
*
24
* Version: 3.0
25
* Design: David Gascón
26
* Implementation: Carlos Bello
27
*/
28
29
#include <WaspSensorAgr_v30.h>
30
31
// Variable to store the anemometer value
32
float anemometer;
33
34
// Variable to store the pluviometer value
35
float pluviometer1; //mm in current hour
36
float pluviometer2; //mm in previous hour
37
float pluviometer3; //mm in last 24 hours
38
39
// Variable to store the vane value
40
int vane;
41
42
// variable to store the number of pending pulses
43
int pendingPulses;
44
45
// define node identifier
46
char nodeID[] = "node_WS";
47
48
//Instance object
49
weatherStationClass weather;
50
51
void setup()
52
{
53
// Turn on the USB and print a start message
54
USB.ON();
55
USB.println(F("Start program"));
56
57
// Turn on the sensor board
58
Agriculture.ON();
59
60
USB.print(F("Time:"));
61
RTC.ON();
62
USB.println(RTC.getTime());
63
64
}
65
66
void loop()
67
{
68
/////////////////////////////////////////////
69
// 1. Enter sleep mode
70
/////////////////////////////////////////////
71
Agriculture.sleepAgr("00:00:00:10", RTC_ABSOLUTE, RTC_ALM1_MODE5, SENSOR_ON, SENS_AGR_PLUVIOMETER);
72
73
/////////////////////////////////////////////
74
// 2.1. check pluviometer interruption
75
/////////////////////////////////////////////
76
if( intFlag & PLV_INT)
77
{
78
USB.println(F("+++ PLV interruption +++"));
79
80
pendingPulses = intArray[PLV_POS];
81
82
USB.print(F("Number of pending pulses:"));
83
USB.println( pendingPulses );
84
85
for(int i=0 ; i<pendingPulses; i++)
86
{
87
// Enter pulse information inside class structure
88
weather.storePulse();
89
90
// decrease number of pulses
91
intArray[PLV_POS]--;
92
}
93
// Clear flag
94
intFlag &= ~(PLV_INT);
95
}
96
97
/////////////////////////////////////////////
98
// 2.2. check RTC interruption
99
/////////////////////////////////////////////
100
if(intFlag & RTC_INT)
101
{
102
USB.println(F("+++ RTC interruption +++"));
103
104
// switch on sensor board
105
Agriculture.ON();
106
107
RTC.ON();
108
USB.print(F("Time:"));
109
USB.println(RTC.getTime());
110
111
// measure sensors
112
measureSensors();
113
114
// Clear flag
115
intFlag &= ~(RTC_INT);
116
}
117
}
118
119
120
/*******************************************************************
121
*
122
* measureSensors
123
*
124
* This function reads from the sensors of the Weather Station and
125
* then creates a new Waspmote Frame with the sensor fields in order
126
* to prepare this information to be sent
127
*
128
*******************************************************************/
129
void measureSensors()
130
{
131
132
USB.println(F("------------- Measurement process ------------------"));
133
134
/////////////////////////////////////////////////////
135
// 1. Reading sensors
136
/////////////////////////////////////////////////////
137
138
// Read the anemometer sensor
139
anemometer = weather.readAnemometer();
140
141
// Read the pluviometer sensor
142
pluviometer1 = weather.readPluviometerCurrent();
143
pluviometer2 = weather.readPluviometerHour();
144
pluviometer3 = weather.readPluviometerDay();
145
146
/////////////////////////////////////////////////////
147
// 2. USB: Print the weather values through the USB
148
/////////////////////////////////////////////////////
149
150
// Print the accumulated rainfall
151
USB.print(F("Current hour accumulated rainfall (mm/h): "));
152
USB.println( pluviometer1 );
153
154
// Print the accumulated rainfall
155
USB.print(F("Previous hour accumulated rainfall (mm/h): "));
156
USB.println( pluviometer2 );
157
158
// Print the accumulated rainfall
159
USB.print(F("Last 24h accumulated rainfall (mm/day): "));
160
USB.println( pluviometer3 );
161
162
// Print the anemometer value
163
USB.print(F("Anemometer: "));
164
USB.print(anemometer);
165
USB.println(F("km/h"));
166
167
// Print the vane value
168
char vane_str[10] = {0};
169
switch(weather.readVaneDirection())
170
{
171
case SENS_AGR_VANE_N : snprintf( vane_str, sizeof(vane_str), "N" );
172
break;
173
case SENS_AGR_VANE_NNE : snprintf( vane_str, sizeof(vane_str), "NNE" );
174
break;
175
case SENS_AGR_VANE_NE : snprintf( vane_str, sizeof(vane_str), "NE" );
176
break;
177
case SENS_AGR_VANE_ENE : snprintf( vane_str, sizeof(vane_str), "ENE" );
178
break;
179
case SENS_AGR_VANE_E : snprintf( vane_str, sizeof(vane_str), "E" );
180
break;
181
case SENS_AGR_VANE_ESE : snprintf( vane_str, sizeof(vane_str), "ESE" );
182
break;
183
case SENS_AGR_VANE_SE : snprintf( vane_str, sizeof(vane_str), "SE" );
184
break;
185
case SENS_AGR_VANE_SSE : snprintf( vane_str, sizeof(vane_str), "SSE" );
186
break;
187
case SENS_AGR_VANE_S : snprintf( vane_str, sizeof(vane_str), "S" );
188
break;
189
case SENS_AGR_VANE_SSW : snprintf( vane_str, sizeof(vane_str), "SSW" );
190
break;
191
case SENS_AGR_VANE_SW : snprintf( vane_str, sizeof(vane_str), "SW" );
192
break;
193
case SENS_AGR_VANE_WSW : snprintf( vane_str, sizeof(vane_str), "WSW" );
194
break;
195
case SENS_AGR_VANE_W : snprintf( vane_str, sizeof(vane_str), "W" );
196
break;
197
case SENS_AGR_VANE_WNW : snprintf( vane_str, sizeof(vane_str), "WNW" );
198
break;
199
case SENS_AGR_VANE_NW : snprintf( vane_str, sizeof(vane_str), "WN" );
200
break;
201
case SENS_AGR_VANE_NNW : snprintf( vane_str, sizeof(vane_str), "NNW" );
202
break;
203
default : snprintf( vane_str, sizeof(vane_str), "error" );
204
break;
205
}
206
207
USB.println( vane_str );
208
USB.println(F("----------------------------------------------------\n"));
209
}
Copied!

Output

1
H#
2
Start program
3
Time:Sun, 00/01/01, 20:23:25
4
+++ PLV interruption +++
5
Number of pending pulses:1
6
+++ PLV interruption +++
7
Number of pending pulses:1
8
+++ PLV interruption +++
9
Number of pending pulses:1
10
+++ PLV interruption +++
11
Number of pending pulses:1
12
+++ PLV interruption +++
13
Number of pending pulses:1
14
+++ PLV interruption +++
15
Number of pending pulses:2
16
+++ PLV interruption +++
17
Number of pending pulses:3
18
+++ PLV interruption +++
19
Number of pending pulses:3
20
+++ PLV interruption +++
21
Number of pending pulses:2
22
+++ RTC interruption +++
23
Time:Sun, 00/01/01, 20:24:10
24
------------- Measurement process ------------------
25
Current hour accumulated rainfall (mm/h): 4.1909999847
26
Previous hour accumulated rainfall (mm/h): 0.0000000000
27
Last 24h accumulated rainfall (mm/day): 0.0000000000
28
Anemometer: 13.6000013351km/h
29
S
30
----------------------------------------------------
31
...
Copied!
Last modified 1yr ago