‘io.js’ includes the following functions:
- widgetExecute – executes a widget, like a user clicking on a button
- widgetSetState – sets a state of a widget, like a user clicking an on or off button
- widgetGetState – returns the state of a widget
- widgetSetString – sends a string via a widget
- widgetGetString – returns the string that a widget is currently set to
- widgetGetValue – returns the value that a widget is currently set to
- Updated ‘widgetSetState’ to return the widget state instead of ‘false’
- Added ‘widgetGetState’ function
- Fixed issues in IE6
- Initial release
If you don’t need to see the actual widget, you can hide it using the following commands. It’s recommend to embed hidden widgets near or right befire the </body> html tag.
The widgetID is the string at the end of the widget code:
‘Q6Vs3RepsH6I’ is the widgetID for the above widget.
The ‘on’ state corresponds to a logic level of high or ‘1’.
The ‘off’ state corresponds to a logic level of low or ‘0’.
var widget_state = widgetGetState('widgetID');
Variable serial and servo widgets need to use widgetSetString to send data to your module.
widgetSetString('widgetID', 'This is my serial message');
var widget_string = widgetGetString('widgetID');
var widget_value = widgetGetValue('widgetID');
If you want to send special characters and bytes with widgetSetString, use the URL encoded characters.
widgetSetString('Q6Vs3RepsH6I', 'This is line 1.%0D%0AThis is line 2.');
The result will be:
This is line 1. This is line 2.
Common URL Codes
- %0D = carriage return
- %0A = linefeed
Here is a table that lists all of the URL codes: URL Codes