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

Required Materials

1 x Waspmote 1 x Agriculture Board v30 Several Agriculture v30 sensors

Notes

-This example is only valid for Waspmote v15

Code

1
/*
2
* ------------ [Ag_v30_11] - Frame Class Utility --------------
3
*
4
* Explanation: This is the basic code to create frames with all sensors
5
* used in the Agriculture Board v30
6
*
7
* Copyright (C) 2016 Libelium Comunicaciones Distribuidas S.L.
8
* http://www.libelium.com
9
*
10
* This program is free software: you can redistribute it and/or modify
11
* it under the terms of the GNU General Public License as published by
12
* the Free Software Foundation, either version 3 of the License, or
13
* (at your option) any later version.
14
*
15
* This program is distributed in the hope that it will be useful,
16
* but WITHOUT ANY WARRANTY; without even the implied warranty of
17
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18
* GNU General Public License for more details.
19
*
20
* You should have received a copy of the GNU General Public License
21
* along with this program. If not, see <http://www.gnu.org/licenses/>.
22
*
23
* Version: 3.0
24
* Design: David Gascón
25
* Implementation: Carlos Bello
26
*/
27
28
#include <WaspSensorAgr_v30.h>
29
#include <BME280.h>
30
#include <WaspFrame.h>
31
32
char node_ID[] = "Node_01";
33
34
//Instace sensor object
35
leafWetnessClass lwSensor;
36
radiationClass radSensor;
37
dendrometerClass dendSensor;
38
pt1000Class pt1000Sensor;
39
watermarkClass wmSensor1(SOCKET_1);
40
watermarkClass wmSensor2(SOCKET_2);
41
watermarkClass wmSensor3(SOCKET_3);
42
weatherStationClass weather;
43
44
//variables to store sensors readings
45
float temperature;
46
float humidity;
47
float pressure;
48
uint8_t wetness;
49
float UVvalue;
50
float radiation;
51
float dendrometer;
52
float pt1000Temperature;
53
float watermark1;
54
float watermark2;
55
float watermark3;
56
float anemometer;
57
float pluviometer1;
58
float pluviometer2;
59
float pluviometer3;
60
uint8_t vane;
61
62
// variable to store the number of pending pulses
63
int pendingPulses;
64
65
void setup()
66
{
67
USB.ON();
68
USB.println(F("Start program"));
69
70
// Turn on the sensor board
71
Agriculture.ON();
72
73
// Set the Waspmote ID
74
frame.setID(node_ID);
75
}
76
77
void loop()
78
{
79
/////////////////////////////////////////////
80
// 1. Enter sleep mode
81
/////////////////////////////////////////////
82
Agriculture.sleepAgr("00:00:00:10", RTC_ABSOLUTE, RTC_ALM1_MODE5, SENSOR_ON, SENS_AGR_PLUVIOMETER);
83
84
/////////////////////////////////////////////
85
// 2. Check interruptions
86
/////////////////////////////////////////////
87
//Check pluviometer interruption
88
if( intFlag & PLV_INT)
89
{
90
USB.println(F("+++ PLV interruption +++"));
91
92
pendingPulses = intArray[PLV_POS];
93
94
USB.print(F("Number of pending pulses:"));
95
USB.println( pendingPulses );
96
97
for(int i=0 ; i<pendingPulses; i++)
98
{
99
// Enter pulse information inside class structure
100
weather.storePulse();
101
102
// decrease number of pulses
103
intArray[PLV_POS]--;
104
}
105
106
// Clear flag
107
intFlag &= ~(PLV_INT);
108
}
109
110
//Check RTC interruption
111
if(intFlag & RTC_INT)
112
{
113
USB.println(F("+++ RTC interruption +++"));
114
115
// switch on sensor board
116
Agriculture.ON();
117
USB.print(F("Time:"));
118
USB.println(RTC.getTime());
119
120
// measure sensors
121
measureSensors();
122
123
// Clear flag
124
intFlag &= ~(RTC_INT);
125
}
126
}
127
128
void measureSensors()
129
{
130
131
///////////////////////////////////////////
132
// 3. Read sensors
133
///////////////////////////////////////////
134
135
//It takes several minutes to read all sensors
136
137
// Read the temperature sensor
138
temperature = Agriculture.getTemperature();
139
// Read the humidity sensor
140
humidity = Agriculture.getHumidity();
141
// Read the pressure sensor
142
pressure = Agriculture.getPressure();
143
// Read the leaf wetness sensor
144
wetness = lwSensor.getLeafWetness();
145
// Read the ultraviolet sensor
146
UVvalue = radSensor.readRadiation();
147
// Conversion from voltage into umol·m-2·s-1
148
radiation = UVvalue / 0.0002;
149
// Read the dendrometer sensor
150
dendrometer = dendSensor.readDendrometer();
151
// Read the PT1000 sensor
152
pt1000Temperature = pt1000Sensor.readPT1000();
153
// Read the watermark 1 sensor
154
watermark1 = wmSensor1.readWatermark();
155
// Read the watermark 2 sensor
156
watermark2 = wmSensor2.readWatermark();
157
// Read the watermark 3 sensor
158
watermark3 = wmSensor3.readWatermark();
159
// Read the anemometer sensor
160
anemometer = weather.readAnemometer();
161
// Read the pluviometer sensor
162
pluviometer1 = weather.readPluviometerCurrent();
163
pluviometer2 = weather.readPluviometerHour();
164
pluviometer3 = weather.readPluviometerDay();
165
// Read the vane sensor
166
vane = weather.readVaneDirection();
167
168
///////////////////////////////////////////
169
// 4. Create ASCII frame
170
///////////////////////////////////////////
171
172
// Create new frame (ASCII)
173
frame.createFrame(ASCII);
174
// Add temperature
175
frame.addSensor(SENSOR_AGR_TC, temperature);
176
// Add humidity
177
frame.addSensor(SENSOR_AGR_HUM, humidity);
178
// Add pressure
179
frame.addSensor(SENSOR_AGR_PRES, pressure);
180
// Add wetness
181
frame.addSensor(SENSOR_AGR_LW, wetness);
182
// Add radiation
183
frame.addSensor(SENSOR_AGR_PAR, radiation);
184
// Add dendrometer
185
frame.addSensor(SENSOR_AGR_TD, dendrometer);
186
// Add PT1000
187
frame.addSensor(SENSOR_AGR_SOILTC, pt1000Temperature);
188
// Add watermark 1
189
frame.addSensor(SENSOR_AGR_SOIL1, watermark1);
190
// Add watermark 1
191
frame.addSensor(SENSOR_AGR_SOIL2, watermark2);
192
// Add watermark 1
193
frame.addSensor(SENSOR_AGR_SOIL3, watermark3);
194
// Add pluviometer value
195
frame.addSensor( SENSOR_AGR_PLV1, pluviometer1 );
196
// Add pluviometer value
197
frame.addSensor( SENSOR_AGR_PLV2, pluviometer2 );
198
// Add pluviometer value
199
frame.addSensor( SENSOR_AGR_PLV3, pluviometer3 );
200
// Add anemometer value
201
frame.addSensor( SENSOR_AGR_ANE, anemometer );
202
// Add pluviometer value
203
frame.addSensor( SENSOR_AGR_WV, vane );
204
205
// Show the frame
206
frame.showFrame();
207
208
// wait 2 seconds
209
delay(2000);
210
}
Copied!

Output

1
H#
2
Start program
3
+++ PLV interruption +++
4
Number of pending pulses:1
5
+++ RTC interruption +++
6
Time:Wed, 16/11/02, 13:20:10
7
===============================
8
Current ASCII Frame:
9
Length: 147
10
Frame Type: 134
11
frame (HEX): 3C3D3E860C2336383235373036334439333734323037234E6F64655F303123302354433A32332E38372348554D3A34322E313423505245533A39393632312E38352E3436234C573A3132235041523A33392E38322354443A342E35343223534F494C54433A32302E313423534F494C313A36302E343123534F494C323A35362E343723534F494C333A35312E303423504C56313A302E303023504C56323A302E303023
12
frame (STR): <=> #68257063D9374207#Node_01#0#TC:23.87#HUM:42.14#PRES:99621.85.46#LW:12#PAR:39.82#TD:4.542#SOILTC:20.14#SOIL1:60.41#SOIL2:56.47#SOIL3:51.04#PLV1:0.00#PLV2:0.00#
13
===============================
Copied!
Last modified 1yr ago