Recent Changes - Search:


To send a message you need to provide the payload to send in a comma separated list. The bytes of the the payload can be provided in decimal, hex or binary format using 0xor 0b prefixes.

	// Supported Prefixes are "0x" and "0b", otherwise Base_10 (DEZ) is assumed	
	String[] splitMessage = messageToSend.split(",");
	byte[] messageToSendBytes = new byte[splitMessage.length];
	String messageForOutputInLog = "";
	for (int i=0;i<splitMessage.length;i++) {
		int type = 10;
		if (splitMessage[i].startsWith("0x")) {
			type = 16;
		} else if (splitMessage[i].startsWith("0b")) {
			type = 2;
		BigInteger b = new BigInteger(splitMessage[i], type);
		messageToSendBytes[i] = (byte) b.intValue() ;
		messageForOutputInLog = messageForOutputInLog + b.intValue() +" ";

Then we need to construct a Message and add the payload created above to the message in order to forward it to the devices. The message also needs to contain a timestamp for the sent Time and a source device id.

	// Constructing the Message
	Message binaryMessage = new Message();

	GregorianCalendar c = new GregorianCalendar();


The created Binary message is the forwared to the WSNAsyncWrapper, together with the destination devices, and the timeout threshold for the Request.

	Future sendFuture = wsn.send(nodeURNs, binaryMessage, 10, TimeUnit.SECONDS);

Again the Result of the sent request can be received using the get() method of the Future object returned by the call to the ''WSNAsyncWrapper

	try {
          JobResult sendJobResult = sendFuture.get();
	  sendJobResult.printResults(System.out, csv);
	  System.exit(sendJobResult.getSuccessPercent() < 100 ? 1 : 0);
	} catch (ExecutionException e) {
	  if (e.getCause() instanceof TimeoutException) {"Call timed out. Exiting...");
Edit - History - Print - Recent Changes - Search
Page last modified on November 20, 2012, at 10:19 PM