Development

Mote Runner:

Sensor Boards / Events

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-Ev 01: Socket 7 Reading with PIR Sensor

In this example we turn on the Events Board v20 and read the value from the PIR sensor, placed on socket 7, printing a message when received.

Required Materials

1 x Waspmote PRO
1 x Battery
1 x MiniUSB wire
1 x Events Sensor Board
1 x PIR Sensor

Notes

* Remember to turn on the manual switch for socket 7 in the Events 2.0 Sensor Board
* Remember to connect the battery to Waspmote for proper operation.
* The connection of the sensor is described in the Events technical guide.
* Logger, Common and Events 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=pir-1.0 --system=waspmote --ref=logger-#.# --ref=/common-1.0 --ref=/events-1.0 PIRExample.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 and Ignacio Ruiz Martín
 */

package com.libelium.examples.events;


import com.ibm.saguaro.logger.Logger;
import com.ibm.saguaro.system.Float;
import com.ibm.saguaro.system.GPIO;
import com.ibm.saguaro.system.Mote;
import com.ibm.saguaro.system.Time;
import com.ibm.saguaro.system.Timer;
import com.ibm.saguaro.system.TimerEvent;
import com.ibm.saguaro.system.csr;
import com.libelium.common.Constants;
import com.libelium.common.Gpio;
import com.libelium.events.Events;

public class PIRExample {
	static Timer timer;
	static Events events = new Events();
	static GPIO gpio = Gpio.getInstance();
	
	static{

		events.ON();
		
		timer = new Timer();
		
		timer.setCallback(new TimerEvent(null){
        		public void invoke(byte param, long time){
        			PIRExample.timeCallback(param,time);
        		}
        	});
	
        long INTERVAL = Time.toTickSpan(Time.MILLISECS,1000);
    	timer.setAlarmBySpan(INTERVAL);
    	
	}
	
	protected static void timeCallback(byte param, long time) {
		long presence = events.readValue(Constants.SENS_SOCKET7);
		
		Logger.appendString(csr.s2b("PIR measurement (0 = no presence, 1 = presence detected): "));
		Logger.appendHexLong(Float.toLong(presence, (byte)0));
		Logger.flush(Mote.INFO);
		
	}
}

Output

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: PIR measurement (0 = no presence, 1 = presence detected): 1

Quick Publish: