Development

Mote Runner:

General / RTC

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-RTC 01: General RTC Example

This example will show how to configure both alarms and how to set and get Data. It will configure the alarm 1 to be fired every second and inside the routine it will toggle one LED, the alarm 2 will be fired every minute and will toggle the other LED. Also, every second the actual date will be printed through the USB.

Required Materials

1 x Waspmote PRO
1 x MiniUSB wire
1 x Battery

Notes

* Remember to connect the battery to Waspmote for proper operation.
* Logger, Common and RTC assemblies must be loaded in the mote.
* Please note that the output is in hexadecimal.
* To compile this example: mrc --assembly=rtcp-1.0 --system=waspmote --ref=logger-#.# --ref=/common-1.0 --ref=/rtc-1.0 RTCExample.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.rtc;

import com.ibm.saguaro.system.LED;
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.rtc.RTC;
import com.ibm.saguaro.logger.*;
import com.libelium.common.Callback;

public class RTCExample {
	static Timer timer;
	static RTC rtc = RTC.getInstance();
	
	static{
		
		rtc.setDate((byte)10,(byte) 6,(byte) 4, (byte)7,(byte) 2, (byte)3, (byte)50);
		
		rtc.setAlarm1(new Callback(null){

			@Override
			public int invoke(byte[] result, int len) {
				return RTCExample.alarmCallback(result, len);
			}
			
		}, (byte)0,false,(byte) 0,(byte) 0, (byte)0,(byte) 0, (byte)0);
		
		rtc.setAlarm2(new Callback(null){

			@Override
			public int invoke(byte[] result, int len) {
				return RTCExample.alarmCallback2(result, len);
			}
			
		}, (byte)0,false,(byte) 0,(byte) 0, (byte)0,(byte) 1);
		
		
		timer = new Timer();
		
		timer.setCallback(new TimerEvent(null){
        		public void invoke(byte param, long time){
        			RTCExample.timeCallback(param,time);
        		}
        	});
	
        long INTERVAL = Time.toTickSpan(Time.MILLISECS,1000);
    	timer.setAlarmBySpan(INTERVAL);
	}

	protected static void timeCallback(byte param, long time) {
		byte[] date = rtc.getDate();
		
		Logger.appendString(csr.s2b("second: ")); 
		Logger.appendInt(date[0]);
		Logger.appendString(csr.s2b(" minute: ")); 
		Logger.appendInt(date[1]);
		Logger.appendString(csr.s2b(" hour: ")); 
		Logger.appendInt(date[2]);
		Logger.appendString(csr.s2b(" date: ")); 
		Logger.appendInt(date[3]);
		Logger.appendString(csr.s2b(" month: ")); 
		Logger.appendInt(date[4]);
		Logger.appendString(csr.s2b(" year: ")); 
		Logger.appendInt(date[5]);
		Logger.flush(Mote.INFO);
		long INTERVAL = Time.toTickSpan(Time.MILLISECS,1000);
		timer.setAlarmBySpan(INTERVAL);

	}
	
	public static int alarmCallback(byte[] result, int len){
		LED.setState((byte)0,(byte)(LED.getState((byte)0)^1));
		return 0;
	}

	public static int alarmCallback2(byte[] result, int len){
		LED.setState((byte)1,(byte)(LED.getState((byte)1)^1));
		return 0;
	}
}

Output

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: second: 00 minute: 03 hour: 0A date: 1B month: 03 year: 07C8

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: second: 01 minute: 03 hour: 0A date: 1B month: 03 year: 07C8

category: log
evname: MAPP
id: 7d
time: 11:21:10.830'000
severity: 5
module: MAPP
logmsg: MAPP: second: 02 minute: 03 hour: 0A date: 1B month: 03 year: 07C8

Quick Publish: