Reader small image

You're reading from  Hands-On Internet of Things with MQTT

Product typeBook
Published inOct 2019
Reading LevelIntermediate
PublisherPackt
ISBN-139781789341782
Edition1st Edition
Languages
Tools
Right arrow
Author (1)
Tim Pulver
Tim Pulver
author image
Tim Pulver

Tim Pulver is a Berlin-based freelance interaction designer and developer. In his work, he combines his physical prototyping experience and knowledge of interface design with modern technologies such as 3D printing, laser cutting, web technologies, and machine learning to create unique interactive experiences. In recent years, he has worked on interactive data visualizations, web-based audiovisual experiences, musical interfaces, and cables an innovative browser-based visual programming language that enables the creation of interactive audiovisual prototypes without writing any code. He holds a Bachelor of Arts degree in interface design from the University of Applied Sciences in Potsdam, Germany.
Read more about Tim Pulver

Right arrow

Assessments

Chapter 1: The Internet of Things in a Nutshell

  1. Some technologies associated with IoT are smart homes, smart cars, and IIoT/Industry 4.0.
  2. Voice user interfaces such as Alexa and Siri are used more and more to control internet-connected devices.
  3. It does not make sense to make every device smart. The more features a device has, the more likely it is for problems to appear. Would you rather have a traditional vacuum cleaner that works 99% of the time, or a vacuum cleaner that only works when a wireless network connection is available but that shows its status in an app?
  4. Prototypes are used to find out if your idea works or not. They can be developed in a quick and dirty way and are all about getting the desired result fast.
  5. No! The beautiful thing about prototyping is that you don't need to be an expert in every area—especially in the Arduino community, where you will find code snippets and diagrams for most common sensors and actuators. Combining example snippets and adding a little bit of logic to the code might do the job for a first version. 

Chapter 2: Basic Architecture of an IoT Prototype

  1. We are living in exciting times! There are a lot of development boards available that are suitable for IoT prototyping. These include the Arduino MKR WiFi 1010, the Raspberry Pi 3 Model B+, M5Stack, NodeMCU, and the Particle Argon, Boron, and Xenon.
  1. Depending on what you plan on building, picking a development board that runs on 3.3V or 5V might be better. If you want to work with Neopixel LEDs, for example, then picking a 5V development board is easier. But the trend is moving toward 3.3V. With a level shifter/logic level converter, you can use 5V modules together with a 3.3V development board, as well.
  2. ZigBee, Thread, CoAP, and MQTT are used for IoT communication.
  3. Some development boards support over-the-air updates, which means that their firmware can be updated without a cable connection, using a wireless internet connection instead.

Chapter 3: Getting Started with MQTT

  1. You can send MQTT messages via Mosquitto using the mosquitto_pub -t "/test" -m "Your message" command.
  2. You can subscribe to MQTT messages via Mosquitto using the mosquitto_sub -t "/test" command.
  3. The -t parameter stands for topic.
  4. The -m parameter, which you have to use when sending messages, stands for message.
  5. Please explore for yourself.

Chapter 4: Setting Up a Lab Environment

  1. To publish an MQTT message with a Hello payload to the /test topic, you have to run mosquitto_pub -t "/test" -m "Hello!" in the Terminal.
  2. To subscribe to MQTT messages that are sent to the /test channel, you have to run mosquitto_sub -t "/test" in the Terminal.
  3. The -t command-line flag stands for topic.
  4. The -m command-line flag stands for message.
  5. This is an exploratory exercise. Go to https://shiftr.io/explore and have a look around.
  6. This is an exploratory exercise.
  1. This is an exploratory exercise. If you are having problems, note that, in the hands-on chapters, we will make use of third-party apps to send and receive MQTT messages together.

Chapter 5: Building Your Own Automatic Pet Food Dispenser

  1. The # character is called a multi-level wildcard. By using it, we subscribe to all subtopics of the topic.
  2. In this project, we are using the public namespace with the try/try login credentials. It is neither secure nor private, and we just use it because it is easier and more tolerable for a prototype. If you want more security and privacy for your data, you need to use a private channel on Shiftr (or any other MQTT server with private channel functionality).
  3. If Shiftr stops working at some point, you can just move on to another (free) MQTT server (a list can be found at https://github.com/mqtt/mqtt.github.io/wiki/public_brokers). This is the beauty of MQTT: there are many implementations, and you can easily move on to another provider or simply create your own (local) server.
  4. You can control the smart pet food dispenser from any MQTT client. MQTT clients come in many shapes and sizes. You can control it using the Terminal (for example, using Mosquitto, which we installed in Chapter 3Getting Started with MQTT), using iOS or Android apps, or using macOS and Windows apps. You can also create a new Arduino project that also uses MQTT, and easily let the two Arduinos communicate using MQTT in the same way.
  5. Writing as little code as possible is the most efficient way of making your ideas a reality. When you find tiny examples or code snippets that solve parts of your problems, you should try to combine them instead of writing all of the code from scratch. You will be faster this way: you don't need to be an expert, and mostly using code that has been used by other people means that it will probably work when you use it.
  6. You really don't need to be an expert to build breathtaking prototypes. In the physical prototyping workshops I've held, many people who have never written code before built awesome prototypes anyway by combining examples, adding some code to glue them together, and making it look nice by spending time on building a case and hiding the (often ugly-looking) inner workings of the prototype.
  1. Please don't bet the life of your pet on your prototype working. As stated before, it is not secure, can probably fail in other ways, and should just be used as a prototype.
  2. There are many more things that you can build using just a servomotor and the techniques we used. Have a brainstorming session and try to come up with five ideas.

Chapter 6: Building a Smart E-Ink To-Do List

  1. QoS stands for quality of service. It was introduced in Chapter 3, Getting Started with MQTT.
  2. QoS 1 is a good compromise for our use case between reliability and performance. With QoS 1, we can be sure messages are delivered (if the other end also uses QoS 1 or 2).
  3. MQTT is an open protocol, so there are libraries for every programming language, more or less. There are also a lot of pre-made third-party applications for Android, iOS, macOS, Windows, Linux, and the web, which you can use. All you have to do is specify the login credentials of the MQTT server you are using (in our case, https://shiftr.io/).
  4. A client ID is basically the name of the MQTT client, as seen in the network. The MQTT server stores messages to be sent, as well as subscriptions for each client ID. Don't confuse this with the MQTT username and password: these are just for authentication.
  5. There can be only one loop and one setup function for each Arduino sketch. If you combine various examples into one, you need to make sure that you integrate the code accordingly. Having two functions with the same name will result in a compile-time error.
  6. There are many examples given in Chapter 3Getting Started with MQTT, for MQTT apps on various platforms. You are missing out on all of the fun if you do not try them out. Third-party MQTT apps allow you to build your own user interfaces to control your smart devices without having to learn another programming language.
  7. When using your own login on https://shiftr.io/, you can activate private namespaces, so other MQTT clients cannot see what you send and cannot interfere with your namespace.

Chapter 7: Build a Smart Productivity Cube, Part 1

  1. Tilt switches contain a small metal ball inside that closes an electronic connection when held in one specific position. If the tilt switch is placed flat, the small metal ball can go either way; when you read it, the result might be either HIGH or LOW—you get random readings. When working with tilt switches, you should make sure that the small metal ball inside is always in a stable position by using appropriate angles in your construction.

Chapter 8: Building a Smart Productivity Cube, Part 2

  1. MQTT apps for iOS and Android can be used to both display and send MQTT messages. Their purpose is to build a personal dashboard that allows you to consume all of the important information published by your MQTT devices and to control them by publishing messages as well.
  2. To send just the activity time (without the activity name), you have to change the client.publish("/tims-channel/cube/activity", text); line to client.publish("/tims-channel/cube/activity", timeSpend);.
  3. A good client ID, to be compatible with most MQTT clients and servers, should be no longer than 23 characters and only contain regular characters (a-z, 0-9, and -). Also, you should make sure that nobody else is using the same name on the same MQTT server. The easiest way is just by appending a few random digits to your client ID (for example, your-name-184638).
lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Internet of Things with MQTT
Published in: Oct 2019Publisher: PacktISBN-13: 9781789341782
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Tim Pulver

Tim Pulver is a Berlin-based freelance interaction designer and developer. In his work, he combines his physical prototyping experience and knowledge of interface design with modern technologies such as 3D printing, laser cutting, web technologies, and machine learning to create unique interactive experiences. In recent years, he has worked on interactive data visualizations, web-based audiovisual experiences, musical interfaces, and cables an innovative browser-based visual programming language that enables the creation of interactive audiovisual prototypes without writing any code. He holds a Bachelor of Arts degree in interface design from the University of Applied Sciences in Potsdam, Germany.
Read more about Tim Pulver