Development

Mote Runner:

Mote Runner / Agriculture

This is the development section of the Waspmote Mote Runner platform. You can navigate through the examples with the left bar.

If you actually want to see examples about the original Waspmote platform, please go its specific development section.

» MR-Ag 06: Digital Humidity Sensor Reading

In this example the Agriculture 2.0 sensor board is turned on and the humidity sensor 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 Digital Temperature and Humidity sensor (Sensirion SHT75)

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 sensirion 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=sens-1.0 --system=waspmote --ref=logger-#.# --ref=/common-1.0 --ref=/agriculture-1.0 SensirionExample.java

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, Diego López Pérez and Ignacio Ruiz Martín
 */

package com.libelium.examples.agriculture;


import com.libelium.common.Callback;
import com.libelium.agriculture.*;
import com.ibm.saguaro.system.Float;
import com.ibm.saguaro.system.*;
import com.libelium.common.Constants;
import com.libelium.common.Gpio;
import com.ibm.saguaro.logger.Logger;

public class SensirionExample {
	static Timer timer;
	static Agriculture agr = new Agriculture();
	static GPIO gpio = Gpio.getInstance();
	
	static{
		agr.ON();
		agr.setSensorMode(Constants.SENS_ON, Constants.SENS_AGR_SENSIRION);

		timer = new Timer();
		
		timer.setCallback(new TimerEvent(null){
    		public void invoke(byte param, long time){
    			SensirionExample.timeCallback(param,time);
    		}
        });
	}
	
	protected static void timeCallback(byte param, long time) {
		agr.readSensirion(Constants.SENSIRION_HUM,new Callback(null) {
			@Override
			public int invoke(byte[] buf, int len) {
				return SensirionExample.callbackSensirion(buf,len);
			}
		});
		long INTERVAL = Time.toTickSpan(Time.MILLISECS,1000);
		timer.setAlarmBySpan(INTERVAL);
	}
	
	private static int callbackSensirion(byte[] buf, int len){
		Logger.appendString(csr.s2b("Sensirion temperature measurement: "));
		
		long result = Util.get32(buf, 0);
		Logger.appendHexLong(Float.toLong(result, (byte)2));
		Logger.flush(Mote.INFO);
		
		return 0;
	}
}

Output

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: Humidity measurement: 000009C4

Quick Publish: