Mozilla Iot



The Mozilla IoT team recently released the Things Framework, which allows you to build IoT devices that speak the Web Thing API. Last week, James built an ESP8266 web thing. This time, I’m going to show you how to build web things with Python, Node.js, or Java. These languages are definitely not optimal for small embedded devices; this tutorial is intended for higher-end devices that can run these languages with ease, or even your own desktop computer.

IoT devices that use face recognition include iPads, Xboxes, and video systems. One possible solution? A secure router can help safeguard your network and your connected devices, which in turn could help protect your facial image. How can you find more protection against facial recognition systems? Will hackers really want to steal your face? An open platform for monitoring and controlling devices over the web.

To demonstrate, we’ll be turning the Music Player Daemon (MPD) into a web thing. The libraries we’ll be using here are webthing-python, webthing-node, and webthing-java.

Mozilla Iot Gateway

Intro to the Music Player Daemon (MPD)

The Music Player Daemon is an open-source music player that has been around since 2003. MPD operates in a client/server model, and is controllable over TCP with a simple text-based protocol. I won’t cover installation here, but MPD can be installed via your package manager on Linux, Homebrew on Mac OS X, or with binaries on Windows.

Mozilla Iot

Some Quick Notes

Although this example is written for MPD, it would be easily portable to other music players with an API, or you could build your own player using this example as a base. More importantly, this example is primarily meant to demonstrate the Things Framework, which can be used to create an endless variety of web things.

The Python, Node.js, and Java web thing libraries all have essentially the same API. While they may not be entirely idiomatic for their respective languages, doing this allows us to maintain all the libraries more easily, which is incredibly valuable while the Web Thing API is still a living draft.

Getting Started

To start, initialize an empty project for your language of choice. For example, you might create a new project in IntelliJ IDEA for Java, or run npm init to start a new Node.js project. You’ll then want to add the webthing library as a dependency. Instructions for doing so can be found on the respective Github project page, or you can look here.

Now we’re ready to write some code. Essentially we’ll do the following:

  1. Create a Thing.
    1. Define its properties.
    2. Define its actions.
    3. Define its events.
  2. Attach the Thing to a WebThingServer.

Create a Thing

First off, let’s import our library of choice.

Now, we’ll create a basic subclass of Thing.

Add Properties

Now that we have our MPDThing, we’ll need to add some properties to it. Obviously, a music player will have quite a few properties. To demonstrate, I will show you how to add one, and I’ll link to the rest of the code at the end of this post.

To add a property, you can do the following inside the MPDThing constructor.

We’ve now created a Property that allows us to GET and PUT the playback volume. The Value piece is an object that essentially stores a cached value and a “value forwarder” callback. When the volume is set via a PUT request, the value forwarder is used to forward the new value to the actual device, which in this case is the MPD server. We’ve also set up some metadata for the property, including a description, value type, and a minimum and maximum value.

Add Actions

A music player can also have a lot of actions. While the MPD web thing has several basic actions like play, pause, and skip, I’ve added one that takes some additional input, which will queue a series of random songs. Action inputs are verified with a JSON Schema validator.

First, let’s create an Action subclass.

QueueRandomAction takes an input, count, queues that number of random songs to the current playlist, and then emits a PlaylistUpdatedEvent (to be defined shortly). To add this new action to our MPDThing, do the following inside the MPDThing constructor:

Add Events

The final piece of our Thing is its events. Since MPD is a client/server model, it can be updated externally by any number of other clients. As such, I created an event that will fire when the current playlist is updated.

As with Thing and Action, we’ll create an Event subclass.

This is a basic Event. The data member will be filled in with a string representation of the current playlist.

To add this Event to our thing, we’ll do the following in the MPDThing constructor:

Create a WebThingServer

Now that we have a thing with properties, actions, and events, we’ll create a WebThingServer and attach the MPDThing to it.

Controlling the Web Thing

Our web thing is complete and it’s now controllable via the Web Thing API. Here’s how to add it to the Things Gateway:

Expanded Thing UI
Add New Thing

New Thing Displayed
Empty Things Screen

The Things Gateway doesn’t currently provide a way to use actions or display events, but those are in the works.

Alternatively, you can control the web thing via cURL or any other HTTP library you choose:

Wrapping Up

Mozilla webthings gateway

Your imagination is really your only limit as to what you can turn into a web thing. If you’d like to see the rest of this example and how the actual MPD controls are implemented, all of the code is available on Github.

If you have any questions or suggestions, you can head over to Discourse or find us in #iot on irc.mozilla.org. Additionally, feel free to create issues, or even better, submit pull requests, to the webthing library repositories!

Mozilla Iot Gateway Login

About Michael Stegeman

Michael is a software engineer at Mozilla working on WebThings.

The Internet of Things is a lot like it sounds. The IoT is a growing system of billions of devices — or things — worldwide that connect to the internet and to each other through wireless networks.

What are some examples of IoT devices, and how do they work?

Although the name “Internet of Things” may be unfamiliar, you may recognize this connected ecosystem better as “smart homes” or “connected homes,” which include the various IoT devices that make your home life easier. But IoT devices are also found outside the home. They can range from a Wi-Fi pet camera on your bookshelf to a medical device implanted in your body, like a pacemaker. As long as the device is able to connect to the internet and has sensors that transmit data, it can be considered an IoT device. Although your smartphone can do both, it’s not an IoT device.

How do IoT devices work?

Smartphones do play a large role in the IoT, however, because many IoT devices can be controlled through an app on a smartphone. You can use your smartphone to communicate with your smart thermostat, for example, to deliver the perfect temperature for you by the time you get home from work. Another plus? This can eliminate unneeded heating or cooling while you’re away, potentially saving you money on energy costs.

Mozilla Iot Supported Devices

IoT devices contain sensors and mini-computer processors that act on the data collected by the sensors via machine learning. Essentially, IoT devices are mini computers, connected to the internet, and are vulnerable to malware and hacking.

Machine learning is when computers learn in a similar way to humans — by collecting data from their surroundings — and it is what makes IoT devices smart. This data can help the machine learn your preferences and adjust itself accordingly. Machine learning is a type of artificial intelligence that helps computers learn without having to be programmed by someone.

That doesn’t mean your smart speaker will discuss the key points of last night’s big game with you. But your connected refrigerator may send you an alert on your smartphone that you’re low on eggs and milk because it knows you’re near a supermarket.

What are the benefits of the IoT?

The Internet of Things is designed to make our lives more convenient. Here are a few examples:

  • Smart bathroom scales working in tandem with your treadmill, delivering food preparation ideas to your laptop or smartphone, so you stay healthy.
  • Security devices monitoring your home, turning lights on and off as you enter and exit rooms, and streaming video so you can check in while you’re away.
  • Smart voice assistants placing your usual takeout order on command, making it a breeze to get fresh food delivered to your door.

The history and future of IoT

It’s not science fiction. We are living connected lives filled with internet-enabled devices that learn our preferences and provide the experiences we want to make our lives more convenient. And the technology that makes it possible to connect our lives is expanding.

It all started in the early 1980s when Carnegie Mellon University students developed the first internet-connected device. It was a Coke vending machine that would tell the programmers if the soda was cold enough for them to want to make the trip from their desks to the machine.

Since then, the IoT has exploded. What about the future? Devices are growing smaller and smarter. Eventually, everything from your toothbrush to your toaster may be connected to the internet 24x7. Your gadgets will become household aides, each chatting with one another, working to serve you better.

IoT security and privacy: What you need to know

What could go wrong? As with any technology, there’s the potential for good and bad.

Convenience is good. But connectedness can also open the door to cybercriminals. Cyberattacks already access data like bank logins, credit card numbers, and more. Strong security is essential.

Mozilla Iot Vs Home Assistant

Consider some of the potential risks of IoT — and those mini CPUs. What if someone hacks your IoT security cameras and watches your every move? What if a cybercriminal commandeers your smart TV, smoke alarms, or front-door lock? Connectedness can create vulnerabilities.

It’s smart to help ensure these connections stay safe and secure — just like you protect yourself against cybercrime. The Internet of Things will continue to open up opportunities for new online threats.

One of the best ways to help defend your networked devices is to make sure that your router is secure. That way, it can protect your entire home Wi-Fi network and the devices connected to it. Think of your Wi-Fi router as the front door to your online world.

Cyber threats have evolved, and so have we.

Norton 360™ with LifeLock™, all-in-one, comprehensive protection against viruses, malware, identity theft, online tracking and much, much more.


Editorial note: Our articles provide educational information for you. NortonLifeLock offerings may not cover or protect against every type of crime, fraud, or threat we write about. Our goal is to increase awareness about cyber safety. Please review complete Terms during enrollment or setup. Remember that no one can prevent all identity theft or cybercrime, and that LifeLock does not monitor all transactions at all businesses.

Mozilla Iot Gateway

Copyright © 2021 NortonLifeLock Inc. All rights reserved. NortonLifeLock, the NortonLifeLock Logo, the Checkmark Logo, Norton, LifeLock, and the LockMan Logo are trademarks or registered trademarks of NortonLifeLock Inc. or its affiliates in the United States and other countries. Firefox is a trademark of Mozilla Foundation. Android, Google Chrome, Google Play and the Google Play logo are trademarks of Google, LLC. Mac, iPhone, iPad, Apple and the Apple logo are trademarks of Apple Inc., registered in the U.S. and other countries. App Store is a service mark of Apple Inc. Alexa and all related logos are trademarks of Amazon.com, Inc. or its affiliates. Microsoft and the Window logo are trademarks of Microsoft Corporation in the U.S. and other countries. The Android robot is reproduced or modified from work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License. Other names may be trademarks of their respective owners.