Ag xtr 23: Send commands to weather station
Basic example that turns on and send commands to weather station. Please set DEBUG_XTR to 2 in order to print the answers by the serial monitor. This example permits to set Time and Date in Maximet RTC very easily via USB port. There is an interface which asks the user to introduce the Date and Time as specified without any need to change this code.

Required Materials

- 1 Waspmote Plug & Sense! Smart Agriculture Xtreme - 1 Gill weather station

Notes

- This example is only valid for Waspmote v15

Code

1
/*
2
----------- [Ag_xtr_23] - Send commands to weather station --------------------
3
4
Explanation: Basic example that turns on and send commands to weather
5
station. Please set DEBUG_XTR to 2 in order to print the answers
6
by the serial monitor. This example permits to set Time and Date in Maximet
7
RTC very easily via USB port. There is an interface which asks the user
8
to introduce the Date and Time as specified without any need to change
9
this code.
10
11
Copyright (C) 2018 Libelium Comunicaciones Distribuidas S.L.
12
http://www.libelium.com
13
14
This program is free software: you can redistribute it and/or modify
15
it under the terms of the GNU General Public License as published by
16
the Free Software Foundation, either version 3 of the License, or
17
(at your option) any later version.
18
19
This program is distributed in the hope that it will be useful,
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
GNU General Public License for more details.
23
24
You should have received a copy of the GNU General Public License
25
along with this program. If not, see .
26
27
Version: 3.1
28
Design: David Gascón
29
Implementation: J.Siscart, V.Boria
30
*/
31
32
#include <WaspSensorXtr.h>
33
34
/*
35
SELECT THE RIGHT SOCKET FOR EACH SENSOR.
36
37
Possible sockets for this sensor are:
38
- XTR_SOCKET_E _________
39
|---------|
40
| A B C |
41
|_D__E__F_|
42
43
44
Example: a 5TM sensor on socket A will be
45
[Sensor Class] [Sensor Name] [Selected socket]
46
Decagon_5TM mySensor (XTR_SOCKET_A);
47
48
Refer to the technical guide for information about possible combinations.
49
www.libelium.com/downloads/documentation/smart_agriculture_xtreme_sensor_board.pdf
50
*/
51
52
int year;
53
int month;
54
int day;
55
int hour;
56
int minute;
57
int second;
58
59
// buffer to set the date and time
60
char buffer[100];
61
char input[100];
62
63
// [Sensor Class] [Sensor Name]
64
weatherStation mySensor;
65
66
uint8_t response = 0;
67
68
void setup()
69
{
70
USB.println(F("Weather station example for setting date and time"));
71
USB.println(F("***********"));
72
USB.println(F("Note: Please enable DEBUG_XTR to 2 in WaspSensorXtr.h to see the Maximet answers"));
73
USB.println(F("***********"));
74
75
// Turn ON the sensor
76
mySensor.ON();
77
78
79
/////////////////////////////////
80
// YEAR
81
/////////////////////////////////
82
do
83
{
84
USB.print("Insert year [yy]:");
85
}
86
while( getData(2) != true );
87
88
year=atoi(input);
89
USB.println(year);
90
91
92
/////////////////////////////////
93
// MONTH
94
/////////////////////////////////
95
do
96
{
97
USB.print("Insert month [mm]:");
98
}
99
while( getData(2) != true );
100
101
month=atoi(input);
102
USB.println(month);
103
104
105
/////////////////////////////////
106
// DAY
107
/////////////////////////////////
108
do
109
{
110
USB.print("Insert day [dd]:");
111
}
112
while( getData(2) != true );
113
114
day=atoi(input);
115
USB.println(day);
116
117
118
/////////////////////////////////
119
// HOUR
120
/////////////////////////////////
121
do
122
{
123
USB.print("Insert Hour [HH]:");
124
}
125
while( getData(2) != true );
126
127
hour=atoi(input);
128
USB.println(hour);
129
130
/////////////////////////////////
131
// MINUTE
132
/////////////////////////////////
133
do
134
{
135
USB.print("Insert minute [MM]:");
136
}
137
while( getData(2) != true );
138
139
minute=atoi(input);
140
USB.println(minute);
141
142
/////////////////////////////////
143
// SECOND
144
/////////////////////////////////
145
do
146
{
147
USB.print("Insert second [SS]:");
148
}
149
while( getData(2) != true );
150
151
second=atoi(input);
152
USB.println(second);
153
154
155
/////////////////////////////////
156
// create buffer
157
/////////////////////////////////
158
sprintf(buffer, "TIME 20%02u-%02u-%02uT%02u:%02u:%02u",
159
year,
160
month,
161
day,
162
hour,
163
minute,
164
second );
165
USB.println(buffer);
166
167
168
mySensor.sendCommand(buffer);
169
delay(5000);
170
171
172
173
}
174
175
void loop()
176
{
177
178
mySensor.sendCommand("TIME");
179
delay(1000);
180
181
}
182
183
184
185
186
/*********************************
187
*
188
* get numBytes from USB port
189
*
190
**********************************/
191
boolean getData(int numBytes)
192
{
193
memset(input, 0x00, sizeof(input) );
194
int i=0;
195
USB.flush();
196
int nRead=0;
197
198
while(!USB.available());
199
200
while(USB.available()>0)
201
{
202
input[i]=USB.read();
203
204
if( (input[i]=='r') && (input[i]=='n') )
205
{
206
input[i]='';
207
}
208
else
209
{
210
i++;
211
}
212
}
213
214
nRead=i;
215
216
if(nRead != numBytes)
217
{
218
USB.print(F("must write "));
219
USB.print(numBytes, DEC);
220
USB.print(F(" characters. Read "));
221
USB.print(nRead, DEC);
222
USB.println(F(" bytes"));
223
return false;
224
}
225
else
226
{
227
input[i]='';
228
return true;
229
}
230
231
}
Copied!

Output

1
I#
2
Weather station example for setting date and time
3
***********
4
Note: Please enable DEBUG_XTR to 2 in WaspSensorXtr.h to see the Maximet answers
5
***********
6
WS RX:
7
MAXIMET GMX541-3B-0003 2669 V2.00.14
8
STARTUP: OK
9
NODE,DIR,SPEED,CDIR,AVGDIR,AVGSPEED,GDIR,GSPEED,AVGCDIR,WINDSTAT,PRECIPT,PRECIPI,PRECIPS,COMPASSH,PRESS,PASL,PSTN,RH,TEMP,DEWPOINT,AH,SOLARRAD,SOLARHOURS,WCHILL,HEATIDX,AIRDENS,WBTEMP,SUNR,SNOON,SUNS,SUNP,TWIC,TWIN,TWIA,XTILT,YTILT,ZORIENT,TIME,VOLT,STATUS,CHECK
10
-,DEG,MS,DEG,DEG,MS,DEG,MS,DEG,-,MM,MM/H,-,DEG,HPA,HPA,HPA,%,C,C,G/M3,WM2,HRS,C,C,KG/M3,C,-,-,-,DEG,-,-,-,DEG,DEG,-,-,V,-,-
11
[XTR] GMX541 found
12
Insert year [yy]:18
13
Insert month [mm]:11
14
Insert day [dd]:13
15
Insert Hour [HH]:13
16
Insert minute [MM]:31
17
Insert second [SS]:30
18
TIME 2018-11-13T13:31:30
19
WS TX:*
20
WS RX:
21
SETUP MODE
22
>WS TX:TIME 2018-11-13T13:31:30
Copied!
Last modified 1yr ago