O'REILLY Getting Started with the Internet of Things.pdf

(6435 KB) Pobierz
972342222.001.png
972342222.002.png
Getting
Started with
the Internet
of Things
Cuno Pister
972342222.003.png
Getting Started with the
Internet of Things
by Cuno Pfister
Copyright © 2011 Cuno Pfister. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc.
1005 Gravenstein Highway North, Sebastopol, CA 95472
O’Reilly books may be purchased for educational, business, or
sales promotional use. Online editions are also available for most
titles ( http://my.safaribooksonline.com ). For more information,
contact our corporate/institutional sales department:
800-998-9938 or corporate@oreilly.com .
Print History: May 2011: First Edition.
Editor: Brian Jepson
Production Editor: Jasmine Perez
Copyeditor: Marlowe Shaeffer
Proofreader: Emily Quill
Compositor: Nancy Wolfe Kotary
Indexer: Angela Howard
Illustrations: Marc de Vinck
Cover Designer: Marc de Vinck
The O’Reilly logo is a registered trademark of O’Reilly Media, Inc.
The Make: Projects series designations and related trade dress
are trademarks of O’Reilly Media, Inc. The trademarks of third
parties used in this work are the property of their respective
owners.
Many of the designations used by manufacturers and sellers to
distinguish their products are claimed as trademarks. Where
those designations appear in this book, and O’Reilly Media, Inc.
was aware of a trademark claim, the designations have been
printed in caps or initial caps.
While every precaution has been taken in the preparation of
this book, the publisher and author assume no responsibility
for errors or omissions, or for damages resulting from the use
of the information contained herein.
ISBN: 978-1-4493-9357-1
[LSI]
Contents
Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . v
I / Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1 / Hello World. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Setting Up the Development Environment. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
HelloWorld . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Building the Program in Visual Studio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Deploying to the Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2 / Writing to Actuators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
BlinkingLed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
3 / Reading from Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
LightSwitch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
VoltageReader. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .20
II / Device as HTTP Client . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4 / The Internet of Things . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
HTTP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .30
Push Versus Pull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
5 / Pachube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6 / Hello Pachube. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Setting Up the Network Coniguration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .43
HelloPachube . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .48
What Netduino Said to Pachube. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
What Pachube Said to Netduino. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7 / Sending HTTP Requests—The Simple Way . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
SimplePutRequest . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Making Web Requests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .64
8 / Sending HTTP Requests—The Eficient Way. . . . . . . . . . . . . . . . . . . . . . . . . . 71
EficientPutRequest. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
9 / Hello Pachube (Sockets Version) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
PachubeClient . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
Contents iii
Zgłoś jeśli naruszono regulamin