OpenThread released by Google is an open-source implementation of the Thread networking protocol. Google Nest has released OpenThread to make the technology used in Nest products broadly available to developers to accelerate the development of products for the connected home.
Node.js® is a JavaScript runtime built on Chrome's V8 JavaScript engine. Latest LTS Version: 12.19.0 (includes npm 6.14.8) Download the Node.js source code or a pre-built installer for your platform, and start developing today. Homebrew is one of the two popular package managers for Mac. Assuming you have previously installed node with brew install node. You can get up-to-date with formulae and upgrade to the latest Node.js version with the following. See full list on treehouse.github.io.
The Thread specification defines an IPv6-based reliable, secure and low-power wireless device-to-device communication protocol for home applications. OpenThread implements all Thread networking layers including IPv6, 6LoWPAN, IEEE 802.15.4 with MAC security, Mesh Link Establishment, and Mesh Routing.
This Codelab will walk you through simulating a Thread network on simulated devices.
What you'll learn
- How to set up the OpenThread build toolchain
- How to simulate a Thread network
- How to authenticate Thread nodes
- How to manage a Thread network with OpenThread Daemon
What you'll need
- git
- Basic knowledge of Linux, network routing
Git
Git is required to complete this Codelab. Download and install it before continuing.
Once installed, follow the instructions for your specific OS to download and build OpenThread.
XCode for Mac OS X
XCode is required to install and build OpenThread on Mac OS X.
After XCode is installed, install the XCode Command Line Tools:
Build on Linux / Mac OS X
These installation instructions have been tested on Ubuntu Server 14.04 LTS and Mac OS X Sierra 10.12.6.
Install OpenThread. The
bootstrap
commands make sure the toolchain is installed and the environment is properly configured:Using Windows
If you prefer Windows, we recommend trying the Docker version of this Codelab.
Once your installation is complete, build the example OpenThread application. For this Codelab we are using the simulation example.
Now build OpenThread Daemon:
The example application you'll use for this Codelab demonstrates a minimal OpenThread application that exposes the OpenThread configuration and management interfaces via a basic command-line interface (CLI).
This exercise takes you through the minimal steps required to ping one simulated Thread device from another simulated Thread device.
Note: This first exercise does not include any network parameter configuration, such as the IEEE 802.15.4 PAN ID or the Thread Master Key. OpenThread currently implements default values for network parameters (which can be changed later via the CLI).
The figure below describes a basic Thread network topology. For this exercise, we'll simulate the two nodes within the green circle: a Thread Leader and Thread Router with a single connection between them.
Ping a node
1**. Start Node 1**
Navigate to the
openthread
directory and spawn the CLI process for a simulated Thread device using the ot-cli-ftd
binary.x86_64-unknown-linux-gnu
represents the platform of VM used for this Codelab. When using a different OS image, OpenThread processes will be found under a different path. For example, on Mac OS X, the platform would be x86_64-apple-darwin
. Check the ~/src/openthread/output
folder for the correct platform value to use.This binary implements an OpenThread device simulated on top of POSIX. The IEEE 802.15.4 radio driver is implemented on top of UDP (IEEE 802.15.4 frames are passed within UDP payloads).
The argument of
1
is a file descriptor that represents the least-significant bits of the 'factory-assigned' IEEE EUI-64 for the simulated device. This value is also used when binding to a UDP port for IEEE 802.15.4 radio emulation (port = 9000 + file descriptor). Each instance of a simulated Thread device in this Codelab will use a different file descriptor.Note: Only use file descriptors of
1
or greater as noted in this Codelab when spawning the process for a simulated device. A file descriptor of 0
is reserved for other use.If you don't see the
>
prompt after running this command, press enter
**.**Create a new Operational Dataset and commit it as the active one. The Operational Dataset is the configuration for the Thread network you are creating.
dataset init new
creates a new Operational Dataset with random values. Your values will differ from the values shown in this Codelab. Replace the values in the Codelab example commands with the values from your Operational Dataset.Commit this dataset as the active one:
Bring up the IPv6 interface:
Start Thread protocol operation:
Wait a few seconds and verify that the device has become the Thread Leader. The Leader is the device responsible for managing router ID assignment.
View the IPv6 addresses assigned to Node 1's Thread interface (your output will be different):
Note the specific IPv6 address types:
- Begins with
fd
= mesh-local - Begins with
fe80
= link-local
Mesh-local address types are classified further:
- Contains
ff:fe00
= Router Locator (RLOC) - Does not contain
ff:fe00
= Endpoint Identifier (EID)
Identify the EID in your console output make a note of it for later use. In the sample output above, the EID is:
fd61:2344:9a52:ede0:d041:c5ba:a7bc:5ce6
The RLOC will change as the network topology changes and a Thread device switches between states. The EID is independent of topology changes and will remain static.
2. Start Node 2
Open a new terminal and navigate to the
openthread
directory and spawn the CLI process. This is your second simulated Thread device:If you don't see the
>
prompt after running this command, press enter
**.**Configure the Thread Master Key and PAN ID, using the same values as Node 1's Operational Dataset:
Commit this dataset as the active one:
![Update node mac os x Update node mac os x](/uploads/1/3/4/8/134854870/660557638.jpg)
Bring up the IPv6 interface:
Start Thread protocol operation:
The device will initialize itself as a Child. A Thread Child is equivalent to an End Device, which is a Thread device that transmits and receives unicast traffic only with a Parent device.
Within 2 minutes you should see the state switch from
child
to router
. A Thread Router is capable of routing traffic between Thread devices. It is also referred to as a Parent.Verify the network
An easy way to verify the mesh network is to look at the router table.
1. Check connectivity
On Node 2, get the RLOC16. The RLOC16 is the last 16 bits of the device's RLOC IPv6 address.
On Node 1, check the router table for Node 2's RLOC16. Make sure Node 2 has switched to the router state first.
Node 1's RLOC of
0xa800
is found in the table, confirming that it is connected to the mesh.2. Ping Node 1 from Node 2
Verify connectivity between the two simulated Thread devices. In Node 2,
ping
the EID assigned to Node 1:Press
enter
to return to the >
CLI prompt.Test the network
Now that you can successfully ping between two simulated Thread devices, test the mesh network by taking one node offline.
Return to Node 1 and stop Thread:
Switch to Node 2 and check the state. Within two minutes, Node 2 detects that the leader (Node 1) is offline, and you should see Node 2 transition to be the
leader
of the network:Once confirmed, stop Thread and factory reset Node 2 before exiting. A factory reset is done to ensure that the Thread network credentials we used in this exercise are not carried over to the next exercise.
Also factory reset and exit Node 1:
See the OpenThread CLI Reference to explore all available CLI commands.
In the previous exercise, you set up a Thread network with two simulated devices and verified connectivity. However, this only allows unauthenticated IPv6 link-local traffic to pass between devices. To route global IPv6 traffic between them (and the Internet via a Thread border router), nodes must be authenticated.
In order to authenticate, one device must act as a Commissioner. The Commissioner is the currently elected authentication server for new Thread devices, and the authorizer for providing the network credentials required for the devices to join the network.
![Node For Mac Os X Node For Mac Os X](/uploads/1/3/4/8/134854870/810034038.png)
In this exercise, we will use the same two-node topology as before. For authentication, the Thread Leader will act as the Commissioner, the Thread Router as a Joiner.
Devices without Thread interfaces may also perform the Commissioner role. For example, a cell phone or a server in the cloud can provide the interface by which a human administrator joins a new device to the Thread Network. These devices are called External Commissioners.
1. Create a network
If continuing from the previous exercise, you should already have two terminal windows open. If not, make sure two are open and ready to use. One will serve as Node 1, the other as Node 2.
In Node 1, spawn the CLI process:
x86_64-unknown-linux-gnu
represents the platform of the VM used for this Codelab. When using a different OS image, OpenThread processes will be found under a different path. For example, on Mac OS X, the platform would be x86_64-apple-darwin
.If you don't see the
>
prompt after running this command, hit enter
.Create a new Operational Dataset, commit it as the active one, and start Thread:
Commit this dataset as the active one:
Bring up the IPv6 interface:
Start Thread protocol operation:
Wait a few seconds and verify that the device has become a Thread Leader:
2. Start the Commissioner role
While still on Node 1, start the Commissioner role:
Allow any Joiner (by using the
*
wildcard) with the J01NME
Joiner Credential to commission onto the network. A Joiner is a device that is added by a human administrator to a commissioned Thread Network.J01NME
is the user-defined Joiner Credential used for this Codelab. You can choose any Joiner Credential you wish in a different implementation of a Thread network. For more information, see Thread Commissioning.3. Start the Joiner role
In a second terminal window, spawn a new CLI process. This is Node 2.
On Node 2, enable the Joiner role using the
J01NME
Joiner Credential.... wait a few seconds for confirmation ...
As a Joiner, the device (Node 2) has successfully authenticated itself with the Commissioner (Node 1) and received the Thread Network credentials.
If you get a
Join failed
message, the Commissioner may have timed out waiting for a Join request. In that case, restart from the commissioner joiner
command. Don't wait too long after starting the Commissioner to enable the Joiner role.You may also receive error and/or log messages on both Nodes 1 and 2 after a successful join. These are normal and can be ignored.
Now that Node 2 is authenticated, start Thread:
4. Validate network authentication
Check the
state
on Node 2, to validate that it has now joined the network. Within two minutes, Node 2 transitions from child
to router
:5. Reset configuration
To prepare for the next exercise, reset the configuration. On each Node, stop Thread, do a factory reset, and exit the simulated Thread device:
You may have to press
enter
a few times to bring the >
prompt back after a factoryreset
command.For this exercise, we are going to simulate one CLI instance (a single embedded SoC Thread device) and one Radio Co-Processor (RCP) instance.
ot-daemon
is a mode of the OpenThread Posix app that uses a UNIX socket as input and output, so that OpenThread core can run as a service. A client can communicate with this service by connecting to the socket using the OpenThread CLI as the protocol.ot-ctl
is a CLI provided by ot-daemon
to manage and configure the RCP. Using this, we'll connect the RCP to the network created by the Thread device.Node For Mac Os X 10.7
Use ot-daemon
This exercise will use three terminal windows, corresponding to the following:
- CLI instance of simulated Thread device (Node 1)
ot-daemon
processot-ctl
CLI instance
If continuing from the previous exercise you should already have two terminal windows open. Open a third to ensure you have three terminal windows available for this exercise.
1. Start Node 1
In the first terminal window, spawn the CLI process for your simulated Thread device:
x86_64-unknown-linux-gnu
represents the platform of VM used for this Codelab. When using a different OS image, OpenThread processes will be found under a different path. For example, on Mac OS X, the platform would be x86_64-apple-darwin
.If you don't see the
>
prompt after running this command, hit enter
.Create a new Operational Dataset, commit it as the active one, and start Thread:
Commit this dataset as the active one:
Bring up the IPv6 interface:
Start Thread protocol operation:
The
channel
is the 2.4 GHz channel as defined in IEEE 802.15.4. Non-reserved values are in the range of 11-26.The
masterkey
can be any user-defined 32 hexadecimal character string. If not specified, the masterkey
defaults to 00112233445566778899AABBCCDDEEFF
, and devices will be able to join the network without having to specify the key.View the IPv6 addresses assigned to Node 1's Thread interface:
As explained in the Simulate a Thread network step, one address is link-local (
fe80
) and three are mesh-local (fd
). The EID is the mesh-local address that does not contain ff:fe00
in the address. In this sample output, the EID is fd55:cf34:dea5:7994:460:872c:e807:c4ab
.Identify the specific EID from your
ipaddr
output, which will be used to communicate with the node.2. Start ot-daemon
In the second terminal window, navigate to the
openthread
directory, and start ot-daemon
for an RCP node, which we'll call Node 2. Use the -v
verbose flag so you can see log output and confirm that it is running:x86_64-unknown-linux-gnu
represents the platform of VM used for this Codelab. When using a different OS image, OpenThread processes will be found under a different path. For example, on Mac OS X, the platform would be x86_64-apple-darwin
.When successful,
ot-daemon
in verbose mode generates output similar to the following:3. Use ot-ctl to join the network
We haven't commissioned Node 2 (the
ot-daemon
RCP) to any Thread network yet. This is where ot-ctl
comes in. ot-ctl
uses the same CLI as the OpenThread CLI app. Therefore, you can control ot-daemon
nodes in the same manner as the other simulated Thread devices.In a third terminal window, start
ot-ctl
:Check the
state
of Node 2 (the RCP node) you started with ot-daemon
:Get Node 2's
eui64
, to restrict joining to the specific Joiner:On Node 1, start the Commissioner and restrict joining to only that eui64:
On Node 2, bring up the network interface and join the network:
... wait a few seconds for confirmation ...
As a Joiner, the RCP (Node 2) has successfully authenticated itself with the Commissioner (Node 1) and received the Thread Network credentials.
If you get a
Join failed
message, the Commissioner may have timed out waiting for a Join request. In that case, restart from the commissioner joiner
command. Don't wait too long after starting the Commissioner to enable the Joiner role.Now join Node 2 to the Thread network:
4. Validate network authentication
Check the
state
on Node 2, to validate that it has now joined the network. Within two minutes, Node 2 transitions from child
to router
:5. Validate connectivity
Quit
ot-ctl
by using Ctrl+D and on your host machine's command line, ping Node 1, using its EID with the ping6
command. If the ot-daemon
RCP instance is successfully joined to and communicating with the Thread network, the ping succeeds:Warning: If you quit
ot-ctl
by using the exit
command, ot-daemon
will terminate as well, as the CLI processor used by ot-ctl
is running within ot-daemon
. To ensure ot-daemon
and any related nodes continue to run, use Ctrl+D to quit ot-ctl
.You've successfully simulated your first Thread network using OpenThread. Awesome!
In this Codelab you learned how to:
- Set up the OpenThread build toolchain
- Simulate a Thread network
- Authenticate Thread nodes
- Manage a Thread network with OpenThread Daemon
If you want to learn more, explore these references:
Follow me on twitch!Since node.js is the new cool kid on the block, I want to write a really short introduction how to install it on Mac OS X and start playing with it.
Exploring technologies is something I try to fit in my everyday, that’s why I’m choosing the verb playing. This little and quick guide is really more for everyone who has more experience with PHP than with ruby or python. I don’t even want to talk to you ruby on rails people, you know how all this stuff works, shoo!
Exploring technologies is something I try to fit in my everyday, that’s why I’m choosing the verb playing. This little and quick guide is really more for everyone who has more experience with PHP than with ruby or python. I don’t even want to talk to you ruby on rails people, you know how all this stuff works, shoo!
Homebrew
Not only for node.js, but a powerful tool that every developer on Mac OS should have or have heard of: homebrew. So head on and install it, because it allows you to install node.js with one command (Terminal phobics, don’t worry, it’s short!) and gets you going on setting up your testing environment.
Getting node.js
To install node.js on your machine, you simply type:
That’s it. You watch a short process of download and build, which has not failed the couple of times I’ve tried it on both Mac OS 10.6 and 10.7, but don’t close that Terminal quite yet.
Running node.js
For running node.js you actually need to run a process in your shell or make something run the process for you. For now, we’ll stick to having the Terminal window open.
How to Node has a very comprehensive guide how to send output to a browser, by making node start an http server and listen for requests. Requests, as in every web capable programming language are important in node.js and you’ll be hearing a lot more about this request object in the future.
How to Node has a very comprehensive guide how to send output to a browser, by making node start an http server and listen for requests. Requests, as in every web capable programming language are important in node.js and you’ll be hearing a lot more about this request object in the future.
So what you don’t need to do is to define a directory, like you know from apache or lighttpd servers. You can create a node project in any folder on your system, go there in a Terminal window and run your .js file with node filename.js, followed by hitting ENTER.
Example:
Let’s say we wanted to use the hello world example, we’d shamelessly copy paste the code into our text editor and save it in a folder called nodetests. Now with the Terminal we type something like:
Node-red Macos
Now we have a running node server on the specified port, that will output Hello World on a specified address. You can see the output by pointing your browser to http://localhost:3000 and it should say: Hello World.
Going back to your editor and changing some lines will have absolutely no effect right now, because node does not check for file changes by default. So even if your file would now output `Hello Moon`, the node server still thinks that it should output `Hello World`, because it was that the last time it checked.
To prevent you from undergoing the horrible task of changing to your Terminal window, pressing
every time you make a change you want to preview, there actually is a way to skip that.
Using node-dev instead of node, automatically restarts your server, whenever it notices a file changed. That’s way cooler and feels a lot more like developing PHP suddenly. It’s not bad to feel a little at home when you start on frighteningly seeming complex stuff like node.js.
NPM: the node package manager
NPM is what apt is for debian or gem for ruby. It’s the universal tool for getting stuff and also packing stuff up in neat and reuseable modules.
Taking a look at the amazing list of modules available and also their own repository site, you will quickly understand why you will want to use it.
By simply typing
Taking a look at the amazing list of modules available and also their own repository site, you will quickly understand why you will want to use it.
By simply typing
you’ll install an hmvc framework, make it available for your project and also have the frameworks own tools for debugging, running servers or similar at hand.
Node.js community
I have not personally met anyone who actually has developed with node, but I’ve recently infected another developer with it.
Although I have joined the IRC channel, because I was stuck on some typical node.js beginner issues like correct use of callbacks and understanding how to prevent node.js from spawing 84 processes on resizing 18.8MP images with the imagemagick module. If you don’t watch out, you’re going to do more stuff parallel than you actually intend to and definitely more than your Mac Book Pro can handle without crashing (seriously).
Especially spion helped me and actually restructured some of my code for my understanding, which was pretty amazing of him, also looking at the things he actually has published. Kudos to him.
Although I have joined the IRC channel, because I was stuck on some typical node.js beginner issues like correct use of callbacks and understanding how to prevent node.js from spawing 84 processes on resizing 18.8MP images with the imagemagick module. If you don’t watch out, you’re going to do more stuff parallel than you actually intend to and definitely more than your Mac Book Pro can handle without crashing (seriously).
Especially spion helped me and actually restructured some of my code for my understanding, which was pretty amazing of him, also looking at the things he actually has published. Kudos to him.
Thank you for reading! If you have any comments, additions or questions, please leave them in the form below! You can also tweet them at me
If you want to read more like this, follow me on feedly or other rss readers