Tags:
view all tags
---+ %SLIDESHOWSTART% ---+ Introduction to Internet of Things (!IoT) <h2 align="center">Session 1: Introduction to !IoT and Python<br /> <br />Isaac Armah-Mensah<br /> <br />University of Cape Coast, Ghana</h2> ---+ Introduction of Lecturers 1 *Uli Raich -- Formally CERN, Geneva, Switzerland* 1 *Isaac Armah-Mensah -- University of Cape Coast Ghana* ---+ The TWiki server All information about this tutorial is available on a TWiki server. TWiki uses the same documentation format as Wikipedia. This makes it very simple for the lecturer to provide on-line documentation, which can be extended by students. This is our Twiki server: <a href="iotworkshop.africa" target="_blank">https://afnog.iotworkshop.africa/do/view</a> Other pages for class resources Micropython Demos: https://github.com/uraich/MicroPython_IoTDemos and <br /> https://github.com/uraich/MicropythonCayenneMQTTClient <br /><br /> C++ version:<br /> https://github.com/uraich/C-IoTDemos <br /><br /> ---+ Workshop Page <img align="text-bottom" alt="workshop.png" height="552" src="%ATTACHURL%/workshop.png" title="workshop.png" width="700" /> ---+ The Internet of Things (!IoT) When the Internet was invented it was used for communications between humans Typical applications where: * <p>Email</p> * <p>Remote login</p> * <p>File transfers</p> With cheaper and more powerful micro-controllers devices can communicate with each other or with centralized servers over the network and they can observe their environment with dedicated sensors. This is what we call the Internet of Things (!IoT) ---+ Introduction to Python The python programming language is a high level programming language that is very interactive and object oriented. Python is an interpreted language which means that the statements which make up the python program is processed at run-time but not compiled first. Python also supports object oriented programming style which employs the use of encapsulating codes within objects. What can python be used for? * <p>Used to create web applications.</p> * <p>Used to connect to database systems.</p> * <p>It can be used to perform complex mathematics</p> * <p>It can be used in data analysis.</p> If you want to learn Python, Try the Python tutorial! For Python beginners: https://docs.python.org/3/tutorial/index.html <br /><br />and for everybody the Python docs: https://docs.python.org/3/index.html ---+ Writing Python Programs Python is a programming language that lets you work more quickly and integrate your systems more effectively. * <p>Python is powerful... and fast;</p> * <p>plays well with others;</p> * <p>runs everywhere;</p> * <p>is friendly & easy to learn;</p> * <p>is Open.</p> Python programs can either be written using any standard editor like nano, emacs as a script or can be written from the python command line. ---+ Using the Command Line (Interactive mode) Simply type python in your terminal and press the enter key to start the interactive python mode. Type print(“Hello world”). Hit enter and it prints Hello world on the screen. <img alt="commandline.png" height="369" src="%ATTACHURL%/commandline.png" title="commandline.png" width="736" /> To exit from the interactive mode, type quit(). ---+ Using the script mode <font face="Times New Roman, serif"><font size="3">Using the interactive mode doesn’t keep </font></font><font face="Times New Roman, serif"><font size="3">the</font></font><font face="Times New Roman, serif"><font size="3"> statements of code we wrote </font></font><font face="Times New Roman, serif"><font size="3">permanently </font></font><font face="Times New Roman, serif"><font size="3">. </font></font> <font face="Times New Roman, serif"><font size="3">But in an ideal situation we might want to keep the codes for future reference. </font></font> <font face="Times New Roman, serif"><font size="3">Hence we make use of an editor like the nano, emacs, </font></font><font face="Times New Roman, serif"><font size="3">etc</font></font><font face="Times New Roman, serif"><font size="3">. </font></font> <img align="text-bottom" alt="helloworld.png" height="55" src="%ATTACHURL%/helloworld.png" title="helloworld.png" width="246" /> <img alt="helloworld2.png" height="100" src="%ATTACHURL%/helloworld2.png" title="helloworld2.png" width="709" /> ---+ Using Thonny Instead of running a standard editor like nano or emacs you may want to run an<b> I</b>ntegrated<b> D</b>evelopment <b>E</b>nvironment (IDE) created specifically for Python instead. *Thonny is Easy to get started.* Thonny comes with Python 3.7 built in, <br />so just one simple installer is needed and you're ready to learn programming. It is very suitable for beginners and programming micro-controllers For basic description of Thonny check https://thonny.org/ and https://realpython.com/python-thonny/ Lets try _thonny_ ---+ Thonny Python Shell and Editor Here you see the 2 idle windows. The top one contains the editor, the second the Python shell <img alt="thonny.png" height="628" src="%ATTACHURL%/thonny.png" title="thonny.png" width="700" /> ---+ Running a python script Script in python can be run from the Linux command shell with: _python3 scriptName_ or we can make it executable and run it like we would run any compiled C program or any bash script: <img alt="runpython.png" src="%ATTACHURL%/runpython.png" title="runpython.png" /> ---+ Command Line Arguments <font face="Times New Roman, serif"><font size="3">Programs can be called with arguments.</font></font> <font face="Times New Roman, serif"><font size="3">Python has a module that helps users parse command-line options and arguments. </font></font> <font face="Times New Roman, serif"><font size="3">Many programs can be run to provide basic information about how they <br />should be run and it employs the use of command line arguments. </font></font> <font face="Times New Roman, serif"><font size="3">The Python </font></font><font face="Times New Roman, serif"><font size="3"> *sys* </font></font><font face="Times New Roman, serif"><font size="3"> module provides access to any command-line arguments via the </font></font><font face="Times New Roman, serif"><font size="3"> *sys.argv* </font></font><font face="Times New Roman, serif"><font size="3">.</font></font> <img alt="argscript.png" src="%ATTACHURL%/argscript.png" /> <img alt="runcmdlineArg.png" src="%ATTACHURL%/runcmdlineArg.png" title="runcmdlineArg.png" /> ---+ Variables <font face="Times New Roman, serif"><font size="3">Variables are just memory allocations for storing values. </font></font> <font face="Times New Roman, serif"><font size="3">Every variable created has a space in memory allocated for it.</font></font> <font face="Times New Roman, serif"><font size="3">Based on the data type of a variable, the interpreter allocates memory and <br />decides what can be stored in the reserved memory. </font></font> <font face="Times New Roman, serif"><font size="3">Python variables do not need explicit declaration to reserve memory space. </font></font> <font face="Times New Roman, serif"><font size="3">The declaration happens automatically when you assign a value to a variable. </font></font> <font face="Times New Roman, serif"><font size="3">The equal sign *(=)* is used to assign values to variables. </font></font> <font face="Times New Roman, serif"><font size="3">The operand to the left of the = operator is the name of the variable and <br />the operand to the right of the = operator is the value stored in the variable. <br /></font></font> <img alt="variable.png" height="575" src="%ATTACHURL%/variable.png" title="variable.png" width="700" /> %SLIDESHOWEND% -- %USERSIG{IsaacArmahMensah - 2019-05-30}% ---++ Comments %COMMENT%
Attachments
Attachments
Topic attachments
I
Attachment
History
Action
Size
Date
Who
Comment
png
argscript.png
r1
manage
29.7 K
2019-06-09 - 03:30
IsaacArmahMensah
png
commandline.png
r2
r1
manage
61.2 K
2019-06-09 - 02:44
IsaacArmahMensah
png
commandlinearg.png
r1
manage
15.5 K
2019-06-09 - 03:21
IsaacArmahMensah
png
helloworld.png
r2
r1
manage
5.8 K
2019-06-09 - 02:24
IsaacArmahMensah
png
helloworld2.png
r2
r1
manage
22.0 K
2019-06-09 - 02:25
IsaacArmahMensah
png
idle.png
r1
manage
105.5 K
2019-06-09 - 02:57
IsaacArmahMensah
png
idlescript.png
r1
manage
39.8 K
2019-06-09 - 03:03
IsaacArmahMensah
png
idleshell.png
r1
manage
33.7 K
2019-06-09 - 03:03
IsaacArmahMensah
png
runcmdlineArg.png
r1
manage
26.0 K
2019-06-09 - 03:30
IsaacArmahMensah
png
runpython.png
r1
manage
102.6 K
2019-06-09 - 03:14
IsaacArmahMensah
png
thonny.png
r1
manage
121.5 K
2019-06-09 - 21:02
IsaacArmahMensah
png
variable.png
r3
r2
r1
manage
74.0 K
2019-06-09 - 21:10
IsaacArmahMensah
png
workshop.png
r1
manage
250.4 K
2019-05-30 - 06:02
IsaacArmahMensah
Edit
|
Attach
|
Watch
|
P
rint version
|
H
istory
:
r11
|
r6
<
r5
<
r4
<
r3
|
B
acklinks
|
V
iew topic
|
Raw edit
|
More topic actions...
Topic revision: r4 - 2019-06-09
-
IsaacArmahMensah
Home
Site map
AFNOG web
Embedded_Systems web
IoT_Course_English web
IoT_Course_French web
Main web
Sandbox web
TWiki web
AFNOG Web
Create New Topic
Index
Search
Changes
Notifications
RSS Feed
Statistics
Preferences
P
P
P
View
Raw View
Print version
Find backlinks
History
More topic actions
Edit
Raw edit
Attach file or image
Edit topic preference settings
Set new parent
More topic actions
Account
Log In
Register User
Edit
Attach
Copyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki?
Send feedback