Access your SmartMesh IP devices through Weaved or ngrok
Background
Your SmartMesh IP network is an essential piece of a low power, reliable, IoT solution. Once you’ve gotten to the point where you have proven all the great attributes of your SmartMesh IP network, you may want to integrate your project into a complete end-to-end IoT solution. A great deal of that end to end solution exists outside of your SmartMesh IP network and outside the parts you can buy from Linear Technology. There are infinitely many choices you can make there, and the vast array of choices might make it hard to figure out where to start.
In this recipe, I’ll show you two different ways I’ve used to access my SmartMesh IP network over the Internet, from anywhere. These quick and easy methods to provide around-the-world connectivity to your SmartMesh IP network are not intended to be free turnkey solutions to what your product might look like. They are intended to be examples you can use to execute a demonstration, access a pilot network remotely, or do a proof-of-concept for your project.
Option 1. Using Weaved to access a Raspberry Pi that is connected to a SmartMesh IP network
My setup:
- A new Raspberry Pi 2, running Raspbian
- A SmartMesh IP starter kit (1 manager + 5 motes)
Step 1: Plug in the Raspberry Pi and plug it into Ethernet
I have my Raspberry Pi plugged into the LAN in my office. I connected the HDMI output to a monitor so I can see the IP address it picked up from the DHCP server. It is possible to configure your Raspberry Pi to email you its IP address as soon as it boots up. That’s a really handy technique that I will possibly write up in another recipe.
Step 2: SSH into your Pi
I use PuTTY to start an SSH session to my Pi. The absolute first thing I do is change the password for the pi user from raspberry
to something else. It’s probably a good idea to assign a new hostname
as well so you can tell multiple Pi’s apart.
Step 3: Get a free account on Weaved.com
Go to www.weaved.com, sign up for a free account. Keep the browser open, because we’ll use that in a couple minutes.
Step 4: Download and install Weaved to your pi.
In that SSH session window, type the command:
wget https://github.com/weaved/installer/raw/master/binaries/weaved-nixinstaller_1.2.13.bin
I have an Ethernet connected pi and it took about 20 seconds to download the installer. Make that file executable with the command:
chmod +x weaved-nixinstaller_1.2.13.bin
Install with this command:
./weaved-nixinstaller_1.2.13.bin
The installer will detect what kind of Pi you have, but you have to confirm for it to proceed. It will test the connection to the weaved server to make sure everything is going to work. I’ve done this at home and in my office and it worked both places. I imagine there may be LAN setups that are not compatible, and this recipe has no guidance on how to troubleshoot that.
If everything is OK, the installer gives you a list of choices for what kind of connection you want to enable. You can have multiple connections enabled if you like, by just running the installer multiple times. In this example, let’s just allow SSH on port 22. That is choice #1. You will have to enter your weaved username and password, and you will be prompted to assign an alias for your device. I gave mine the name “bubbalinear.orangepi2.com”.
That’s it! You now have the setup to allow you to connect to the linux shell of your Pi from anywhere in the world, anytime you like.
Step 5: Actually connecting from anywhere
Now, from any web browser anywhere, you can sign in to weaved and see your registered devices on a list. You can request a connection which will open up a port for 30 minutes. The site will give you a URL and port number that you can use from your SSH client to connect to your Pi. I use both the weaved.com website and the weaved iphone app to do this. With a free account, you can only stay connected for 30 minutes, but that is enough time to check on the network stats of your SmartMesh IP network or run some tests. It’s quite useful!
Option 2: Using ngrok
to port forward content from your Raspberry Pi to anywhere
One of the free example applications that Linear provides is DustLink. DustLink is a Python-based application that can connect to the SmartMesh IP manager and display information about that network as a webpage. Typically, you run DustLink on a computer that is connected to the SmartMesh IP manager, and you view the webpage on that same computer, pointing your browser to http://localhost:8080
. ngrok
is another piece of free software that opens up sockets between computers. Now you can plug your manager into Raspberry Pi, and run DustLink on Raspberry Pi, and view that DustLink webpage from any browser anywhere in the world.
My setup is exactly the same. I have a manager plugged into a USB port of my Raspberry Pi.
Step 1. Plug in Pi into Ethernet and note its IP address
Step 2. Download ngrok.zip from ngrok.com
Go to www.ngrok.com. This is an open source project and you pay what you want. There is no sign up, and no fees. Download the appropriate zip file to your PC. I used ngrok_2.0.19_linux_arm.zip
.
Step 3. Move ngrok.zip to your Pi.
I used WinSCP
to move the zip file to my Pi. The only installation is unzipping it with the command:
unzip ngrok_2.0.19_linux_arm.zip
Step 4. Get DustLink Running
If you already have DustLink installed on your pi, start it up. If not, follow the instructions on the earlier recipe getting DustLink running on your Pi.
Step 5. Generate an ngrok
url
Dustlink is running on http://localhost:8080
. To forward that to the outside world, use the command:
./ngrok http 8080
ngrok
will generate for you a url that you can use from any browser, anywhere in the world to view the DustLink webpage that is running on your Pi. You probably should not give this url to an enormous group of people, but if I want to show a network that has been running for a long time, it is very useful to do the deployment in advance.