Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Events
Videos
Audiobooks
Packt Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
Arrow up icon
GO TO TOP
Mastering IOT

You're reading from   Mastering IOT Build modern IoT solutions that secure and monitor your IoT infrastructure

Arrow left icon
Product type Course
Published in Apr 2019
Publisher Packt
ISBN-13 9781838645434
Length 782 pages
Edition 1st Edition
Arrow right icon
Authors (2):
Arrow left icon
Colin Dow Colin Dow
Author Profile Icon Colin Dow
Colin Dow
Perry Lea Perry Lea
Author Profile Icon Perry Lea
Perry Lea
Arrow right icon
View More author details
Toc

Table of Contents (34) Chapters Close

Title Page
Copyright
About Packt
Contributors
Preface
1. The IoT Story FREE CHAPTER 2. IoT Architecture and Core IoT Modules 3. Sensors, Endpoints, and Power Systems 4. Communications and Information Theory 5. Non-IP Based WPAN 6. IP-Based WPAN and WLAN 7. Long-Range Communication Systems and Protocols (WAN) 8. Routers and Gateways 9. IoT Security 10. Installing Raspbian on the Raspberry Pi 11. Writing Python Programs Using Raspberry Pi 12. Using the GPIO to Connect to the Outside World 13. Subscribing to Web Services 14. Controlling a Servo with Python 15. Working with the Servo Control Code to Control an Analog Device 16. Setting Up a Raspberry Pi Web Server 17. Reading Raspberry Pi GPIO Sensor Data Using Python 18. Building a Home Security Dashboard 19. Publishing to Web Services 20. Creating a Doorbell Button Using Bluetooth 21. Enhancing Our IoT Doorbell 22. Introducing the Raspberry Pi Robot Car 23. Controlling the Robot Car Using Python 24. Connecting Sensory Inputs from the Robot Car to the Web 25. Controlling the Robot Car with Web Service Calls 26. Building the JavaScript Client 27. Putting It All Together 1. Other Books You May Enjoy Index

Using the Python command line


Let's start doing some coding. Whenever I start using a new operating system for development, I like to go through some basics just to get my mind back into it (I'm speaking particularly to those of us who are all too familiar with coding into the wee hours of the morning).

The simplest way to access Python is from the Terminal. We will run a simple program to get started. Load the Terminal from the main toolbar and type python3 at the prompt. Type the following line and hit Enter:

from datetime import datetime

This line loads the datetime object from the datetime module into our instance of Python. Next type the following and hit Enter:

print(datetime.now())

You should see the current date and time printed to the screen:

Let's try another example. Type the following into the shell:

import pyjokes

This is a library that's used to tell programming jokes. To have a joke printed out, type the following and hit Enter:

pyjokes.get_joke()

You should see the following output...

lock icon The rest of the chapter is locked
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Mastering IOT
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Modal Close icon
Modal Close icon