You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/index.md
+138-5Lines changed: 138 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
Node generator
2
2
----
3
-
Node generator is a command line tool to generate Node-RED nodes based on various sources such as an OpenAPI document or a Function node.
3
+
Node generator is a command line tool to generate Node-RED nodes based on various sources such as an OpenAPI document, a Function node or [Web of Things Thing Description](https://www.w3.org/TR/wot-thing-description/).
4
4
It helps developers dramatically reduce the time to implement Node-RED nodes.
5
5
6
6
## Use cases
@@ -31,17 +31,22 @@ Node generator can generate an original node from a subflow that contains the fl
31
31
And Node-RED users can easily share their original node with other Node-RED users via flow library.
32
32
33
33
#### (4) Connection to devices
34
-
Web of Things (WoT) is a standard specification to connect IoT devices.
35
-
Node generator will support the Web of Things specification to create original nodes.
36
-
Currently, there is [a slide](https://github.com/w3c/wot/blob/master/plugfest/2018-bundang/images/Plugfest-Bundang-WoT.pdf) and [a screenshot](https://github.com/w3c/wot/blob/master/plugfest/2018-bundang/result-hitachi.md) of the prototype implementation on GitHub.
34
+
IoT application developers wants to concentrate their effort to
35
+
create value from connected devices, and not to go into
36
+
detail of implementation. To abstract out these detail,
37
+
W3C Web of Things (WoT) provides mechanism to formally describe
38
+
interfaces of IoT devices. In WoT, a device interface is
39
+
described by Thing Description, and Node generator will support the Thing Description to create original nodes.
40
+
Using Node generator, application developers can handle a node
41
+
in Node-RED as an avatar of a device.
37
42
38
43
## How to use Node generator
39
44
To install Node generator to your local PC, you need to input the following "npm install" command on command prompt (Windows) or terminal (macOS/Linux).
40
45
Because the command execution needs root permission, "sudo" is required before "npm install" command on macOS or Linux environment.
41
46
42
47
npm install -g node-red-nodegen
43
48
44
-
The current version of Node generator supports function node and OpenAPI document as source files.
49
+
The current version of Node generator supports function node, OpenAPI document and WoT Thing Description as source files.
45
50
node-red-nodegen creates a node from the file which is specified in the argument of the command as follows.
46
51
47
52
node-red-nodegen <source file> -> The command tool outputs the node from the source file
@@ -50,6 +55,7 @@ The following documentation explains methods of creating nodes from two types of
50
55
51
56
-[How to create a node from OpenAPI document](#how-to-create-a-node-from-openapi-document)
52
57
-[How to create a node from function node](#how-to-create-a-node-from-function-node)
58
+
-[How to create a node from WoT Thing Description](#how-to-create-a-node-from-wot-thing-description)
53
59
54
60
## Generated files which node package contains
55
61
The following is a typical directory structure of the node package generated by Node generator.
@@ -711,6 +717,133 @@ The following example is the procedure to generate a node from the function node
711
717
712
718
-> You can use format-date node on your Node-RED flow editor.
713
719
720
+
## How to create a node from WoT Thing Description
721
+
You can specify the URL or file path of a Thing Description (TD) as the first argument of the node-red-nodegen command. If you use the URL for retrieve a TD, or the file whose extension isn't ".jsonld", you should specify the `--wottd` option. And, if you get a TD using URL, you can also specify `--lang` option to get a TD of the specific language, if exist.
722
+
723
+
(1) Generate node using node-red-nodegen command
724
+
725
+
node-red-nodegen td.jsonld
726
+
727
+
Node-RED users typically import the generated node to the palette of Node-RED flow editor using the following procedures.
728
+
729
+
(2) Change current directory to Node-RED home directory (Typically, Node-RED home directory is ".node-red" under the home directory)
730
+
731
+
cd ~/.node-red
732
+
733
+
(3) Locally install the module
734
+
735
+
npm install <location of node module>
736
+
737
+
(4) Start Node-RED
738
+
739
+
node-red
740
+
741
+
(5) Access the Node-RED flow editor (http://localhost:1880)
742
+
743
+
-> You can see the generated node on the palette (in an "Web of Things" category, if not specified by command-line option) of the Node-RED flow editor.
744
+
745
+
(6) Drag and drop the generated node to the workspace
746
+
747
+
(7) Configure the node
748
+
749
+
- Interaction: which interaction do you want to use?
750
+
- Name: what is the name of the interaction?
751
+
- Access: when you use a property, what kind of interaction do you want? (Read/Write/Observe)
752
+
- Form: which pair of authentication method and end point do you want to use?
753
+
- Token or Username/Password: if the end point needs credential for access, specify it.
754
+
- Node name: you can specify the display name of the node
755
+
756
+
(8) Create a flow on the Node-RED flow editor
757
+
758
+
- Property:
759
+
- To read a property, send any message to the node, and the result will emitted as msg.payload.
760
+
- To write to property, send the value to be written as msg.payload.
761
+
- When you observe a property, the node periodically emits the property value as msg.payload.
762
+
- Action:
763
+
- To invoke an action, send message to a node with arguments in msg.payload.
764
+
- Event:
765
+
- The node emits messages when event occurred. Event is stored in msg.payload.
766
+
767
+
(9) Run the flow
768
+
769
+
### Command line options
770
+
If you want to customize the generated node, the following procedures and command line options will be helpful.
771
+
772
+
#### Module name
773
+
Node generator uses "node-red-contrib-" as the default prefix for the module, and default node name is created from "name" property in TD.
774
+
If you want to change the default module name, you can specify the module name using `--module` or `--prefix` option.
775
+
776
+
node-red-nodegen td.jsonld --module wotmodule
777
+
node-red-nodegen td.jsonld --prefix node-red-wot
778
+
779
+
#### Node name
780
+
In the case of the node generated from Thing Description, "name" property in TD is used as the generated node's name.
781
+
Node generator will replace uppercase characters and spaces with hyphens to convert appropriate name for npm module and Node-RED node.
782
+
783
+
If you want to change the default name, you can set the node name using `--name` option.
784
+
If "name" property contains a double-byte character instead of alphabet and number, you need to specify the node name using `--name` option in order for Node generator to generate the name correctly.
785
+
786
+
node-red-nodegen td.jsonld --name new-node-name
787
+
788
+
#### Version
789
+
By default, Node generator uses "version" property as the module version number.
790
+
791
+
When you update the version number of the module without incrementing the version number in Thing Description, you need to specify `--version` option.
792
+
A conflict error will occur when you publish a module that has the same version number as the previously published module when using "npm publish" command.
793
+
In this case, the `--version` option needs to be specified to update the version number of the module.
794
+
795
+
node-red-nodegen td.jsonld --version 0.0.2
796
+
797
+
#### Keywords
798
+
`--keywords` is a useful options for keywords of the module in the flow library.
799
+
On the flow library website, visitors can search the module using keywords.
800
+
For example, if you want to use "lamp" as a keyword, you can specify the word using `--keyword` option.
801
+
By default, Node generator uses "node-red-nodegen" as a keywords.
802
+
803
+
node-red-nodegen td.jsonld --keywords lamp
804
+
805
+
To add more than two keywords, you can also use comma-separated keywords.
806
+
807
+
node-red-nodegen td.jsonld --keywords lamp,led
808
+
809
+
If "--keywords node-red" is specified when you publish the generated node, your node will be registered on the flow library and you can install the node via Node-RED flow editor.
On the palette of Node-RED flow editor, the generated node is in "Web of Things" category by default.
815
+
To change the category, you can use `--category` option.
816
+
For example, the node generated from the following command can be viewed in the "analysis" category on the Node-RED flow editor.
817
+
818
+
node-red-nodegen td.jsonld --category analysis
819
+
820
+
#### Node icon
821
+
Node generator command supports `--icon` option to specify icon file for the generated node.
822
+
You can use PNG file path or [file name of stock icons](https://nodered.org/docs/creating-nodes/appearance) for the option. The icon should have white on a transparent background.
823
+
824
+
node-red-nodegen td.jsonld --icon <PNG file or stock icon>
825
+
826
+
827
+
#### Node color
828
+
By default, Node generator uses default node color defined in the node templates. If you need to change it, you can use the `--color` option of the command line. The option value should be the sequence of the hexadecimal numbers ("RRGGBB" formats) which represents node color.
829
+
830
+
node-red-nodegen td.jsonld --color FFFFFF
831
+
832
+
#### Node information in info tab
833
+
Node generator automatically generates the node information in the info tab using the following properties in Thing Description
834
+
835
+
- description: Node description:
836
+
- title/description/forms in properties/actions/events: Interaction description
837
+
- support: Support Information
838
+
- links: References
839
+
840
+
If you want to modify node information in info tab, you can manually edit the generated HTML file.
841
+
842
+
#### README
843
+
To explain the details of the node, you can write documentation in a README.md file.
844
+
The documentation will be used in the flow library website if you publish your node on the flow library.
845
+
The Node generator outputs the template file of README.md so you can just modify it.
846
+
714
847
## Known Issues
715
848
- In the Node generator command, you cannot use --tgz option and --icon option simultaneously because it has an asynchronous problem.
716
849
- The value of `info.title` in the OpenAPI document has to start with an alphabet (not a number) because it will be used in the variable name in the generated code.
0 commit comments