IoT Development for ESP32 and ESP8266 with JavaScript: A Practical Guide to XS and the Moddable SDK Peter Hoddie pdf download
IoT Development for ESP32 and ESP8266 with JavaScript: A Practical Guide to XS and the Moddable SDK Peter Hoddie pdf download
https://textbookfull.com/product/iot-development-for-esp32-and-
esp8266-with-javascript-a-practical-guide-to-xs-and-the-moddable-
sdk-peter-hoddie/
https://textbookfull.com/product/micropython-programming-with-
esp32-and-esp8266-rui-santos/
https://textbookfull.com/product/developing-iot-projects-with-
esp32-discover-the-iot-development-ecosystem-with-esp32-to-
create-production-grade-smart-devices-2nd-edition-vedat-ozan-
oner/
https://textbookfull.com/product/hands-on-esp32-with-arduino-ide-
unleash-the-power-of-iot-with-esp32-and-build-exciting-projects-
with-this-practical-guide-1st-edition-zulfiqar/
https://textbookfull.com/product/practical-internet-of-things-
with-javascript-build-standalone-exciting-iot-projects-with-
raspberry-pi-3-and-javascript-1st-edition-arvind-ravulavaru/
Applied Machine Learning for Health and Fitness: A
Practical Guide to Machine Learning with Deep Vision,
Sensors and IoT Kevin Ashley
https://textbookfull.com/product/applied-machine-learning-for-
health-and-fitness-a-practical-guide-to-machine-learning-with-
deep-vision-sensors-and-iot-kevin-ashley/
https://textbookfull.com/product/the-complete-guide-to-esp32-and-
arduino-for-iot-unleash-the-power-of-the-internet-of-things-
build-connected-devices-and-automate-your-worl-1st-edition-
hatake/
https://textbookfull.com/product/a-practical-guide-to-biomedical-
research-for-the-aspiring-scientist-1st-edition-peter-agger/
https://textbookfull.com/product/ios-10-sdk-development-creating-
iphone-and-ipad-apps-with-swift-chris-adamson/
https://textbookfull.com/product/internet-of-things-from-scratch-
build-iot-solutions-for-industry-4-0-with-esp32-raspberry-pi-and-
aws-1st-edition-renaldi-gondosubroto/
IoT Development
for ESP32 and
ESP8266 with
JavaScript
A Practical Guide to XS and the
Moddable SDK
—
Peter Hoddie
Lizzie Prader
IoT Development for
ESP32 and ESP8266
with JavaScript
A Practical Guide to XS
and the Moddable SDK
Peter Hoddie
Lizzie Prader
IoT Development for ESP32 and ESP8266 with JavaScript: A Practical
Guide to XS and the Moddable SDK
Peter Hoddie Lizzie Prader
Menlo Park, CA, USA Menlo Park, CA, USA
Acknowledgments���������������������������������������������������������������������������xxiii
Foreword������������������������������������������������������������������������������������������ xxv
Introduction������������������������������������������������������������������������������������ xxvii
iii
Table of Contents
Troubleshooting��������������������������������������������������������������������������������������������������14
Device Not Connected/Recognized���������������������������������������������������������������14
Incompatible Baud Rate��������������������������������������������������������������������������������16
Device Not in Bootloader Mode���������������������������������������������������������������������17
Adding a Display�������������������������������������������������������������������������������������������������18
Connecting a Display to the ESP32���������������������������������������������������������������19
Connecting a Display to the ESP8266�����������������������������������������������������������20
Installing helloworld-gui�������������������������������������������������������������������������������22
Conclusion����������������������������������������������������������������������������������������������������������24
iv
Table of Contents
Classes����������������������������������������������������������������������������������������������������������������75
Class Constructor and Methods��������������������������������������������������������������������75
Static Methods����������������������������������������������������������������������������������������������77
Subclasses����������������������������������������������������������������������������������������������������78
Private Fields�������������������������������������������������������������������������������������������������84
Private Methods���������������������������������������������������������������������������������������������86
Using Callback Functions in Classes�������������������������������������������������������������87
Modules��������������������������������������������������������������������������������������������������������������90
Importing from Modules��������������������������������������������������������������������������������90
Exporting from Modules��������������������������������������������������������������������������������93
ECMAScript Modules vs. CommonJS Modules����������������������������������������������94
Globals����������������������������������������������������������������������������������������������������������������94
Arrays������������������������������������������������������������������������������������������������������������������96
Array Shorthand��������������������������������������������������������������������������������������������97
Accessing Elements of an Array��������������������������������������������������������������������97
Iterating over Arrays��������������������������������������������������������������������������������������99
Adding and Removing Elements of an Array�����������������������������������������������101
Searching Arrays�����������������������������������������������������������������������������������������103
Sorting Arrays����������������������������������������������������������������������������������������������104
Binary Data�������������������������������������������������������������������������������������������������������106
ArrayBuffer���������������������������������������������������������������������������������������������106
Typed Arrays������������������������������������������������������������������������������������������������107
Data Views���������������������������������������������������������������������������������������������������114
Memory Management���������������������������������������������������������������������������������������118
The Date Class�������������������������������������������������������������������������������������������������121
Event-Driven Programming�������������������������������������������������������������������������������125
Conclusion��������������������������������������������������������������������������������������������������������126
v
Table of Contents
Chapter 3: Networking����������������������������������������������������������������������127
About Networking���������������������������������������������������������������������������������������������128
Connecting to Wi-Fi�������������������������������������������������������������������������������������������129
Connecting from the Command Line�����������������������������������������������������������130
Connecting with Code���������������������������������������������������������������������������������131
Connecting to Any Open Access Point���������������������������������������������������������134
Installing the Network Host�������������������������������������������������������������������������������137
Installing Examples�������������������������������������������������������������������������������������������137
Getting Network Information�����������������������������������������������������������������������������137
Making HTTP Requests�������������������������������������������������������������������������������������138
Fundamentals����������������������������������������������������������������������������������������������138
GET��������������������������������������������������������������������������������������������������������������140
Streaming GET���������������������������������������������������������������������������������������������141
GET JSON����������������������������������������������������������������������������������������������������143
Subclassing an HTTP Request���������������������������������������������������������������������145
Setting Request Headers�����������������������������������������������������������������������������147
Getting Response Headers��������������������������������������������������������������������������148
POST������������������������������������������������������������������������������������������������������������149
Handling Errors��������������������������������������������������������������������������������������������150
Securing Connections with TLS������������������������������������������������������������������������151
Using TLS with the SecureSocket Class���������������������������������������������������152
Public Certificates���������������������������������������������������������������������������������������152
Private Certificates��������������������������������������������������������������������������������������154
Creating an HTTP Server�����������������������������������������������������������������������������������155
Fundamentals����������������������������������������������������������������������������������������������155
Responding to a Request�����������������������������������������������������������������������������157
Responding to JSON PUT�����������������������������������������������������������������������������158
vi
Table of Contents
vii
Table of Contents
viii
Table of Contents
Preference Data�������������������������������������������������������������������������������������������235
Reading and Writing Preferences����������������������������������������������������������������236
Deleting Preferences�����������������������������������������������������������������������������������237
Don’t Use JSON�������������������������������������������������������������������������������������������237
Security�������������������������������������������������������������������������������������������������������239
Resources���������������������������������������������������������������������������������������������������������239
Adding Resources to a Project��������������������������������������������������������������������240
Accessing Resources����������������������������������������������������������������������������������241
Using Resources������������������������������������������������������������������������������������������241
Accessing Flash Memory Directly���������������������������������������������������������������������243
Flash Hardware Fundamentals��������������������������������������������������������������������244
Accessing Flash Partitions��������������������������������������������������������������������������246
Example: Frequently Updated Integer���������������������������������������������������������251
Conclusion��������������������������������������������������������������������������������������������������������254
Chapter 6: Hardware�������������������������������������������������������������������������255
Installing the Hardware Host�����������������������������������������������������������������������������256
Notes on Wiring�������������������������������������������������������������������������������������������������256
Following the Wiring Instructions����������������������������������������������������������������256
Troubleshooting Wiring Issues���������������������������������������������������������������������257
Blinking an LED�������������������������������������������������������������������������������������������������258
Reading a Button����������������������������������������������������������������������������������������������260
Other Digital Input Modes����������������������������������������������������������������������������262
Monitoring for Changes�������������������������������������������������������������������������������266
Controlling a Tri-color LED��������������������������������������������������������������������������������267
LED Setup����������������������������������������������������������������������������������������������������268
ESP32 Wiring Instructions���������������������������������������������������������������������������268
ESP8266 Wiring Instructions�����������������������������������������������������������������������269
ix
Table of Contents
Chapter 7: Audio�������������������������������������������������������������������������������295
Speaker Options������������������������������������������������������������������������������������������������295
Adding the Analog Speaker�������������������������������������������������������������������������������297
ESP32 Wiring Instructions���������������������������������������������������������������������������298
ESP8266 Wiring Instructions�����������������������������������������������������������������������299
Adding an I2S Chip and Digital Speaker������������������������������������������������������������300
ESP32 Wiring Instructions���������������������������������������������������������������������������300
ESP8266 Wiring Instructions�����������������������������������������������������������������������302
Installing the Audio Host�����������������������������������������������������������������������������������303
The AudioOut Class�����������������������������������������������������������������������������������������304
AudioOut Configuration�����������������������������������������������������������������������������������304
Audio Hardware Protocols���������������������������������������������������������������������������304
Audio Data Formats�������������������������������������������������������������������������������������308
Audio Compression��������������������������������������������������������������������������������������310
Setting the Audio Queue Length������������������������������������������������������������������310
Playing Audio with AudioOut���������������������������������������������������������������������������311
Instantiating AudioOut�������������������������������������������������������������������������������311
x
Table of Contents
xi
Table of Contents
Poco or Piu?������������������������������������������������������������������������������������������������������352
Conclusion��������������������������������������������������������������������������������������������������������355
xii
Table of Contents
Using Multi-touch����������������������������������������������������������������������������������������404
Applying Rotation����������������������������������������������������������������������������������������404
Conclusion��������������������������������������������������������������������������������������������������������405
xiii
Table of Contents
xiv
Table of Contents
Glossary��������������������������������������������������������������������������������������������565
Index�������������������������������������������������������������������������������������������������583
xv
About the Authors
Peter Hoddie is an engineer and entrepreneur focused on client software.
He is recognized for crafting compact and efficient code that pushes the
boundaries of user experience on consumer hardware. The software he and
his teams have built has powered mass-market consumer products from
companies including Apple, Palm, Sling, HP, Sony, and Whirlpool. Peter
recognizes that the first users of any product are the developers creating
it, and that those developers cannot build compelling consumer products
on a foundation that’s unstable, complex, or confusing. He therefore
champions investments in great tools and a simple runtime architecture.
Peter has founded several companies, including Kinoma, which merged
into Marvell Semiconductor. He led QuickTime development at Apple
during the 1990s as a Distinguished Engineer. He contributed to the
development of the QuickTime file format and its adoption by ISO into the
MPEG-4 standard. He is currently a member of the JavaScript language
standards committee (ECMA TC39) and chair of ECMA TC53 for “Smart
wearable systems and sensor-based devices.” Peter is particularly proud
of his work putting both the KinomaJS framework and Darwin Streaming
Server into open source. He continues to come to terms with the ten
patents that bear his name.
xvii
About the Authors
xviii
About the Technical Reviewers
Mark Wharton was born in England, was raised in Papua New Guinea
and Australia, and worked as a software engineer for startups and large
corporations in Australia, Japan, and the United States. He currently
works at Amazon on the Alexa Automotive initiative. Since his early days
programming the 6502 assembly language on Apple IIe and Commodore
64 computers, Mark excels at making the most of limited resources in
constrained environments. Now in his spare time, Mark enjoys applying
those skills to a new generation of low-cost, low-power devices using the
Moddable SDK.
xix
About the Editor
Caroline Rose is a freelance technical writer and editor based in
Palo Alto, California. With a career that has included 7 years working
as a programmer, her focus has been on producing highly technical
documentation, most notably as lead writer and editor of the original
Inside Macintosh. Caroline was also Manager of Publications at NeXT and
the editor of Apple’s quarterly technical journal, develop. Her subsequent
freelance work began with coauthoring updated versions of Adobe’s
PostScript and PDF reference manuals and went on to include clients such
as AMD, Apple, Apress, Kinoma, Logitech, Nokia, and Sony. In her free
time, Caroline enjoys playing guitar, singing, swimming, hiking, traveling,
and working on her memoir.
xxi
Acknowledgments
This book is better because of the generous assistance of many talented
individuals we’re fortunate to call friends.
xxiii
Foreword
Those of you who have read Wikipedia cover to cover will remember the
definition of hybrid vigor. For the rest of you:
The practical upshot of this is that if you take separate, inbred strains
of, say, corn and breed them together, you get a great big vigorous plant,
hence the name hybrid vigor.
The Moddable SDK, as described in this book, represents the hybrid
vigor between embedded and JavaScript development. Using Moddable is
a short path to very large amounts of corn.
If you’re an embedded developer, you delight in the ability to get
close to the metal, to program on tiny, inexpensive devices without the
affordances offered by development on large systems. Writing in C/C++
and/or assembly language gives you a great deal of control, but you often
struggle with shoehorning functionality into these small devices, wrestle
brittle development and debugging environments, and build ad hoc
device-specific ways of updating code and managing resources. If the
embedded device has a display or is capable of wireless communications,
you need to track down the right tools to build, simulate, and test a wide
variety of functionality in the absence of a rich underlying OS. A great deal
of your energy goes into managing the constraints of these small systems
rather than into the applications themselves.
xxv
Foreword
— Peter Barrett
xxvi
Introduction
This book is a hands-on guide to writing the software for IoT products.
Each chapter is filled with compact, focused examples for you to learn
from, study, run, and modify. When you finish this book, you’ll know the
fundamentals of building sophisticated IoT products on low-cost hardware
using modern JavaScript.
IoT products differ from traditional products in two ways: they have
the ability to run software and they have the ability to communicate. Their
communication is often over the internet, but it may be more local—for
example, between products on your home Wi-Fi network or with your
phone over a Bluetooth connection.
IoT products are often created by adding a microcontroller with Wi-Fi
or Bluetooth capabilities to a traditional product. The cost of adding a
microcontroller with communication capabilities is about one dollar today
and continues to fall. At that price, nearly every product is going to be an
IoT product—not just televisions and thermostats but also light bulbs,
light switches, electric wall plugs, door locks, window shades, garage door
openers, ceiling fans, rice cookers, refrigerators, and more.
The code in this book runs on the ESP32 and ESP8266 microcontrollers
from Espressif, which offer remarkable power at an unprecedented cost.
Unsurprisingly, they’re widely deployed in IoT products and extremely
popular with makers and hobbyists. What you’ll learn in this book isn’t
limited to these microcontrollers, however; it can be applied to a growing
number of microcontrollers from manufacturers including Nordic,
Qualcomm, and Silicon Labs.
Adding IoT hardware to a traditional product is the easy part; the hard
part is the software. Software defines the product’s features and behavior.
xxvii
Introduction
It determines whether the product is reliable and easy to use and whether
it’s secure from external attacks and respects the privacy of users. Software
decides what other products the product can communicate with, its energy
use, the ease of adding new features over time, and much more.
Software is fundamental to IoT products, yet most of the industry
continues to write the software for them using the same tools and
techniques embedded software developers have used for decades. While
the hardware has advanced by orders of magnitude, the software has not.
That’s a problem, because much more is expected of the software in an IoT
product today than the software in a digital thermostat from 1999.
xxviii
Introduction
xxix
Introduction
xxx
Introduction
xxxi
Introduction
xxxii
Another Random Document on
Scribd Without Any Related Topics
There is one strange bird song that is half song and half dance that
perhaps most of you may never be able to hear and see; but as it is
worth going miles to hear, and nights of watching to witness, I am
going to set it here as one of your outdoor tasks or feats: you must
hear the mating song of the woodcock. I have described the song
and the dance in “Roof and Meadow,” in the chapter called “One
Flew East and One Flew West.” Mr. Bradford Torrey has an account
of it in his “Clerk of the Woods,” in the chapter named “Woodcock
Vespers.” To hear the song is a rare experience for the habitual
watcher in the woods, but one that you might have the first April
evening that you are abroad.
Go down to your nearest meadow—a meadow near a swampy piece
of woods is best—and here, along the bank of the meadow stream,
wait in the chilly twilight for the speank, speank, or the peent,
peent, from the grass—the signal that the song is about to begin.
VI
One of the dreadful—positively dreadful—sounds of the late spring
that I hear day in and day out is the gobbling, strangling, ghastly
cries of young crows feeding. You will surely think something is
being murdered. The crying of a hungry baby is musical in
comparison. But it is a good sound to hear, for it reminds one of the
babes in the woods—that a new generation of birds is being brought
through from babyhood to gladden the world. It is a tender sound!
The year is still young.
VII
You should hear the hum of the honey-bees on a fresh May day in
an apple tree that is just coming into perfect bloom. The enchanting
loveless of the pink and white world of blossoms is enough to make
one forget to listen to the hum-hum-hum-humming-ing-ing-ing-ing
of the excited bees. But hear their myriad wings, fanning the
perfume into the air and filling the sunshine with the music of work.
The whir, the hum of labor—of a busy factory, of a great steamship
dock—is always music to those who know the blessedness of work;
but it takes that knowledge, and a good deal of imagination besides,
to hear the music in it. Not so with the bees. The season, the day,
the colors, and perfumes—they are the song; the wings are only the
million-stringed æolian upon which the song is played.
VIII
You should hear the grass grow. What! I repeat, you should hear the
grass grow. I have a friend, a sound and sensible man, but a lover of
the out-of-doors, who says he can hear it grow. But perhaps it is the
soft stir of the working earthworms that he hears. Try it. Go out
alone one of these April nights; select a green pasture with a slope
to the south, at least a mile from any house, or railroad; lay your ear
flat upon the grass, listen without a move for ten minutes. You hear
something—or do you feel it? Is it the reaching up of the grass? is it
the stir of the earthworms? is it the pulse of the throbbing universe?
or is it your own throbbing pulse? It is all of these, I think; call it the
heart of the grass beating in every tiny living blade, if you wish to.
You should listen to hear the grass grow.
IX
The fires have gone out on the open hearth. Listen early in the
morning and toward evening for the rumbling, the small, muffled
thunder, of the chimney swallows, as they come down from the open
sky on their wonderful wings. Don’t be frightened. It isn’t Santa
Claus this time of year; nor is it the Old Nick! The smothered
thunder is caused by the rapid beating of the swallows’ wings on the
air in the narrow chimney-flue, as the birds settle down from the top
of the chimney and hover over their nests. Stick your head into the
fireplace and look up! Don’t smoke the precious lodgers out, no
matter how much racket they make.
X
Hurry out while the last drops of your first May thunder-shower are
still falling and listen to the robins singing from the tops of the trees.
Their liquid songs are as fresh as the shower, as if the raindrops in
falling were running down from the trees in song—as indeed they
are in the overflowing trout-brook. Go out and listen, and write a
better poem than this one that I wrote the other afternoon when
listening to the birds in our first spring shower:—
The warm rain drops aslant the sun
And in the rain the robins sing;
Across the creek in twos and troops,
The hawking swifts and swallows wing.
“She was laying her course, I thought, straight down the length of
this dreadful pasture, when, not far from the fence, she suddenly
hove to, warped herself short about, and came back, barely clearing
me. I warped about, too, and in her wake bore down across the
corner of the pasture, across the powdery public road, and on to a
fence along a field of young corn.
“I was somewhat wet by this time, but not so wet as I had been
before wallowing through the deep, dry dust of the road. Hurrying
up behind a large tree by the fence, I peered down the corn-rows
and saw the turtle stop, and begin to paw about in the loose, soft
soil. She was going to lay!
“I held on to the tree and watched, as she tried this place, and that
place, and the other place. But the place, evidently, was hard to find.
What could a female turtle do with a whole field of possible nests to
choose from? Then at last she found it, and, whirling about, she
backed quickly at it and, tail first, began to bury herself before my
staring eyes.
“Those were not the supreme moments of my life; perhaps those
moments came later that day; but those certainly were among the
slowest, most dreadfully mixed of moments that I ever experienced.
They were hours long. There she was, her shell just showing, like
some old hulk in the sand alongshore. And how long would she stay
there? and how should I know if she had laid an egg?
“I could still wait. And so I waited, when, over the freshly awakened
fields, floated four mellow strokes from the distant town clock.
“Four o’clock! Why there was no train until seven! No train for three
hours! The eggs would spoil! Then with a rush it came over me that
this was Sunday morning, and there was no regular seven o’clock
train,—none till after nine.
“I think I should have fainted had not the turtle just then begun
crawling off. I was weak and dizzy; but there, there in the sand,
were the eggs! and Agassiz! and the great book! Why, I cleared the
fence—and the forty miles that lay between me and Cambridge—at
a single jump! He should have them, trains or no. Those eggs should
go to Agassiz by seven o’clock, if I had to gallop every mile of the
way. Forty miles! Any horse could cover it in three hours, if he had
to; and, upsetting the astonished turtle, I scooped out her long
white eggs.
“On a bed of sand in the bottom of the pail I laid them, with what
care my trembling fingers allowed; filled in between them with more
sand; so with layer after layer to the rim; and covering all smoothly
with more sand, I ran back for my horse.
“That horse knew, as well as I, that the turtles had laid, and that he
was to get those eggs to Agassiz. He turned out of that field into the
road on two wheels, a thing he had not done for twenty years,
doubling me up before the dashboard, the pail of eggs miraculously
lodged between my knees.
“I let him out. If only he could keep this pace all the way to
Cambridge!—or even halfway there, I would have time to finish the
trip on foot. I shouted him on, holding to the dasher with one hand,
holding the pail of eggs with the other, not daring to get off my
knees, though the bang on them, as we pounded down the wood-
road, was terrific. But nothing must happen to the eggs; they must
not be jarred, or even turned over in the sand before they came to
Agassiz.
“In order to get out on the pike it was necessary to drive back away
from Boston toward the town. We had nearly covered the distance,
and were rounding a turn from the woods into the open fields,
when, ahead of me, at the station it seemed, I heard the quick,
sharp whistle of a locomotive.
“What did it mean? Then followed the puff, puff, puff, of a starting
train. But what train? Which way going? And jumping to my feet for
a longer view, I pulled into a side road that paralleled the track, and
headed hard for the station.
“We reeled along. The station was still out of sight, but from behind
the bushes that shut it from view, rose the smoke of a moving
engine. It was perhaps a mile away, but we were approaching, head
on, and, topping a little hill, I swept down upon a freight train, the
black smoke pouring from the stack, as the mighty creature pulled
itself together for its swift run down the rails.
“My horse was on the gallop, following the track, and going straight
toward the coming train. The sight of it almost maddened me—the
bare thought of it, on the road to Boston! On I went; on it came, a
half—a quarter of a mile between us, when suddenly my road shot
out along an unfenced field with only a level stretch of sod between
me and the engine.
“With a pull that lifted the horse from his feet, I swung him into the
field and sent him straight as an arrow for the track. That train
should carry me and my eggs to Boston!
“The engineer pulled the whistle. He saw me stand up in the rig,
saw my hat blow off, saw me wave my arms, saw the tin pail swing
in my teeth, and he jerked out a succession of sharp Halts! But it
was he who should halt, not I; and on we went, the horse with a
flounder landing the carriage on top of the track.
“The train was already grinding to a stop; but before it was near a
standstill, I had backed off the track, jumped out, and, running
down the rails with the astonished engineers gaping at me, had
swung aboard the cab.
“They offered no resistance; they hadn’t had time. Nor did they have
the disposition, for I looked strange, not to say dangerous. Hatless,
dew-soaked, smeared with yellow mud, and holding, as if it were a
baby or a bomb, a little tin pail of sand!
“‘Crazy,’ the fireman muttered, looking to the engineer for his cue.
“I had been crazy, perhaps, but I was not crazy now.
“‘Throw her wide open,’ I commanded. ‘Wide open! These are fresh
turtle eggs for Professor Agassiz of Cambridge. He must have them
before breakfast.’
“Then they knew I was crazy, and, evidently thinking it best to
humor me, threw the throttle wide open, and away we went.
“I kissed my hand to the horse, grazing unconcernedly in the open
field, and gave a smile to my crew. That was all I could give them,
and hold myself and the eggs together. But the smile was enough.
And they smiled through their smut at me, though one of them held
fast to his shovel, while the other kept his hand upon a big ugly
wrench. Neither of them spoke to me, but above the roar of the
swaying engine I caught enough of their broken talk to understand
that they were driving under a full head of steam, with the intention
of handing me over to the Boston police, as perhaps the safest way
of disposing of me.
“I was only afraid that they would try it at the next station. But that
station whizzed past without a bit of slack, and the next, and the
next; when it came over me that this was the through freight, which
should have passed in the night, and was making up lost time.
“Only the fear of the shovel and the wrench kept me from shaking
hands with both men at this discovery. But I beamed at them; and
they at me. I was enjoying it. The unwonted jar beneath my feet
was wrinkling my diaphragm with spasms of delight. And the
fireman beamed at the engineer, with a look that said, ‘See the
lunatic grin; he likes it!’
“He did like it. How the iron wheels sang to me as they took the
rails! How the rushing wind in my ears sang to me! From my stand
on the fireman’s side of the cab I could catch a glimpse of the track
just ahead of the engine, where the ties seemed to leap into the
throat of the mile-devouring monster. The joy of it! of seeing space
swallowed by the mile!
“I shifted the eggs from hand to hand and thought of my horse, of
Agassiz, of the great book, of my great luck,—luck,—luck,—until the
multitudinous tongues of the thundering train were all chiming ‘luck!
luck! luck!’ They knew! they understood! This beast of fire and
tireless wheels was doing its best to get the eggs to Agassiz!
“We swung out past the Blue Hills, and yonder flashed the morning
sun from the towering dome of the State House. I might have
leaped from the cab and run the rest of the way on foot, had I not
caught the eye of the engineer watching me narrowly. I was not in
Boston yet, nor in Cambridge either. I was an escaped lunatic, who
had held up a train, and forced it to carry me from Middleboro to
Boston.
“Perhaps I had overdone the lunacy business. Suppose these two
men should take it into their heads to turn me over to the police,
whether I would or no? I could never explain the case in time to get
the eggs to Agassiz. I looked at my watch. There were still a few
minutes left in which I might explain to these men, who, all at once,
had become my captors. But how explain? Nothing could avail
against my actions, my appearance, and my little pail of sand.
“I had not thought of my appearance before. Here I was, face and
clothes caked with yellow mud, my hair wild and matted, my hat
gone, and in my full-grown hands a tiny tin pail of sand, as if I had
been digging all night with a tiny tin shovel on the shore! And thus
to appear in the decent streets of Boston of a Sunday morning!
“I began to feel like a lunatic. The situation was serious, or might
be, and rather desperately funny at its best. I must in some way
have shown my new fears, for both men watched me more sharply.
“Suddenly, as we were nearing the outer freight-yard, the train
slowed down and came to a stop. I was ready to jump, but still I
had no chance. They had nothing to do, apparently, but to guard
me. I looked at my watch again. What time we had made! It was
only six o’clock,—a whole hour left in which to get to Cambridge!
“But I didn’t like this delay. Five minutes—ten—went by.
“‘Gentlemen,’ I began, but was cut short by an express train coming
past. We were moving again, on—into a siding—on to the main track
—on with a bump and a crash and a succession of crashes, running
the length of the train—on, on at a turtle’s pace, but on,—when the
fireman, quickly jumping for the bell-rope, left the way to the step
free, and—
“I never touched the step, but landed in the soft sand at the side of
the track, and made a line for the freight-yard fence.
“There was no hue or cry. I glanced over my shoulder to see if they
were after me. Evidently their hands were full, or they didn’t know I
had gone.
“But I had gone; and was ready to drop over the high board-fence,
when it occurred to me that I might drop into a policeman’s arms.
Hanging my pail in a splint on top of a post, I peered cautiously over
—a very wise thing to do before you jump a high board-fence.
There, crossing the open square toward the station, was a big, burly
fellow with a club—looking for me!
“I flattened for a moment, when some one in the freight-yard yelled
at me. I preferred the policeman, and, grabbing my pail, I slid softly
over to the street. The policeman moved on past the corner of the
station out of sight. The square was free, and yonder stood a cab.
“Time was flying now. Here was the last lap. The cabman saw me
coming, and squared away. I waved a dollar-bill at him, but he only
stared the more. A dollar can cover a good deal, but I was too much
for one dollar. I pulled out another, thrust them both at him, and
dodged into the cab, calling, ‘Cambridge!’
“He would have taken me straight to the police-station, had I not
said, ‘Harvard College. Professor Agassiz’s house! I’ve got eggs for
Agassiz,’ pushing another dollar up at him through the hole.
“It was nearly half past six.
“‘Let him go!’ I ordered. ‘Here’s another dollar if you make Agassiz’s
house in twenty minutes. Let him out; never mind the police!’
“He evidently knew the police, or there were none around at that
time on a Sunday morning. We went down the sleeping streets, as I
had gone down the wood-roads from the pond two hours before,
but with the rattle and crash now of a fire brigade. Whirling a corner
into Cambridge Street, we took the bridge at a gallop, the driver
shouting out something in Hibernian to a pair of waving arms and a
belt and brass buttons.
“Across the bridge with a rattle and jolt that put the eggs in
jeopardy, and on over the cobble-stones, we went. Half standing, to
lessen the jar, I held the pail in one hand and held myself in the
other, not daring to let go even to look at my watch.
“But I was afraid to look at the watch. I was afraid to see how near
to seven o’clock it might be. The sweat was dropping down my nose,
so close was I running to the limit of my time.
“Suddenly there was a lurch, and I dived forward, ramming my head
into the front of the cab, coming up with a rebound that landed me
across the small of my back on the seat, and sent half of my pail of
eggs helter-skelter over the floor.
“We had stopped. Here was Agassiz’s house; and without taking
time to pick up the eggs that were scattered, I jumped out with my
pail and pounded at the door.
“No one was astir in the house. But I would stir some one. And I did.
Right in the midst of the racket the door opened. It was the maid.
“‘Agassiz,’ I gasped, ‘I want Professor Agassiz, quick!’ And I pushed
by her into the hall.
“‘Go ’way, sir. I’ll call the police. Professor Agassiz is in bed. Go ’way,
sir!’
“‘Call him—Agassiz—instantly, or I’ll call him myself.’
“But I didn’t; for just then a door overhead was flung open, a great
white-robed figure appeared on the dim landing above, and a quick
loud voice called excitedly,—
“‘Let him in! Let him in. I know him. He has my turtle eggs!’
“And the apparition, slipperless, and clad in anything but an
academic gown, came sailing down the stairs.
“The maid fled. The great man, his arms extended, laid hold of me
with both hands, and dragging me and my precious pail into his
study, with a swift, clean stroke laid open one of the eggs, as the
watch in my trembling hands ticked its way to seven—as if nothing
unusual were happening to the history of the world.”
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.
textbookfull.com