0% found this document useful (0 votes)
13 views59 pages

Hands On MQTT Programming with Python Gaston C. Hillar download

The document is a promotional overview of the book 'Hands-On MQTT Programming with Python' by Gaston C. Hillar, which focuses on using the MQTT protocol with Python for IoT applications. It outlines the book's content, including installation of the Mosquitto server, security practices, and practical examples for controlling devices and monitoring events. Additionally, it provides links to download the book and related resources from the publisher's website.

Uploaded by

pkeyctvekt9769
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views59 pages

Hands On MQTT Programming with Python Gaston C. Hillar download

The document is a promotional overview of the book 'Hands-On MQTT Programming with Python' by Gaston C. Hillar, which focuses on using the MQTT protocol with Python for IoT applications. It outlines the book's content, including installation of the Mosquitto server, security practices, and practical examples for controlling devices and monitoring events. Additionally, it provides links to download the book and related resources from the publisher's website.

Uploaded by

pkeyctvekt9769
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Hands On MQTT Programming with Python Gaston C.

Hillar download

https://textbookfull.com/product/hands-on-mqtt-programming-with-
python-gaston-c-hillar/

Download full version ebook from https://textbookfull.com


We believe these products will be a great fit for you. Click
the link to download now, or visit textbookfull.com
to discover even more!

Swift 3 Object Oriented Programming Gaston C. Hillar

https://textbookfull.com/product/swift-3-object-oriented-
programming-gaston-c-hillar/

Internet of Things with Python 1st Edition Gastón C.


Hillar

https://textbookfull.com/product/internet-of-things-with-
python-1st-edition-gaston-c-hillar/

Python Programming For Beginners: Python Mastery in 7


Days: Top-Secret Coding Tips with Hands-On Exercises
for Your Dream Job 1st Edition Oswald Thornton

https://textbookfull.com/product/python-programming-for-
beginners-python-mastery-in-7-days-top-secret-coding-tips-with-
hands-on-exercises-for-your-dream-job-1st-edition-oswald-
thornton/

Python Crash Course A Hands On Project Based


Introduction to Programming 2nd Edition Eric Matthes

https://textbookfull.com/product/python-crash-course-a-hands-on-
project-based-introduction-to-programming-2nd-edition-eric-
matthes/
Programming for Game Design: A Hands-On Guide with
Godot 1st Edition Wang

https://textbookfull.com/product/programming-for-game-design-a-
hands-on-guide-with-godot-1st-edition-wang/

Hands-on Scikit-Learn for machine learning


applications: data science fundamentals with Python
David Paper

https://textbookfull.com/product/hands-on-scikit-learn-for-
machine-learning-applications-data-science-fundamentals-with-
python-david-paper/

Hands On Start to Wolfram Mathematica And Programming


with the Wolfram Language Cliff Hastings

https://textbookfull.com/product/hands-on-start-to-wolfram-
mathematica-and-programming-with-the-wolfram-language-cliff-
hastings/

Programming for Game Design: A Hands-On Guide with


Godot 1st Edition Wallace Wang

https://textbookfull.com/product/programming-for-game-design-a-
hands-on-guide-with-godot-1st-edition-wallace-wang/

Programming for Game Design: A Hands-On Guide with


Godot 1st Edition Wallace Wang

https://textbookfull.com/product/programming-for-game-design-a-
hands-on-guide-with-godot-1st-edition-wallace-wang-2/
Hands-On MQTT Programming with Python

Work with the lightweight IoT protocol in Python

Gaston C. Hillar
BIRMINGHAM - MUMBAI
Hands-On MQTT
Programming with Python
Copyright © 2018 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or
transmitted in any form or by any means, without the prior written permission of the publisher,
except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information
presented. However, the information contained in this book is sold without warranty, either express
or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable
for any damages caused or alleged to have been caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and
products mentioned in this book by the appropriate use of capitals. However, Packt Publishing
cannot guarantee the accuracy of this information.

Commissioning Editor: Kunal Choudhari


Acquisition Editor: Reshma Raman
Content Development Editor: Aditi Gour
Technical Editor: Sushmeeta Jena
Copy Editor: Safis Editing
Project Coordinator: Hardik Bhinde
Proofreader: Safis Editing
Indexer: Tejal Daruwale Soni
Graphics: Jason Monteiro
Production Coordinator: Shraddha Falebhai

First published: May 2018

Production reference: 1180518

Published by Packt Publishing Ltd.


Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.

ISBN 978-1-78913-854-2
www.packtpub.com
mapt.io

Mapt is an online digital library that gives you full access to


over 5,000 books and videos, as well as industry leading tools
to help you plan your personal development and advance your
career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with
practical eBooks and Videos from over 4,000 industry
professionals

Improve your learning with Skill Plans built especially


for you

Get a free eBook or video every month

Mapt is fully searchable

Copy and paste, print, and bookmark content


PacktPub.com
Did you know that Packt offers eBook versions of every book
published, with PDF and ePub files available? You can upgrade
to the eBook version at www.PacktPub.com and, as a print book
customer, you are entitled to a discount on the eBook copy. Get
in touch with us at [email protected] for more details.

At www.PacktPub.com, you can also read a collection of free technical


articles, sign up for a range of free newsletters, and receive
exclusive discounts and offers on Packt books and eBooks.
About the Author
Gaston C. Hillar is Italian and has been working with
computers since he was 8 years old. Gaston has a bachelor's
degree in computer science (graduated with honors) and an
MBA. He is the CTO of Mapgenix, a freelance author, and a
speaker.

He has been a senior contributing editor at Dr. Dobb's and has


written more than a hundred articles on software development
topics. He has received the prestigious Intel® Black Belt
Software Developer award eight times.

He lives with his wife, Vanesa, and his two sons, Kevin and
Brandon.

Acknowledgements:

While writing this book, I was fortunate to work with an excellent team at Packt, whose
contributions vastly improved the presentation of this book. Reshma Raman allowed me to provide
her ideas to write a book dedicated to MQTT programming with Python, and I jumped into this
exciting project. Aditi Gour helped me realize my vision for this book and provided many sensible
suggestions regarding the text, the format, and the flow. The reader will notice her great work. It′s
been great working with Reshma on another project and I can't wait to work with Reshma and
Aditi again. I would like to thank my technical reviewers and proofreaders for their thorough
reviews and insightful comments. I was able to incorporate some of the knowledge and wisdom
they have gained in their many years in the software development industry. This book was possible
because they gave valuable feedback.

The entire process of writing a book requires a huge number of lonely hours. I wouldn't be able to
write an entire book without dedicating some time to play soccer against my sons, Kevin and
Brandon, and my nephew, Nicolas. Of course, I never won a match. However, I did score a few
goals! Of course, I'm talking about real-life soccer, but I must also include virtual soccer when the
weather didn't allow us to kick a real-life ball.
About the reviewer
Ben Howes is the founder and lead consultant at Zoetrope
Ltd, a specialist IoT consultancy
and product development firm in the UK. Ben has been
creating connected hardware for
over 10 years and has worked across projects spanning from
start-ups to multinational
deployments.

I'd like to thank Richard Webb, my cofounder, for starting Zoetrope with me.
Packt is searching for
authors like you
If you're interested in becoming an author for Packt, please
visit authors.packtpub.com and apply today. We have worked with
thousands of developers and tech professionals, just like you, to
help them share their insight with the global tech community.
You can make a general application, apply for a specific hot
topic that we are recruiting an author for, or submit your own
idea.
Preface
MQTT is the preferred IoT publish-subscribe lightweight
messaging protocol. Python is definitely one of the most
popular programming languages. It is open source,
multiplatform, and you can use it to develop any kind of
application. If you develop IoT, web applications, mobile apps,
or a combination of these solutions, you must learn how MQTT
and its lightweight messaging system works. The combination
of Python and MQTT makes it possible to develop powerful
applications that communicate with sensors, different devices,
and other applications. Of course, it is extremely important to
take security into account when working with this protocol.

Most of the time, when you work with complex IoT solutions
coded in modern Python 3.6, you will use different IoT boards
that might use diverse operating systems. MQTT has its own
specific vocabulary and different working modes. Learning
MQTT is challenging, because it includes too many abstract
concepts that require real-life examples to be easy to
understand.

This book will allow you to dive deep in to the latest version of
the MQTT protocol: 3.1.1. You will learn to work with the most
recent Mosquitto MQTT server, command-line tools, and GUI
tools to allow you to understand how everything works with
MQTT and the possibilities that this protocol provides for your
projects. You will learn security best practices and use them for
a Mosquitto MQTT server.
Then, you will work with many real-life examples in Python
3.6. You will control a vehicle, process commands, interact with
actuators, and monitor a surf competition by exchanging
MQTT messages with the Eclipse Paho MQTT client library.
You will also work with a cloud-based, real-time MQTT
provider.

You will be able to run the examples on a wide range of modern


IoT boards, such as Raspberry Pi 3 Model B+, Qualcomm
DragonBoard 410c, BeagleBone Black, MinnowBoard Turbot
Quad-Core, LattePanda 2G, and UP Core 4GB. However, any
other board that supports Python 3.6 will be able to run the
samples.
Who this book is for
This book is aimed at Python developers who want to develop
applications that can interact with other applications and
devices, such as IoT boards, sensors, and actuators.
What this book covers
Chapter 1 , Installing an MQTT 3.1.1 Mosquitto Server, starts our
journey toward the usage of the preferred IoT publish-
subscribe lightweight messaging protocol in diverse IoT
solutions, combined with mobile apps and web applications.
We will learn how MQTT and its lightweight messaging system
work. We will understand the MQTT puzzle: clients, servers
(formerly known as brokers), and connections. We will learn
the procedures to install an MQTT 3.1.1 Mosquitto server in
Linux, macOS, and Windows. We will learn special
considerations for running a Mosquitto server on the Cloud
(Azure, AWS, and other cloud providers).

Chapter 2 , Using Command-Line and GUI Tools to Learn How


MQTT Works, teaches us to work with command-line and GUI
tools to learn how MQTT works in detail. We will learn MQTT
basics, the specific vocabulary for MQTT, and its working
modes. We will use different utilities and diagrams to
understand the most important concepts related to MQTT. We
will understand everything we need to know before writing
Python code to work with the MQTT protocol. We will work
with the different Quality of Service levels, and we will analyze
and compare their overheads.
Chapter 3 , Securing an MQTT 3.1.1 Mosquitto Server, focuses on
how to secure an MQTT 3.1.1 Mosquitto server. We will make
all the necessary configurations to work with digital certificates
to encrypt all the data sent between the MQTT clients and the
server. We will use TLS, and we will learn to work with client
certificates for each MQTT client. We will also learn to force the
desired TLS protocol version.

Chapter 4 , Writing Code to Control a Vehicle with Python and


MQTT Messages, focuses on writing Python 3.x code to control
a vehicle with MQTT messages delivered through encrypted
connections (TLS 1.2). We will write code that will be able to
run on different popular IoT platforms, such as a Raspberry Pi
3 board. We will understand how we can leverage our
knowledge of the MQTT protocol to build a solution based on
requirements. We will learn to work with the latest version of
the Eclipse Paho MQTT Python client library.

Chapter 5 , Testing and Improving Our Vehicle Control Solution


in Python, outlines using our vehicle control solution with
MQTT messages and Python code. We will learn how to process
commands received in MQTT messages with Python code. We
will write Python code to compose and send MQTT messages
with commands. We will work with the blocking and threaded
network loops, and we will understand the difference between
them. Finally, we will take advantage of the last will and
testament feature.
Chapter 6 , Monitoring a Surfing Competition with Cloud-Based
Real-Time MQTT Providers and Python, gets you started with
writing Python code to use the PubNub cloud-based, real-time
MQTT provider in combination with a Mosquitto MQTT server
to monitor a surfing competition. We will build a solution from
scratch by analyzing the requirements, and we will write
Python code that will run on waterproof IoT boards connected
to multiple sensors in surfboards. We will define the topics and
commands, and we will work with a cloud-based MQTT server,
in combination with the Mosquitto MQTT server used in the
previous chapters.

, Solutions, the right answers for the Test Your


Appendix

Knowledge sections of each chapter are included in the


appendix.
To get the most out of this
book
You need a basic knowledge of Python 3.6.x and IoT boards.
Download the example
code files
You can download the example code files for this book from
your account at www.packtpub.com. If you purchased this book
elsewhere, you can visit www.packtpub.com/support and register to
have the files emailed directly to you.

You can download the code files by following these steps:

1. Log in or register at www.packtpub.com.


2. Select the SUPPORT tab.
3. Click on Code Downloads & Errata.
4. Enter the name of the book in the Search box and follow
the onscreen instructions.

Once the file is downloaded, please make sure that you unzip or
extract the folder using the latest version of:

WinRAR/7-Zip for Windows

Zipeg/iZip/UnRarX for Mac

7-Zip/PeaZip for Linux


The code bundle for the book is also hosted on GitHub at http
s://github.com/PacktPublishing/Hands-On-MQTT-Programming-with-Python . In
case there's an update to the code, it will be updated on the
existing GitHub repository.

We also have other code bundles from our rich catalog of books
and videos available at https://github.com/PacktPublishing/. Check
them out!
Download the color images
We also provide a PDF file that has color images of the
screenshots/diagrams used in this book. You can download it
here: http://www.packtpub.com/sites/default/files/downloads/HandsOnMQTTProgr
.
ammingwithPython_ColorImages.pdf
Conventions used
There are a number of text conventions used throughout this
book.

CodeInText : Indicates code words in text, database table names,


folder names, filenames, file extensions, pathnames, dummy
URLs, user input, and Twitter handles. Here is an example:
"Mount the downloaded WebStorm-10*.dmg disk image file as
another disk in your system."

A block of code is set as follows:

@staticmethod
def on_subscribe(client, userdata, mid, granted_qos):
print("I've subscribed with QoS: {}".format(
granted_qos[0]))

When we wish to draw your attention to a particular part of a


code block, the relevant lines or items are set in bold:

time.sleep(0.5)
client.disconnect()
client.loop_stop()

Any command-line input or output is written as follows:


sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa

Bold: Indicates a new term, an important word, or words that


you see onscreen. For example, words in menus or dialog boxes
appear in the text like this. Here is an example: "Select System
info from the Administration panel."

Warnings or important notes appear like this.

Tips and tricks appear like this.


Get in touch
Feedback from our readers is always welcome.

General feedback: Email [email protected] and mention the


book title in the subject of your message. If you have questions
about any aspect of this book, please email us at
[email protected].

Errata: Although we have taken every care to ensure the


accuracy of our content, mistakes do happen. If you have found
a mistake in this book, we would be grateful if you would report
this to us. Please visit www.packtpub.com/submit-errata, selecting your
book, clicking on the Errata Submission Form link, and
entering the details.

Piracy: If you come across any illegal copies of our works in


any form on the Internet, we would be grateful if you would
provide us with the location address or website name. Please
contact us at [email protected] with a link to the material.

If you are interested in becoming an author: If there is a


topic that you have expertise in and you are interested in either
writing or contributing to a book, please visit authors.packtpub.com.
Reviews
Please leave a review. Once you have read and used this book,
why not leave a review on the site that you purchased it from?
Potential readers can then see and use your unbiased opinion
to make purchase decisions, we at Packt can understand what
you think about our products, and our authors can see your
feedback on their book. Thank you!

For more information about Packt, please visit packtpub.com.


Installing an MQTT 3.1.1
Mosquitto Server
In this chapter, we will start our journey toward using the
preferred IoT publish-subscribe lightweight messaging
protocol in diverse IoT solutions, combined with mobile apps
and web applications. We will learn how MQTT and its
lightweight messaging system work.

We will understand the MQTT puzzle: clients, servers (formerly


known as brokers), and connections. We will learn the
procedures to install an MQTT 3.1.1 Mosquitto server in Linux,
macOS, and Windows. We will learn special considerations for
running a Mosquitto server in the cloud (Azure, AWS, and
other cloud providers). We will gain an understanding of the
following:

Understanding convenient scenarios for the MQTT


protocol

Working with the publish-subscribe pattern

Working with message filtering

Understanding the MQTT puzzle: clients, servers, and


connections
Installing a Mosquitto server on Linux

Installing a Mosquitto server on macOS

Installing a Mosquitto server on Windows

Considerations for running a Mosquitto server in the


cloud
Other documents randomly have
different content
Fig. 111.—Busold’s chromatic top.

More complicated contrivances have also been constructed on the


same principle, by which one may perceive the rotating disc through
slits which turn at the same time. We will now describe the
construction of some discs invented by Plateau under the name of
the Phenakistoscope. These discs are made of strong cardboard,
from six to ten inches in diameter (fig. 112), on which a certain
number of figures (eight to twelve) are placed in circles at an equal
distance from each other, presenting the successive phases of a
periodical movement. This disc is placed on another opaque circle of
rather larger diameter, which has on its margin as many openings as
the first disc has figures. The two discs are placed one on the other,
and are fixed in the centre by means of a screw at the anterior
extremity of a small iron axis, the other end being fitted into a
handle. To make use of this contrivance we place ourselves in front
of the glass, towards which we turn the disc with the figures, placing
the eye so as to see the figures through one of the holes of the large
disc. Directly the apparatus begins to turn round, the figures seen in
the glass appear to execute the particular movements which they
represent in different positions. Let us designate by means of the
figures 1, 2, 3, the different openings through which the eye
successively looks, and point out by the same numbers the figures in
the radiuses thus numbered. If the experimenter looks in the glass
through opening 1, he will see first figure 1, which appears in the
glass to pass before his eyes; then the rotation of the disc displaces
opening 1, and the cardboard intervenes, until opening 2 appears;
then figure 2 takes the place of figure 1, until it in turn disappears,
and opening 3 presents figure 3 to view. If these figures were all
similar, the spectator would have but a series of visual impressions,
separate but alike, which by a sufficiently rapid rotation mingle
together in one durable impression like a perfectly immovable object.
If, on the contrary, the figures differ slightly from each other, the
luminous sensations will also mingle in a single object, which will
however appear to be modified in a continuous manner, conformably
with the differences of successive images. With a difference of
speed, we obtain a new series of phenomena. A most simple
contrivance of this kind is a top of C. B. Dancer, of Manchester (fig.
113). It will be seen that the axis carries another disc, pierced with
openings of different shapes, to the edge of which a thread is
attached. This second disc is carried along by the friction of the axis,
but its rotation is less rapid because of the great resistance offered
by the air to the piece of thread which participates in the movement.
If the lower disc has several differently-coloured sectors, they
produce a very motley appearance, which seems to move sometimes
by leaps, and sometimes by continuous motion. We must distinguish
between the phenomena of successive contrast and simultaneous
contrast.
Fig. 112.—Rotating disc.

Fig. 113.—Mr. Dancer’s top.

Phenomena of successive contrast develop what are called


accidental images. If we fix our eyes for a considerable time on a
coloured object, and then suddenly direct them towards a uniform
white surface, we experience the sensation of the object as it is, but
it appears coloured with a complementary tint; that is to say, it has
the colour which, superposed on the genuine tint, we obtain from
pure white. Thus a red object produces a consecutive green object.
The experiment can be tried by gazing at the sun when it is setting,
and then directing one’s eyes towards a white wall in the same
direction.
Phenomena of simultaneous contrast arise from the influence
exercised over each other by different shades and colours which we
see simultaneously. That we may be certain that we have really
obtained phenomena of this kind, the experiments must be arranged
in such a manner that accidental images are not produced, and that
the part of the retina affected by the sensation of colour does not
receive, even momentarily, a passing image.

Fig. 114.—Disc, which exhibits, when in rotation, a series of concentric rings.

The phenomena of simultaneous contrast appear with the greatest


clearness with slight differences of colour, and are therefore exactly
the contrary of phenomena of successive contrast, which are
favoured by strong oppositions of colour and light. We can, in
general, characterise phenomena of simultaneous contrast as
governed by this law, common to all perceptions of the senses: the
differences clearly perceived appear greater than the differences
equal to them, but perceived with greater difficulty, either because
they only affect the observation in an uncertain manner, or that the
memory fails to judge of them. A man of middle height appears
small beside a tall man, because at the moment it is forcibly
impressed on us that there are taller men than he, and we lose sight
of the fact that there are smaller. The same man of medium height
appears tall beside a man of small stature. We can easily make
experiments on simultaneous contrast with a sheet of transparent
paper. We fasten together a sheet of green and a sheet of rose-
coloured paper, so as to obtain a sheet half red and half green. On
the line of separation between the two colours we place a strip of
grey paper, and cover the whole with a sheet of thin letter-paper of
the same size. The grey strip will then appear red at the edge
touching the green, and green at the edge touching the red; the
centre presenting an intermediate shade. It presents a still more
decided appearance if the grey strip is perpendicular with the line of
separation of the two colours; the piece of grey then stretching into
the green will present as deep a red as the red foundation on the
other side. If the line of grey colour exactly covers the line of
separation between the two colours, the contrasting colour is more
feeble; the edges of the grey paper then present complementary
strips of colour. Similar effects may be obtained by superposing, in
gradually diminishing layers, strips of thin paper, so as to form
successive bands of different thicknesses. If it is then lit up from
behind, the objective intensity is evidently constant through the
extent of each layer; nevertheless every strip appears darker at the
edge touching a more transparent layer, and lighter at the edge in
contact with a thicker layer. The dull tints of China ink, superposed in
layers, will produce a similar effect. The phenomena are produced
by means of rotative discs of most beautiful and delicate gradations
of colour. Let us give the sectors of the disc the form represented by
fig. 114, and make them black and white; and when in rotation we
shall see a series of concentric rings of a shade that becomes darker
and darker towards the centre. The angular surface of the dark
portions is constant in each of these rings. The intensity, therefore,
of each ring is uniform during rapid rotation; it is only between one
ring and another that the intensity varies. Each ring also appears
lighter on its inner side when it borders on a darker ring, and darker
on its outer side when in contact with a lighter ring. If the
differences of intensity in the rings are very slight, one can scarcely
judge sometimes if the inner rings are darker than the outer; the
eye is only struck by the periodical alternations of light and shade
presented by the edges of the rings. If, instead of white and black,
we take two different colours, each ring will present two colours on
its two edges, although the colour of the rest of the ring will be
uniform. Each of the constituent colours presents itself with more
intensity on that edge of the ring which borders on another ring
containing a smaller quantity of the colour. Thus, if we mix blue and
yellow, and the blue predominates in the exterior and the yellow in
the interior, every ring will appear yellow at its outer, and blue at its
inner edge; and if the colours present together very slight
differences, we may fall into the illusion which causes the differences
really existing between the colours of the different rings to
disappear, leaving instead, on a uniformly coloured background, the
contrasting blue and yellow of the edges of the rings. It is very
characteristic that in these cases we do not see the mixed colours,
but seem to see the constituent colours separately, one beside the
other, and one through the other.
All the experiments we have described afford great interest to the
student; they can easily be performed by those of our readers who
are particularly interested in these little-known subjects. Any one
may construct the greater part of the appliances we have
enumerated, and others can be obtained at an optician’s. The discs
in particular are extensively manufactured, and with great success.
CHAPTER XI.
OPTICAL ILLUSIONS—ZOLLNER’S DESIGNS—THE THAUMATROPE—
PHENOKISTOSCOPE—THE ZOOTROPE—THE PRAXINOSCOPE—
THE DAZZLING TOP.
We shall now continue the subject by describing some illusions more
curious still—those of ocular estimation. These illusions depend
rather on the particular properties of the figures we examine, and
the greater part of these phenomena may be placed in that category
whose law we have just formulated: the differences clearly perceived
appear greater than the differences equal to them, but perceived
with greater difficulty. Thus a line —— when divided appears greater
than when not divided; the direct perception of the parts makes us
notice the number of the sub-divisions, the size of which is more
perceptible than when the parts are not clearly marked off. Thus, in
fig. 115, we imagine the length ab equals bc, although ab is in
reality longer than bc. In an experiment consisting of dividing a line
into two equal parts, the right eye tends to increase the half on the
right, and the left eye to enlarge that on the left. To arrive at an
exact estimate, we turn over the paper and find the exact centre.
Fig. 115.

Fig. 116.

Illusions of this kind become more striking when the distances to be


compared run in different directions. If we look at a and b (fig. 116),
which are perfect squares, a appears greater in length than width,
whilst b, on the contrary, appears to have greater width than length.
The case is the same with angles. On looking at fig. 117, angles 1, 2,
3, 4 are straight, and should appear so when examined. But 1 and 2
appear pointed, and 3 and 4 obtuse. The illusion is still greater if we
look at the figure with the right eye. If, on the contrary, we turn it,
so that 2 and 3 are at the bottom, 1 and 2 will appear greatly
pointed to the left eye. The divided angles always appear relatively
greater than they would appear without divisions.
The same illusion is presented in a number of examples in the
course of daily life. An empty room appears smaller than a furnished
room, and a wall covered with paperhangings appears larger than a
bare wall. It is a well-known source of amusement to present
someone in company with a hat, and request him to mark on the
wall its supposed height from the ground. The height generally
indicated will be a size and a half too large.
We will relate an experience described by Bravais: “When at sea,” he
says, “at a certain distance from a coast which presents many
inequalities, if we attempt to draw the coastline as it presents itself
to the eye, we shall find on verification that the horizontal
dimensions have been correctly sketched at a certain scale, while all
the vertical angular objects have been represented on a scale twice
as large. This illusion, which is sure to occur in estimates of this
kind, can be demonstrated by numerous observations.”
M. Helmholtz has also indicated several optical illusions.

Fig. 117.

Fig. 118.

Fig. 119.

If we examine fig. 118, the continuation of the line a does not


appear to be d,—which it is in reality,—but f, which is a little lower.
This illusion is still more striking when we make the figure on a
smaller scale (fig. 119), as at b, where the two fine lines are in
continuation with each other, but do not appear to be so, and at c,
where they appear so, but are not in reality. If we draw the figures
as at a (fig. 118), leaving out the line d, and look at them from a
gradually increasing distance, so that they appear to diminish, it will
be found that the further off the figure is placed, the more it seems
necessary to lower the line f to make it appear a continuation of a.
These effects are produced by irradiation; they can also be produced
by black lines on a white foundation. Near the point of the two acute
angles, the circles of diffusion of the two black lines touch and
mutually reinforce each other; consequently the retinal image of the
narrow line presents its maximum of darkness nearest to the broad
line, and appears to deviate on that side. In figures of this kind,
however, executed on a larger scale, as in fig. 118, irradiation can
scarcely be the only cause of illusion. We will continue our exposition
as a means of finding an explanation. In fig. 120, a and b present
some examples pointed out by Hering; the straight, parallel lines, a
b, and c d, appear to bend outwards at a, and inwards at b. But the
most striking example is that represented by fig. 121, published by
Zollner.
The vertical black strips of this figure are parallel with each other,
but they appear convergent and divergent, and seem constantly
turned out of a vertical position into a direction inverse to that of the
oblique lines which divide them. The separate halves of the oblique
lines are displaced respectively, like the narrow lines in fig. 119. If
the figure is turned so that the broad vertical lines present an
inclination of 45° to the horizon, the convergence appears even
more remarkable, whilst we notice less the apparent deviation of the
halves of the small lines, which are then horizontal and vertical. The
direction of the vertical and horizontal lines is less modified than that
of the oblique lines. We may look upon these latter illusions as fresh
examples of the aforesaid rule, according to which acute angles
clearly defined, but of small size, appear, as a rule, relatively larger
when we compare with obtuse or right angles which are undivided;
but if the apparent enlargement of an acute angle shows itself in
such a manner that the two sides appear to diverge, the illusions
given in figs. 118, 120, and 121, will be the result.
Fig. 120.—The horizontal lines, a, b, c, d, are strictly parallel; their appearance of
deviation is caused by the oblique lines.

In fig. 118 the narrow lines appear to turn towards the point where
they penetrate the thick line and disappear, to appear afterwards in
continuation of each other. In fig. 120 the two halves of each of the
two straight lines seem to deviate through the entire length in such
a manner that the acute angles which they form with the oblique
lines appear enlarged. The same effect is shown by the vertical lines
of fig. 121.
M. Helmholtz is of opinion (figs. 120, 121) that the law of contrast is
insufficient to entirely explain the phenomena, and believes that the
effect is also caused by the movements of the eye. In fact, the
illusions almost entirely disappear, if we fix on a point of the object
in order to develop an accidental image, and when we have obtained
one very distinctly, which is quite possible with Zollner’s design (fig.
121), this image will present not the slightest trace of illusion. In fig.
118 the displacement of the gaze will exercise no very decided
influence on the strengthening of the illusion; on the contrary, it
disappears when we turn our eyes on the narrow line, ad. On the
other hand, the fixing of the eyes causes the illusion to disappear
with relative facility in fig. 120, and with more difficulty in fig. 121; it
will, however, disappear equally in the latter design, if we fix it
immovably, and instead of considering it as composed of black lines
on a white background, we compel ourselves to picture it as white
lines on a black foundation; then the illusion vanishes. But if we let
our eyes wander over the illustration, the illusion will return in full
force. We can indeed succeed in completely destroying the illusion
produced by these designs by covering them with a sheet of opaque
paper, on which we rest the point of a pin. Looking fixedly at the
point, we suddenly draw away the paper, and can then judge if the
gaze has been fixed and steady according to the clearness of the
accidental image which is formed as a result of the experiment.

Fig. 121.—The vertical strips are parallel; they appear convergent or divergent
under the influence of the oblique lines.
Fig. 122.—Observation of electric spark.

The light of an electric spark furnishes the surest and simplest


means of counteracting the influence of movements of the eyes, as
during the momentary duration of the spark the eye cannot execute
any sensible movement. For this experiment the present writer has
made use of a wooden box, a b c d (fig. 122), blackened on the
inside. Two holes are made for the eyes on each side of the box, f
and g. The observer looks through the openings, f, and in front of
openings, g, the objects are placed; these are pierced through with
a pin, which can be fixed by the eyes in the absence of the electric
spark, when the box is perfectly dark. The box is open, and rests on
the table, b d, to allow of changing the object. The conducting wires
of electricity are at h and i; in the centre of the box is a strip of
cardboard, white on the side facing the spark, the light of which it
shelters from the eye of the observer and throws back again on the
object. With the electric light the illusion was completely perceptible
with fig. 118, while it disappeared altogether in fig. 120; with fig.
121 it was not entirely absent, but when it showed itself, it was
much more feeble and doubtful than usual, though the intensity of
light was quite sufficient to allow of the form of the object being
very distinctly examined. Thus two different phenomena have to be
explained; first, the feeble illusion which is produced without the
intervention of movements of the eye; and secondly, the
strengthening of the illusion in consequence of these movements.
The law of contrast sufficiently explains the first; that which one
perceives most distinctly with indirect vision is the concordance of
directions with dimensions of the same kind. We perceive more
distinctly the difference of direction presented at their intersection by
the two sides of an acute or obtuse angle, than the deviation that
exists between one of the sides and the perpendicular which we
imagine placed on the other side, but which is not marked. By being
distributed on both sides, the apparent enlargement of the angles
gives way to displacements, and changes of direction of the sides. It
is difficult to correct the apparent displacement of the lines when
they remain parallel to their true direction; for this reason, the
illusion of the figure is relatively more inflexible. Changes of
direction, on the contrary, are recognised more easily if we examine
the figure attentively, when these changes have the effect of causing
the concordance of the lines (which accord in reality) to disappear; it
is probably because of the difference in aspect of the numerous
oblique lines of figs. 120 and 121 that the concordance of these lines
escapes the observer’s notice. As regards the influence exercised by
the motion of the eyes in the apparent direction of the lines, M.
Helmholtz, after discussing the matter very thoroughly, proves the
strengthening of the illusion in Zollner’s illustration to be caused by
those motions. It is not now our intention to follow out the whole of
this demonstration; it will be sufficient to point out to the reader a
fruitful force of study, with but little known results.
The Romans were well acquainted with the influence of oblique
lines. At Pompeii, fresco paintings are to be found, in which the lines
are not parallel, so that they satisfy the eye influenced by adjacent
lines. Engravers in copper-plate have also studied the influence of
etchings on the parallelism of straight lines, and they calculate the
effect that they will produce on the engraving. In some
ornamentations in which these results have not been calculated, it
sometimes happens that parallel lines do not appear parallel because
of the influence of other oblique lines, and a disagreeable effect is
produced. A similar result is to be seen at the railway station at
Lyons, the roof of which is covered with inlaid work in point de
Hongrie. The wide parallel lines of this ceiling appear to deviate, a
result produced by a series of oblique lines formed by the planks of
wood.

Fig. 123.—Two sides of a Thaumatrope disc.

Having given a long account of the result of M. Helmholtz’s labours,


we will pass to the consideration of another kind of experiments, or
rather appliances, based on the illusions of vision, and the
persistence of impressions on the retina.
The Thaumatrope, to which we have already referred, is a plaything
of very ancient origin, based on the principle we have mentioned. It
consists of a cardboard disc, which we put in motion by pulling two
cords. On one side of the disc a cage, a, is portrayed, on the other a
bird, b (fig. 123). When the little contrivance is turned round, the
two designs are seen at the same time, and form but one image—
that of a bird in its cage (fig. 124). It is of course hardly necessary
to add that the designs may be varied.
We have already referred to M. Plateau’s rotating disc (the
Phenakistoscope). Through the narrow slits we perceive in
succession representations of different positions of a certain action.
The persistence of the luminous impressions on the retina gives to
the eye the sensation of a continuous image, which seems animated
by the same movements as those portrayed in the different phases
(fig. 125).
Fig. 124.—Appearance of the Thaumatrope in rotation.

Fig. 125.—Plateau’s Phenokistoscope.


The Zootrope (fig. 126) is a perfected specimen of this apparatus. It
is composed of a cylinder of cardboard, turning on a central axis.
The cylinder is pierced with vertical slits at regular intervals, and
through which the spectator can see the designs upon a band of
paper adapted to the interior of the apparatus in rotation. The
designs are so executed that they represent the different times of a
movement between two extremes; and in consequence of the
impressions upon the retina the successive phases are mingled, so
the spectator believes he sees, without transition, the entire
movement. We give a few specimens of the pictures for the
Zootrope (fig. 127). We have here an ape leaping over a hedge, a
dancing “Punch,” a gendarme pursuing a thief, a person holding the
devil by the tail, a robber coming out of a box, and a sportsman
firing at a bird. The extremes of the movement are right and left;
the intermediary figures make the transitions, and they are usually
equal in number to the slits in the Zootrope. It is not difficult to
construct such an instrument, and better drawings could be made
than the specimens taken at random from a model. The earth might
be represented turning in space, or a fire-engine pumping water
could be given, and thus the Zootrope might be quite a vehicle of
instruction as well as of amusement. This instrument is certainly one
of the most curious in the range of optics, and never fails to excite
interest. The ingenious contrivances which have up to the present
time reproduced it, all consist in the employment of narrow slits,
which besides reducing the light to a great extent, and consequently
the light and clearness of the object, require the instrument to be
set in rapid rotation, which greatly exaggerates the rapidity of the
movements represented, and without which the intermissions of the
spectacle could not unite in a continuous sensation.
Fig. 126.—The Zootrope.

Fig. 127.—Pictures used in the Zootrope.


We present here an apparatus based on a very different optical
arrangement. In the Praxinoscope12 (a name given by the inventor,
Mr. Reynaud, to this new apparatus), the substitution of one object
for another is accomplished without interruption in the vision, or
solution of continuity, and consequently without a sensible reduction
of light; in a word, the eye beholds continuously an image which,
nevertheless, is incessantly changing before it. The result was
obtained in this manner. Having sought unsuccessfully by mechanical
means to substitute one object for another without interrupting the
continuity of the spectacle, the inventor was seized with the idea of
producing this substitution, not with the objects themselves, but
with their virtual images. He then contrived the arrangement which
we will now describe. A plane mirror, ab (fig. 129), is placed at a
certain distance from an object, cd, and the virtual image will be
seen at c′d′. If we then turn the plane mirror and object towards the
point, o, letting be and df be their new positions, the image will be at
c″d″. Its axis, o, will not be displaced. In the positions, ab and cd,
first occupied by the plane mirror and the object, we now place
another mirror and object. Let us imagine the eye placed at m. Half
of the first object will be seen at od″, and half of the second at oc′.
If we continue the rotation of the instrument, we shall soon have
mirror No. 2 at tt′, and object No. 2 at ss′. At the same moment the
image of object No. 2 will be seen entirely at c‴d″. Mirror No. 2 and
its object will soon after be at be and df. If we then imagine another
mirror and its corresponding object at ab and cd, the same
succession of phenomena will be reproduced. This experiment
therefore shows that a series of objects placed on the perimeter of a
polygon will be seen successively at the centre, if the plane mirrors
are placed on a concentric polygon, the “apothème” of which will be
less by one-half, and which will be carried on by the same
movement. In its practical form, M. Reynaud’s apparatus consists of
a polygonal or simply circular box (fig. 128), (for the polygon may be
replaced by a circle without the principle or result being changed), in
the centre of which is placed a prism of exactly half a diameter less,
the surface of which is covered with plane mirrors. A strip of
cardboard bearing a number of designs of the same object,
portrayed in different phases of action, is placed in the interior of the
circular rim of the box, so that each position corresponds to a plate
of the glass prism. A moderate movement of rotation given to the
apparatus, which is raised on a central pivot, suffices to produce the
substitution of the figures, and the animated object is reflected on
the centre of the glass prism with remarkable brightness, clearness,
and delicacy of movement. Constructed in this manner, the
Praxinoscope forms an optical toy both interesting and amusing. In
the evening, a lamp placed on a support ad hoc, in the centre of the
apparatus, suffices to light it up very clearly, and a number of
persons may conveniently assemble round it, and witness the effects
produced.

Fig. 129.

Fig. 128.—M. Reynaud’s Praxinoscope.

Besides the attractions offered by the animated scenes of the


Praxinoscope, the apparatus may also be made the object of useful
applications in the study of optics. It permits an object, a drawing,
or a colour, to be substituted instantaneously in experiments on
secondary or subjective images, etc., on the contrast of colours or
the persistence of impressions, etc. We can also make what is called
a synthesis of movements by placing before the prism a series of
diagrams of natural objects by means of photography.
M. Reynaud has already arranged an apparatus which exhibits in the
largest dimensions the animated reflection of the Praxinoscope, and
which lends itself to the demonstration of curious effects before a
numerous auditory. The ingenious inventor has recently contrived
also a very curious improvement in the original apparatus. In the
Praxinoscope Theatre he has succeeded in producing truly
ornamental tableaux, as on a small Lilliputian stage, in the centre of
which the principal object moves with startling effect. To obtain this
result, M. Reynaud commences by cutting out in black paper the
different figures, the whole of which will form an object animated by
the rotation given to the Praxinoscope. To supply the decorations, he
arranges on the black foundation the image of an appropriate
coloured design by means of a piece of glass. It is well known that
transparent glass possesses the property of giving a reflection of the
objects on the nearest side as well as on the farthest. We may recall
the applications of this optical effect in theatres, and also in courses
of physics, under the title of impalpable spectres. It is also by
reflection on thin, transparent glass, that M. Reynaud produces the
image of the ornamentations in the Praxinoscope Theatre. The
decorations are really placed in the lid, which is held by a hook in a
vertical position, thus forming the front side of the apparatus (fig.
130). In this side a rectangular opening is made, through which the
spectator (using both eyes) perceives at the same time the animated
reflection of the Praxinoscope, and the immovable image of the
decorations reflected in the transparent glass. The position of the
latter and its distance from the coloured decorations are arranged so
that the reflection is thrown behind the moving figure, which
consequently appears in strong relief against the background, the
effect produced being very striking. It is evident that to change the
decorations it is only necessary to place in succession on a slide the
different chromos representing landscapes, buildings, the interior of
a circus, etc. It is easy to choose an arrangement suitable for each
of the moving figures placed in the Praxinoscope. By this clever and
entirely novel optical combination, the mechanism of the contrivance
is entirely lost sight of, leaving only the effect produced by the
animated figures, which fulfil their different movements on the little
stage. The Praxinoscope Theatre can also be used as well in the
evening as in the daytime. By daylight, it is sufficient to place it
before a window, and in the evening the same effects may be
produced, perhaps in even a more striking manner, by simply placing
a lamp on the stand, with a small plated reflector, and a lamp-shade.
The illusion produced by this scientific plaything is very complete
and curious, and M. Reynaud cannot be too much commended for
so cleverly applying his knowledge of physics in the construction of
an apparatus which is at the same time both an optical instrument
and a charming source of amusement.

Fig 130.—The Praxinoscope Theatre.


Fig. 131.—The Dazzling Top.

Amongst the toys founded upon the persistency of impressions upon


the retina we may instance the “Dazzling Top” (fig. 131). This
remarkable invention is quite worthy of a place in every cabinet, and
is an ingenious specimen of a perfected Helmholtz top. It is a
metallic toy put in motion by means of a cord wound round a
groove. The axis is hollow, admits a metallic stem, and fits into a
handle which is held in the hand. The top is placed upon a little cup
in an upright position, and it is then set spinning in the usual way
with the cord. The stem and handle are then withdrawn, and as the
top will continue to spin for a long time, discs and various outline
shapes can be fixed upon it, and various objects will be shadowed
thereon. Cups, bowls, candlesticks, and jugs can be seen plainly
revolving as the top carries the wire representation in outline rapidly
past the eyes. Coloured cardboard can be worked into various
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like