Development

Mote Runner:

Mote Runner / 6LoWPAN

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-6LowPAN 01: Reply

This example reply to the sender with the same information it receives. Detailed information can be found on the Mote Runner folder: /examples/mrv6

Required Materials

2 x Waspmote PRO
1 x Ethernet Shield
1 x Expansion Board
2 x Battery
1 x Ethernet cable

Code

namespace com.ibm.saguaro.gateway.generic {
    using com.ibm.saguaro.system;
    using com.ibm.saguaro.mrv6;
    using com.ibm.saguaro.util;

    /// <summary>
    /// Main class and socket
    /// </summary>
    public class ReplySocket : UDPSocket {
        /// <summary>Port that socket binds to </summary>
        internal static uint LOCAL_PORT = 1024;

        /// <summary>Singleton instance </summary>
        internal static ReplySocket socket = new ReplySocket();

        /// <summary>Class to blink LED </summary>
        //internal LEDControl ledctrl;

        /// <summary>Constructor </summary>
        public ReplySocket() {
            //ledctrl = new LEDControl(2);
            this.bind(LOCAL_PORT);
        }

        /// <summary>Receive packet </summary>
        public override int onPacket(Packet packet) {
            //ledctrl.setState(1, 500);
            LED.setState(2, (byte)(LED.getState(2)^1));

            uint len = packet.payloadLen;
            byte[] buf = (byte[]) Util.alloca((byte) len, Util.BYTE_ARRAY);
            Util.copyData(packet.payloadBuf, packet.payloadOff, buf, 0, len);
            
            try {
                packet.swap(len);
            } catch {
                return 0;
            }
            Util.copyData(buf, 0, packet.payloadBuf, packet.payloadOff, len);
            this.send(packet);
            return 0;
        }


    }
} // namespace

Quick Publish: