» MR-Ag 12: Vane sensor reading
In this example the Agriculture 2.0 sensor board is turned on and the vane read every second approximately, printing the result through the USB port.
Required Materials
1 x Waspmote
1 x Battery
1 x Agriculture 2.0 board or Agriculture PRO 2.0 board
1 x Weather Station
Notes
* Remember to connect the battery to Waspmote for proper operation.
* The connection of the sensor is described in the Agriculture 2.0 technical guide.
* When turning on the vane sensor you will be powering all the low consumption group sensors. See the Agriculture 2.0 board technical guide for more information.
* Logger, Common and Agriculture assemblies must be loaded in the mote.
* Please note that the output is in hexadecimal.
* Please note that Float.toLong() method has been used with a precission of 2 decimals. For example, a 3413 output in decimal base means 34.13. For more information of Float class, see http://localhost:5000/gac/saguaro-system-11.3.htm?fqn=r:com.ibm.saguaro.system.Float
* To compile this example: mrc --assembly=vane-1.0 --system=waspmote --ref=logger-#.# --ref=
Code
/**
* Copyright (C) 2013 Libelium Comunicaciones Distribuidas S.L.
* http://www.libelium.com
*
* This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public License
* (LGPL) version 3.0 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl-3.0.html
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Design: David Gascón
*
* @version 0.1
* @author Anartz Nuin Jiménez and Ignacio Ruiz Martín
*/
package com.libelium.examples.agriculture;
import com.ibm.saguaro.system.*;
import com.libelium.agriculture.*;
import com.libelium.common.Constants;
import com.libelium.common.Gpio;
import com.ibm.saguaro.logger.Logger;
public class VaneExample {
static Timer timer;
static Agriculture agr = new Agriculture();
static GPIO gpio = Gpio.getInstance();
static{
agr.ON();
agr.setSensorMode(Constants.SENS_ON, Constants.SENS_AGR_VANE);
timer = new Timer();
timer.setCallback(new TimerEvent(null){
public void invoke(byte param, long time){
VaneExample.timeCallback(param,time);
}
});
long INTERVAL = Time.toTickSpan(Time.MILLISECS,1000);
timer.setAlarmBySpan(INTERVAL);
}
protected static void timeCallback(byte param, long time) {
long vane = agr.readValue(Constants.SENS_AGR_VANE);
byte[] string = null;
switch((int)vane){
case Constants.SENS_AGR_VANE_N : string=csr.s2b("N");
break;
case Constants.SENS_AGR_VANE_NNE : string=csr.s2b("NNE");;
break;
case Constants.SENS_AGR_VANE_NE : string=csr.s2b("NE");
break;
case Constants.SENS_AGR_VANE_ENE : string=csr.s2b("ENE");
break;
case Constants.SENS_AGR_VANE_E : string=csr.s2b("E");
break;
case Constants.SENS_AGR_VANE_ESE : string=csr.s2b("ESE");
break;
case Constants.SENS_AGR_VANE_SE : string=csr.s2b("SE");
break;
case Constants.SENS_AGR_VANE_SSE : string=csr.s2b("SSE");
break;
case Constants.SENS_AGR_VANE_S : string=csr.s2b("S");
break;
case Constants.SENS_AGR_VANE_SSW : string=csr.s2b("SSW");
break;
case Constants.SENS_AGR_VANE_SW : string=csr.s2b("SW");
break;
case Constants.SENS_AGR_VANE_WSW : string=csr.s2b("WSW");
break;
case Constants.SENS_AGR_VANE_W : string=csr.s2b("W");
break;
case Constants.SENS_AGR_VANE_WNW : string=csr.s2b("WNW");
break;
case Constants.SENS_AGR_VANE_NW : string=csr.s2b("WN");
break;
case Constants.SENS_AGR_VANE_NNW : string=csr.s2b("NNW");
break;
}
Logger.appendString(csr.s2b("Vane measuremet: "));
Logger.appendString(string);
Logger.flush(Mote.INFO);
long INTERVAL = Time.toTickSpan(Time.MILLISECS,1000);
timer.setAlarmBySpan(INTERVAL);
}
}
Output
category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Vane measurement: NNE