MESH SDK Reference Manual

Version:1.0, Release:2015/08/01

Summery of MESH SDK

What is MESH SDK?

MESH SDK(Software Development Kit) is an install-free Web application. Using the MESH SDK, you can create your original Software Tag very easily on your Web browser with JavaScript if you are online.

What you can do with the MESH SDK?

You can make your original Software Tags like the following examples by the simple setting and programming with JavaScript on MESH SDK.

Connecting to Web Services

The Software Tag which accesses other Web Services with open Web API.

Connecting to Other Smart Devices

The Software Tag which controls functions of other WiFi controlled smart devices with open Web API.

Logic algorithm

The Software Tag which carries out complicated procedure, operation and flow control on Canvas.

Development method

Overall flow

The development flow of the Software Tag is as follows.
1. Making: Access the MESH SDK with your Web browser and making your original Software Tag.
2. Addition: Add your original Tag to the MESH App on your tablet.
3. Using & Debugging:Execute your original Tag and check if it works well.

In addition, we offer other functions to help development and sharing of your Tag in SDK.

1. Making

What you should do mainly to make your Tag is following three points.

Acquire the Developmemt account. And access to SDK.

Describe outside specifications and the disposal of every function Tags on SDK.

Preservation of the Tag which you made.

For more detail, please check the following steps.

Sign up the developmemt account and access to SDK.

Step 1. Access Top page of MESH SDK

Input “http://meshprj.com/sdk/” into the search window of the browser and search it. Or Click this link “SDK TOP page“.

Step 2. Access a sign in page

Click a button of “Start using the MESH SDK”.

Step 3. Access an account registration page

Click “Create New Account” button.

Step 4. Input an account information

Fill out input columns and Click “Register”.

Step 5. Confirmation and registration of the account information

Confirm that input information does not have a mistake and Click “Register”.

Step 6. Account application completion

You get the registration reception e-mail of to your e-mail address that input. It takes time from the registration reception to registration completion for limit the number of the accounts during closed β period.

Step 7. To activate your Account

You get a registration completion email to your e-mail address when ready for the account. An account is enabled when you access the URL on that email.

Step 8. Access to SDK

Click “Start using the MESH SDK” of the account validation completion page or the SDK Top page.
(You can access SDK if you enter the sign in the information that it was registered. When you do not enter the sign in, it is spurted to a sign in page.)

Describe outside specifications and the disposal of every function Tags on SDK

Step 1. Create a new Tag

Click “Create New Tag” of the upper page. A dialog to describe for the setting of the Tag stands up when you click it.

Step 2. Set the item concerned of outside specifications

Input the outside items about specifications such as an icon, the name of the Tag, description of the Tag, the function of the Tag, the name of the function, and more.
For more information about every item, please refer to “about a setting item“.
In addition, you can change indication / non-indication of the item by clicking “▶︎/ ▼”.

Step 3. Describes a code of every function on SDK by a JavaScript

Describe a code of JavaScript on a necessary part of “Initialize”, “Execute”, “Result” and “Receive”. A tab change is possible by clicking each label. Please refer to “About a Code” for the details about the description of the code.

Save the Tag which you made

Step 1. Save the Tag

Scroll a dialog to the top and Click “Save” button of the header.

Step 2. When you fail in preservation

When the input contents have an error, you cannot save the Tag. Because the text of the error point becomes in the red, please revise it.

2. Addition

What you should do to add a Tag on the MESH application of the tablet is following two points.

Enter the sign in on application

Download the Tag

Please watch below a detailed procedure.

Enter the sign in on application

Step 1. Open the menu by the list of recipes page

Tap a button in the top right corner of the list of recipes page of the application.

Step 2. Open the account management dialog from the menu

Tap “SDK” button in the menu.

Step 3. Sign in

Input a registered account information and Tap “Sign in” button.

Download the Tag

Step 1. Open list of Tags dialog which you developed

Add to a category “Custom” bottom on the list of the Canvas, when you sign in. And there is “+” button within a category, you tap it.

Step 2. Select the Tag to download

Tap the Tag which you want to download, because the Tags which you made are listed.

Step 3. Start to download

Confirm the details and Tap “Add” button

Step 4. Confirm that a Tag was added

When downloading is completed, a new Tag is added to a list of Tags of the Canvas.

3. Using & Debugging

It is following three points to do for using & debugging a Tag on the MESH application of the tablet.

Using on Canvas

Operation check by the log

Reflection of re-edition and editing contents

Please watch below a detailed procedure.

Using on Canvas

Step 1. Use on Canvas by making drag & drop from a list

Carry out the Tag which you made in SDK by making drag & drop from a list to the Canvas, like other Tags.

Step 2. Confirm whether there is an error

Displayed in the mark indicating the error on the icon of the Tag when an error occurs at the time of use.

Operation check by the log

Step 1. Open log dialog

A dialog for log reading stands up, by tapping “Log” button in the Custom category of the list of Tags.

Step 2. Confirm a log

Be output the messages by error and the log command, in real time. Please refer to the log output for the details about the log command.

Reflection of re-edition and editing contents

It is necessary to edit the Tag which you made on SDK again, when you found a bug and when you want to be changed of function. In addition, it is necessary to let editing contents update on the application when you edit it again.

Step 1. Re-edit the Tag on SDK

Re-edit a necessary point by turning on the “Edit” button and opening the dialog for the Tag editing.

Step 2. Open Tag detail dialog

Open Tag detail dialog, by tapping the Tag icon on the list of Canvas.

Step 3. Check for Updates

Confirm whether there is the update that was edited on SDK by tapping “Check for Updates” button. When there is update, open the dialog for update.

Step 4. Update

Update a Tag by tapping “Update” button in the dialog for the update.

Other functions

We offer Export function and Import function as other functions to support development & sharing of the Tag other than the function mentioned above in MESH SDK.

Export function

By the Export function, you can output the Tag which I made as data of JSON.
The procedure is as follows.

Step 1. Open Export dialog

Click “Export” button after opening the editing dialog of the Tag which wants to export on SDK edit dialog.

Step 2. Copy output data

Copy output JSON data and use it.

Import function

By the Import function, you can make a Tag by reading the JSON data of the Tag output by the Export function mentioned above.

The procedure is as follows.

Step 1. Open Import dialog

Click “Import” button after opening an editing dialog with SDK edit dialog.

Step 2. Paste JSON data

Click “Load JSON” button after you input JSON data into an input column.

Step 3. Read data

A dialog to be attention will appear, because import overwrites by the setting of the Tag inputting now. But Import is completed by choosing “OK”. When the JSON data have an error, you fail in Import.

A setting item, A code are detailed

About a setting item

A component and attribute of the Tag

The MESH Tag is constructed in element {Tag, Function}, and one Tag has one or more Function. Tag and Function have an attribute level such as follows each. And they become the setable item in SDK.

Correspondence on attribute level and Canvas UI

Correspondence on each attribute level of the Tag and Canvas UI are as follows.

Setting of the attribute

Set each attribute level of the Tag in an editing dialog of SDK.

About code

Summary

Implement four methods {Initialize, Receive, Execute, Result} which has a function to define the movement of each function.

The summaries of four methods are as follows.

Method Summary
Initialize Use at the time of initialization of Function. Implement it when needed initialization processing for such as the setting of schedulers and the securing of internal variable.
Receive Use when you received a message from an input connector. There are multiple input connectors and implements it when you want to distinguish which you received it from.
Execute Use for Function run time. Usually, Describe procedures for this method.
Result Execute method is completed and Use when I send a message to next Tag from an output connector. There are multiple output connectors and Implements it when you want to choose which connector you output a message from. At default, Output them from all output connectors.

In addition, as the common organization which is available by Software Tag development,

Processing control

Connector control

Task scheduler

The variable, the constant

Library

These are prepared.

Processing control

Control whether you stop processing or continue (whether you use the next method) by the return value of each method. For example, in the case of the following source code, processing continues, and the next method is carried out.

Receive / Execute / Result
return { resultType : "continue" }

I perform the control by a value of “resultType” of the return value. A value of “resultType” includes three following patterns.

resultType Processing control
“continue” Move to the next method. When “resultType” is not appointed explicitly, it is considered that “continue” was appointed as a default value.
“stop” Do not move to the next method.
“pause” Do not move to the next method. Use this when you wait for a specific condition being met, for example you wait for a response of async such as Web API to come back.

Connector control

When there are multiple input connectors of Function, you distinguish which connector it was input by and can change the processing. It is stored which input connector you received a message in, in the constant “index” which you can refer to in “Receive” method.

The sample source codes to refer to input connector ID are as follows.

Receive]
if ( index == 0 ) {     //input from the first connector
    log( "message from #0" );
}

When there are multiple output connectors of Function, usually a message is output after practice completion of Function by all output connectors, but you can choose connectors to output.
The setting appoints connector ID sequence as “indexes” in a return value in “Result” method.
The sample source codes to set output connector ID are as follows.

Result
return {
    indexes : [0, 1],   //Output from the first connector and the second one
    resultType : "continue"
}

Task scheduler

Task scheduler can carry out a timer in Function when you set a task scheduler. You perform the setting by appointing “taskConfig” object in the return value of the Initialize method.
In the case of follows, Function is carried out every 100 seconds.

Initialize
return {
    resultType : "pause",
    taskConfig : {
        mode : "interval",
        seconds : 100
    }
}

The setting pattern of “taskConfig” is as follows.

Setting pattern Example
Carry it out at regular intervals.
taskConfig : {  //Carry it out every ten seconds
			    mode : "interval",
			    seconds : 10
			} 
Carry it out on the date and the time you appointed it
taskConfig : {  //It is carried out every day at 12:29.
			    mode : "every_day",
			    hours : 12,
			    minutes : 29
				} 
Carried out every day at the time I appointed it.
taskConfig : {  //It is carried out on 5:27pm, July 31, 2015
			    mode : "date",
			    year : 2015,
			    month : 7,
			    day : 31,
			    hours : 17,
			    minutes : 27,
			    seconds : 00
			} 

The variable and the constant

The variable and the constant that you can access from a method of Function, are prepared for. The variable and the constant are the following kind.

the constant: properties

It is a setting parameter of Function. You can refer to a value set from a source code by a user.


The reference is as follows.

Initialize / Receive / Execute / Result
var count = properties.myProp

The constant : index (Only a “Receive” method is accessible)

When there are multiple input connectors of Function, it is a value to show what number connector you received it in.

The reference is as follows.

Receive
if ( index == 0 ) {     //Input from the first connector
    log( "message from #0" );
}
Variables : runtimeValues

It is the variable that you can share between methods in same Function. Assume the use as the state variable of Function mainly. You perform the initialization of the variable in “Initialize” method.
You appoint it as runtimeValues object in a return value as follows.

Initialize
return {
    runtimeValues : { count : 0 }   //Define the variable called "count" and Initialize it.
}

Carry out the access to a variable by refer and update to runtimeValues object in each method.
But you appoint runtimeValues object as a return value of the methods by all means when you updated it.
Update is not reflected when you forget it.

Execute
runtimeValues.count++;
if ( runtimeValues.count == properties.Limit ) {
    runtimeValues.count = 0;
    return {
        resultType : "continue",        //Continue processing
        runtimeValues : runtimeValues   //Return it as "runtimeValues"
    };
} else {
    return {
        resultType : "pause",           //Stop processing
        runtimeValues : runtimeValues   //Return it as "runtimeValues"
    }
}
Variables : messageValues

Refer and update to the data of message. That data is sent from the origin of connection to the connections on Canvas.

The access to a variable refer and update to messageValues object in each method.But please appoint messageValues object as a return value of the methods by all means when you update it.
Update is not reflected when you forget designation.

The example of source code on the message transmission side Tag as follows.

Execute
var msgVal = {};
msgVal.date = new Date();   //Add information (e.g. The practice date and time ) to a message

return {
    messageValues : msgVal, //Return it as "message Values".
    resultType : "continue"
}

The example of source code on the message reception side Tag is as follows.

Execute
var date = messageValues.date;

Library

In SDK, we push forward the maintenance of the function that is available for the common use by Software Tag development. At present, we prepare for two following functions.

Ajax

It is a sync HTTP communication facility. The main parameter that we can appoint is based on ajax method of jQuery basically as follows.

Parameter Details
url URL that you want to access
data Data object which wants to transmit to URL
type Kind of HTTP communication { GET / POST }
contentType Value of the content-type header to use when you send data to a server
dataType The data type that is given back by a server {xml / html / script / json / jsonp / text}
timeout Time before making time-out (millisecond)
beforeSend Event handler that is called back before the request transmission
success Event handler that is called back when communication succeeds
error Event handler that is called back when communication fails

When you want to wait for a reply for, please appoint resultType:”pause” in the return value of the method. Because the Ajax is asynchronous communication.
The sample source codes of the weather check (please refer to “Weather forecast Tag” for the details) using weather forecast Web Service (OpenWeatherMap service) are as follows.

Execute
//The API which gets daily weather forecast
var apiURL = "http://api.openweathermap.org/data/2.5/forecast/daily";

//The parameter of the API
//Pass the value of the property
var data = {
	"q" : properties.location,
	"cnt" : 1,
	"APPID" : '1111111111' //Please replace it with the App ID you get
};

ajax ({
	url : apiURL,
	data : data,
	type : "get",
	timeout : 5000,
	success : function ( contents ) {
		//Validate the contents
		if ( !contents.list || !contents.list[ 0 ] || !contents.list[ 0 ].weather || !contents.list[ 0 ].weather[ 0 ] || !contents.list[ 0 ].weather[ 0 ].id ) {
			log("Weather : Invalid data");
			runtimeValues.outputIndex = -1;
			callbackSuccess( {
				resultType : "continue",
				runtimeValues : runtimeValues
			} );
		}

		//Extract the ID part indicating the weather and convert it to the number value
		var idNum = contents.list[ 0 ].weather[ 0 ].id + 0;

		//Change the value of "outputIndex" depending on the weather
		if ( ( 200 <= idNum && idNum <= 531 ) || ( 600 <= idNum && idNum <= 622 ) ) { //Rainy
			runtimeValues.outputIndex = 2;
		} else if ( 701 <= idNum && idNum <= 781 ) { //Cloudy
			runtimeValues.outputIndex = 1;
		} else if ( 800 <= idNum && idNum <= 802 ) { //Sunny
			runtimeValues.outputIndex = 0;
		} else {
			runtimeValues.outputIndex = 1;
		}
		
		callbackSuccess( {
			resultType : "continue",
			runtimeValues : runtimeValues
		} );
	},
	error : function ( request, errorMessage ) {
		log("Weather : Network error");
		runtimeValues.outputIndex = -1;
		callbackSuccess( {
			resultType : "continue",
			runtimeValues : runtimeValues
		} );
	}
});

return {
	resultType : "pause"
};

Sample

Summary

Introduce following three kinds, as a sample of the Software Tag which you can make in SDK.

- Example of an other apparatuses cooperation : Camera Tag

- Example of an other services cooperation : Weather forecast Tag

- Example of a software logic: Random Tag

Please be careful to use it after having observed Terms of Use of each API on this occasion.

In addition, you confirm about the setting contents except the source code, by importing the JSON data (Camera Tag, Weather forecast Tag, Random Tag) of individual Tags.

Camera Tag

Camera Tag is a Software Tag to control a supporting camera from MESH, using Sony Camera Remote API beta. In this example, Implement a Tag with "TakePicture" Function that takes a picture in simple. When you use this Tag, on network connection by iPad and camera supporting Camera Remote API beta, please use it.

In addition, you are necessary to appoint ActionListURL (e.g. http://192.168.122.1:10000/sony) as Property. Please use it after having checked ActionListURL of the supporting camera.

Camera Tag: code

"TakePicture" Function

The source codes of "TakePicture" Function are as follows.

Initialize
/*** No Initialize Codes ***/

Receive
/*** No Receive Codes ***/

Execute
//The endpoint URL of Remote API
var endPointURL = properties.actionListURL + "/camera";

//The JSON data which puts the camera into "Shooting mode"
var setShootModeJSONData = {
    method : "setShootMode",
    params : ["still"],
    id : 1,
    version : "1.0"
};

//The JSON data which makes the camera take picture
var takePictureJSONData = {
    method : "actTakePicture",
    params : [],
    id : 1,
    version : "1.0"
};

//Puts the camera into "Shooting mode"
ajax ({
    url : endPointURL,
    type : "post",
    data : JSON.stringify( setShootModeJSONData ),
    contentType : "application/json",
    dataType : "json",
    timeout : 5000,
    success : function ( contents ) {
        //Makes the camera take picture
        ajax({
            url : endPointURL,
            type : "post",
            data : JSON.stringify( takePictureJSONData ),
            contentType : "application/json",
            dataType : "json",
            timeout : 5000,
            success : function ( contents ) {
                callbackSuccess( {
                    resultType : "continue"
                } );
            },
            error : function ( request, errorMessage ) {
                log("Camera : Network error");
                callbackSuccess( {
                    resultType : "continue"
                } );
            }
        });
        
    },
    error : function ( request, errorMessage ) {
        log("Camera : Network error");
        callbackSuccess( {
            resultType : "continue"
        } );
    }
});

return {
    resultType : "pause"
};
Result
/*** No Result Codes ***/

Camera Tag: JSON data for Import

List below JSON data for Import.
The making of the Tag, a setting item, confirmation of the code, the editing are possible on SDK by Importing JSON data in reference to "Import function".

JSON data for Import
{"formatVersion":"1.0","tagData":{"name":"Camera","icon":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAAAXNSR0IArs4c6QAAA8BJREFUeAHtnE9rIkEQxceoIIpelOTmKZDv/2E8efDkRVBRRBMjcamFXhrsP5Opnn4z7hOCw3RPv6r365pp3bU7i8XiXvAFc+AFpkzhvw4QAHgiEAABgB0Ay7MCCADsAFieFUAAYAfA8qwAAgA7AJZnBYAB9DT693v8a6ROp6ORaMy1sVyr5qkC8Pr6GjVou90WPz8/0X5N7jAcDovRaBQM8evrqzgej8E+rkYVgOl0WrjIyzkzY/b7fasBSB4CYDabPfhn53k6nYrD4eD04+FC64QKgIzjAmCfNyAszdYeunI156rmyYcweDoQQEkAZqaX7F66GwGUtKrqLSY2vPoZEBMItUtSk8mkeHlpzjyQ1czn52co7KRttQIoM2vG43HR7XaTJqUZTJaSl8vlYXFR1y2oVgBiRChwaVuv1xq/arnWFbNMJtd5CSDUFgtQBUDWvrFX7EOYL6nYuLnaJb7r9VpIrr6Klj7n87lSSB3Nf0vxBWRH0nSD7VhDx3XlqqqAZzE3ZLxpqyvX5iw/TKb/2TsBgIETwLMAkIeUfGVb5mEFzjmJfK/XKwaDgXqsZBUgxs/nc3VAbRlAvqJ+e3tTT7hkANpiXNPiJAAwEQIgALADYHlWAAGAHQDLswIIAOwAWJ4VQABgB8DyrAACADsAlmcFEADYAbA8K4AAwA6A5VkBBAB2ACzPCiAAsANgeVYAAYAdAMuzAggA7ABYnhVAAGAHwPKsAAIAOwCWZwUQANgBsDwrgADADoDlWQEEAHaggrz8ZFX+UuxxofqhdoXYn+oS+VmW9vfDvAUppoTWfJEmAAWAFJcSQAoXFWMQgMK8FJcSQAoXFWMQgMK8FJcSQAoXFWOo9gt6f3//tw6WJZnZJ8I+Xq1Wxe12U4SIvVRykh2C7Z1z7fW/OZYdtWT7td8uTVUAZMOK0KdBCU7+2v6SHGVjwZC5IR9C+fMWFHLHaguZb3X79aGqAmJqZYKObeoX00jdLjG74ja3mtR6tQKIBStJfXx8BG9jsTFSt+92u2Kz2TxAcEFJoQ0FIEktl8sUeSQdw2V2XRXAZ0ACdJqFRq0ANIEl8CXpEK6qMAKhNtPH966+BblMloBc531BtOG8Kx87z6oQVP8g0+/3o959f39H+zS9g/kcEIpTAFX5wKmqgGcwN2SqaZOlcl3L5VqfASYBvvsdIAC/N1laCCCLzX4RAvB7k6WFALLY7BchAL83WVoIIIvNfhEC8HuTpYUAstjsFyEAvzdZWgggi81+EQLwe5OlhQCy2OwX+QM87NrMcdrt8wAAAABJRU5ErkJggg==","description":"This is a sample Software Tag using \"Camera Remote API\".","functions":[{"id":"function_0","name":"TakePicture","connector":{"inputs":[{"label":""}],"outputs":[{"label":""}]},"properties":[{"name":"ActionListURL","referenceName":"actionListURL","type":"string","defaultValue":"http://192.168.0.100:10000/sony"}],"extension":{"initialize":"/*** No Initialize Codes ***/","receive":"/*** No Receive Codes ***/","execute":"//The endpoint URL of Remote API\nvar endPointURL = properties.actionListURL + \"/camera\";\n\n//The JSON data which puts the camera into \"Shooting mode\"\nvar setShootModeJSONData = {\n   \tmethod : \"setShootMode\",\n\tparams : [\"still\"],\n\tid : 1,\n\tversion : \"1.0\"\n};\n\n//The JSON data which makes the camera take picture\nvar takePictureJSONData = {\n\tmethod : \"actTakePicture\",\n\tparams : [],\n\tid : 1,\n\tversion : \"1.0\"\n};\n\n//Puts the camera into \"Shooting mode\"\najax ({\n\turl : endPointURL,\n\ttype : \"post\",\n\tdata : JSON.stringify( setShootModeJSONData ),\n\tcontentType : \"application/json\",\n\tdataType : \"json\",\n\ttimeout : 5000,\n\tsuccess : function ( contents ) {\n\t\t//Makes the camera take picture\n\t\tajax({\n\t\t\turl : endPointURL,\n\t\t\ttype : \"post\",\n\t\t\tdata : JSON.stringify( takePictureJSONData ),\n\t\t\tcontentType : \"application/json\",\n\t\t\tdataType : \"json\",\n\t\t\ttimeout : 5000,\n\t\t\tsuccess : function ( contents ) {\n\t\t\t\tcallbackSuccess( {\n\t\t\t\t\tresultType : \"continue\"\n\t\t\t\t} );\n\t\t\t},\n\t\t\terror : function ( request, errorMessage ) {\n\t\t\t\tlog(\"Camera : Network error\");\n\t\t\t\tcallbackSuccess( {\n\t\t\t\t\tresultType : \"continue\"\n\t\t\t\t} );\n\t\t\t}\n\t\t});\n\t\t\n\t},\n\terror : function ( request, errorMessage ) {\n\t\tlog(\"Camera : Network error\");\n\t\tcallbackSuccess( {\n\t\t\tresultType : \"continue\"\n\t\t} );\n\t}\n});\n\nreturn {\n\tresultType : \"pause\"\n};","result":"/*** No Result Codes ***/"}}]}}

Download

Weather forecast Tag

Weather forecast Tag is the Software Tag which a reaction turns into depending on current weather using Weather APII which OpenWeatherMap service provides.
In this example, when there was input from an input connector, you implement a Tag to output into plural output connector after distinguishing weather which is fine, rain, cloudy, at the specific place
(for example appoint it by character string including Tokyo).

Weather forecast Tag : code

"Check" Function

The source codes of "Check" Function are as follows. There is a line describing API Key in a part of the source code of "Execute". When you use this Tag, you make a account by OpenWeatherMap service, and you use it after having rearranged to API Key which you acquired.

Initialize
//Initialize "outputIndex"
return {
    runtimeValues : {
        outputIndex : 0
    }
};
Receive
/*** No Receive Codes ***/

Execute

//The API which gets daily weather forecast
var apiURL = "http://api.openweathermap.org/data/2.5/forecast/daily";
 
//The parameter of the API
//Pass the value of the property
var data = {
    "q" : properties.location,
    "cnt" : 1,
    "APPID" : '1111111111' //Please replace it with the App ID you get
};
 
ajax ({
    url : apiURL,
    data : data,
    type : "get",
    timeout : 5000,
    success : function ( contents ) {
        //Validate the contents
        if ( !contents.list || !contents.list[ 0 ] || !contents.list[ 0 ].weather || !contents.list[ 0 ].weather[ 0 ] || !contents.list[ 0 ].weather[ 0 ].id ) {
            log("Weather : Invalid data");
            runtimeValues.outputIndex = -1;
            callbackSuccess( {
                resultType : "continue",
                runtimeValues : runtimeValues
            } );
        }
 
        //Extract the ID part indicating the weather and convert it to the number value
        var idNum = contents.list[ 0 ].weather[ 0 ].id + 0;
 
        //Change the value of "outputIndex" depending on the weather
        if ( ( 200 <= idNum && idNum <= 531 ) || ( 600 <= idNum && idNum <= 622 ) ) { //Rainy
            runtimeValues.outputIndex = 2;
        } else if ( 701 <= idNum && idNum <= 781 ) { //Cloudy
            runtimeValues.outputIndex = 1;
        } else if ( 800 <= idNum && idNum <= 802 ) { //Sunny
            runtimeValues.outputIndex = 0;
        } else {
            runtimeValues.outputIndex = 1;
        }
         
        callbackSuccess( {
            resultType : "continue",
            runtimeValues : runtimeValues
        } );
    },
    error : function ( request, errorMessage ) {
        log("Weather : Network error");
        runtimeValues.outputIndex = -1;
        callbackSuccess( {
            resultType : "continue",
            runtimeValues : runtimeValues
        } );
    }
});
 
return {
    resultType : "pause"
};

Result
//Select an output connector depending on the "outputIndex" value updated in "Execute"
return {
    indexes : [ runtimeValues.outputIndex ],
    resultType : "continue"
};

Weather forecast Tag: JSON data for Import

List below JSON data for Import.
You are available for the making of the Tag, a setting item, confirmation, the editing of the code on SDK, by importing JSON data in reference to "Import function".

JSON data for import
{"formatVersion":"1.0","tagData":{"name":"Weather","icon":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAAAXNSR0IArs4c6QAAAqFJREFUeAHtnUtrwkAYRRNRBHUjoks3guD//y2CG1fuRBTBhYiPMl3MqiY0k+ZoPYHCkJi5892TO6N9TPPlcvnIPDAHWpiywt8OCAB+EAQgANgBWN4ECAB2AJY3AQKAHYDlTYAAYAdgeRMgANgBWL6doj8ej0tv3+122ePx3t/v6/V6Wb/fL6z1crlkx+Ox8DU/XWwEwE/C73QuACh72E6nUyUArgHwkyAAAcAOwPImAAaQtAjXMfbBYFBHN7X1Ed7NhK+mDhzAcDjMWq3XCeLhcPgsAJvNpqmH7SV1khIQ3vt+whGmpLJaz+dzJStyfy2lkm+13fQ6k29tJb1XRwKAeQlAALADsHytCeh2u3A5zcmHzy6dTidZsFYAs9ksy/M8eVDv0EH4BD+dTpOHWiuA5NF8YAcCgKELQACwA7C8CRAA7AAsbwIEADsAy5sAAcAOwPImQACwA7C8CRAA7AAsbwIEADsAy5sAAcAOwPImQACwA7C8CRAA7AAsbwIEADsAy5sAAcAOwPImQACwA7C8CRAA7AAsbwIEADsAy5sAAcAOwPL+oTYMwClIALADsLwJEADsACxvAgQAOwDLmwAYQNKOWYvFonT4q9Xq7bcuHo1G2WQyKaw17KhVZfu1JACfsi9EqLOs1rLrz+g5BT1zpqHzAmjI6GcySVPQs05/c34+n7/UvqHb7Tbb7/e/KSHptTiA9XqdVEDdN9/v97q7LOwPB3C73QoH+N8vugbAhAUAA0j6gUy7XT6DXa9XuMR0+bBBX9kG4+H/5FSZTssdLBj/fzC3oLx4KSzMf7U4OwVFm5mGABjfo6oAohVMQwCM71FVANEKpiEAxveoKoBoBdMQAON7VBVAtIJpCIDxPaoKIFrBNATA+B5VBRCtYBpfYS9rl/NlrzIAAAAASUVORK5CYII=","description":"This is a sample Software Tag using \"Open Weather Map : Weather API\".","functions":[{"id":"function_0","name":"Check","connector":{"inputs":[{"label":""}],"outputs":[{"label":"Sunny"},{"label":"Cloudy"},{"label":"Rainy"}]},"properties":[{"name":"Location","referenceName":"location","type":"string","defaultValue":"Tokyo"}],"extension":{"initialize":"//Initialize \"outputIndex\"\nreturn {\n\truntimeValues : {\n\t\toutputIndex : 0\n\t},\n\tresultType : \"continue\"\n};","receive":"/*** No Receive Codes ***/","execute":"//The API which gets daily weather forecast\nvar apiURL = \"http://api.openweathermap.org/data/2.5/forecast/daily\";\n\n//The parameter of the API\n//Pass the value of the property\nvar data = {\n\t\"q\" : properties.location,\n\t\"cnt\" : 1,\n\t\"APPID\" : '1111111111' //Please replace it with the App ID you get\n};\n\najax ({\n\turl : apiURL,\n\tdata : data,\n\ttype : \"get\",\n\ttimeout : 5000,\n\tsuccess : function ( contents ) {\n\t\t//Validate the contents\n\t\tif ( !contents.list || !contents.list[ 0 ] || !contents.list[ 0 ].weather || !contents.list[ 0 ].weather[ 0 ] || !contents.list[ 0 ].weather[ 0 ].id ) {\n\t\t\tlog(\"Weather : Invalid data\");\n\t\t\truntimeValues.outputIndex = -1;\n\t\t\tcallbackSuccess( {\n\t\t\t\tresultType : \"continue\",\n\t\t\t\truntimeValues : runtimeValues\n\t\t\t} );\n\t\t}\n\n\t\t//Extract the ID part indicating the weather and convert it to the number value\n\t\tvar idNum = contents.list[ 0 ].weather[ 0 ].id + 0;\n\n\t\t//Change the value of \"outputIndex\" depending on the weather\n\t\tif ( ( 200 <= idNum && idNum <= 531 ) || ( 600 <= idNum && idNum <= 622 ) ) { //Rainy\n\t\t\truntimeValues.outputIndex = 2;\n\t\t} else if ( 701 <= idNum && idNum <= 781 ) { //Cloudy\n\t\t\truntimeValues.outputIndex = 1;\n\t\t} else if ( 800 <= idNum && idNum <= 802 ) { //Sunny\n\t\t\truntimeValues.outputIndex = 0;\n\t\t} else {\n\t\t\truntimeValues.outputIndex = 1;\n\t\t}\n\t\t\n\t\tcallbackSuccess( {\n\t\t\tresultType : \"continue\",\n\t\t\truntimeValues : runtimeValues\n\t\t} );\n\t},\n\terror : function ( request, errorMessage ) {\n\t\tlog(\"Weather : Network error\");\n\t\truntimeValues.outputIndex = -1;\n\t\tcallbackSuccess( {\n\t\t\tresultType : \"continue\",\n\t\t\truntimeValues : runtimeValues\n\t\t} );\n\t}\n});\n\nreturn {\n\tresultType : \"pause\"\n};","result":"//Select an output connector depending on the \"outputIndex\" value updated in \"Execute\"\nreturn {\n\tindexes : [ runtimeValues.outputIndex ],\n\tresultType : \"continue\"\n};"}}]}}

Download

Random Tag

The Random Tag is the Software Tag which chooses one among plural output connectors at random and outputs a message, whenever a message is input into an input connector.
In this example, choose one from six output connectors at random and output a message.

Random Tag : code

"RandomOut" Function

The source code of "RandomOut" Function is as follows.

Initialize
/*** No Initialize Codes ***/

Receive
/*** No Receive Codes ***/

Execute
/*** No Execute Codes ***/

Result
//Select a output connector out of 6 connectors randomly
var outputIndex = Math.floor( Math.random() * 6 );
 
return {
    indexes : [ outputIndex ],
    resultType : "continue"
}

List below JSON data for Import.

You are available for the making of the Tag, a setting item, confirmation, the editing of the code on SDK, by importing JSON data in reference to "Import function".

JSON data for import
{"formatVersion":"1.0","tagData":{"name":"Random","icon":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAYAAADimHc4AAAAAXNSR0IArs4c6QAAA8BJREFUeAHtnE9rIkEQxceoIIpelOTmKZDv/2E8efDkRVBRRBMjcamFXhrsP5Opnn4z7hOCw3RPv6r365pp3bU7i8XiXvAFc+AFpkzhvw4QAHgiEAABgB0Ay7MCCADsAFieFUAAYAfA8qwAAgA7AJZnBYAB9DT693v8a6ROp6ORaMy1sVyr5qkC8Pr6GjVou90WPz8/0X5N7jAcDovRaBQM8evrqzgej8E+rkYVgOl0WrjIyzkzY/b7fasBSB4CYDabPfhn53k6nYrD4eD04+FC64QKgIzjAmCfNyAszdYeunI156rmyYcweDoQQEkAZqaX7F66GwGUtKrqLSY2vPoZEBMItUtSk8mkeHlpzjyQ1czn52co7KRttQIoM2vG43HR7XaTJqUZTJaSl8vlYXFR1y2oVgBiRChwaVuv1xq/arnWFbNMJtd5CSDUFgtQBUDWvrFX7EOYL6nYuLnaJb7r9VpIrr6Klj7n87lSSB3Nf0vxBWRH0nSD7VhDx3XlqqqAZzE3ZLxpqyvX5iw/TKb/2TsBgIETwLMAkIeUfGVb5mEFzjmJfK/XKwaDgXqsZBUgxs/nc3VAbRlAvqJ+e3tTT7hkANpiXNPiJAAwEQIgALADYHlWAAGAHQDLswIIAOwAWJ4VQABgB8DyrAACADsAlmcFEADYAbA8K4AAwA6A5VkBBAB2ACzPCiAAsANgeVYAAYAdAMuzAggA7ABYnhVAAGAHwPKsAAIAOwCWZwUQANgBsDwrgADADoDlWQEEAHaggrz8ZFX+UuxxofqhdoXYn+oS+VmW9vfDvAUppoTWfJEmAAWAFJcSQAoXFWMQgMK8FJcSQAoXFWMQgMK8FJcSQAoXFWOo9gt6f3//tw6WJZnZJ8I+Xq1Wxe12U4SIvVRykh2C7Z1z7fW/OZYdtWT7td8uTVUAZMOK0KdBCU7+2v6SHGVjwZC5IR9C+fMWFHLHaguZb3X79aGqAmJqZYKObeoX00jdLjG74ja3mtR6tQKIBStJfXx8BG9jsTFSt+92u2Kz2TxAcEFJoQ0FIEktl8sUeSQdw2V2XRXAZ0ACdJqFRq0ANIEl8CXpEK6qMAKhNtPH966+BblMloBc531BtOG8Kx87z6oQVP8g0+/3o959f39H+zS9g/kcEIpTAFX5wKmqgGcwN2SqaZOlcl3L5VqfASYBvvsdIAC/N1laCCCLzX4RAvB7k6WFALLY7BchAL83WVoIIIvNfhEC8HuTpYUAstjsFyEAvzdZWgggi81+EQLwe5OlhQCy2OwX+QM87NrMcdrt8wAAAABJRU5ErkJggg==","description":"This is a sample Software Tag.","functions":[{"id":"function_0","name":"RandomOut","connector":{"inputs":[{"label":""}],"outputs":[{"label":"out1"},{"label":"out2"},{"label":"out3"},{"label":"out4"},{"label":"out5"},{"label":"out6"}]},"properties":[],"extension":{"initialize":"/*** No Initialize Codes ***/","receive":"/*** No Receive Codes ***/","execute":"/*** No Execute Codes ***/","result":"//Select a output connector out of 6 connectors randomly\nvar outputIndex = Math.floor( Math.random() * 6 );\n\nreturn {\n\tindexes : [ outputIndex ],\n\tresultType : \"continue\"\n}\n"}}]}}

Download

To Page Top