Line: 1 to 1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
![]() Slide 1: Introduction to Internet of Things (IoT) | |||||||||
Line: 379 to 379 | |||||||||
We can therefore find out if the module is imported or executed by checking the name variable: | |||||||||
Changed: | |||||||||
< < | _if name_ == "__main__" | ||||||||
> > | if _name_ == "__main__" | ||||||||
this executes the main code only if not imported into a main program
| |||||||||
Line: 435 to 435 | |||||||||
A very typical example of a python library is matplotlib for plotting. | |||||||||
Changed: | |||||||||
< < | ![]() | ||||||||
> > | ![]() | ||||||||
Changed: | |||||||||
< < | ![]() | ||||||||
> > | ![]() | ||||||||
Callbacks | |||||||||
Changed: | |||||||||
< < | ![]() | ||||||||
> > | Callbacks are very often used in Graphical User Interface (GUI systems)
GUI elements (widgets) are set up by the programmer and events are attached to them.
Typical examples are:
A Dummy GUIOur dummy GUI allows to register a callback and if one is registered it will call it every 2 s.![]() The application running the dummy GUIThe application first registers the callback and then gives control to the dummy GUI main loop. The main loop will wait for an event (2 s elapsed) and call the callback function when the event has occurred.![]() | ||||||||
%SLIDESHOWEND% | |||||||||
Line: 483 to 514 | |||||||||
| |||||||||
Added: | |||||||||
> > |
|
Line: 1 to 1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
![]() Slide 1: Introduction to Internet of Things (IoT) | |||||||||
Line: 222 to 222 | |||||||||
The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. | |||||||||
Changed: | |||||||||
< < | ![]() | ||||||||
> > | ![]() | ||||||||
Data Types in PythonPrograms store data in one form or the other and must be of a certain type. | |||||||||
Line: 312 to 312 | |||||||||
We have seen conditions already in the very first example | |||||||||
Changed: | |||||||||
< < | ![]() | ||||||||
> > | ![]() | ||||||||
LoopsA loop statement allows us to execute a statement or group of statements multiple times. | |||||||||
Line: 379 to 379 | |||||||||
We can therefore find out if the module is imported or executed by checking the name variable: | |||||||||
Changed: | |||||||||
< < | if _name_ == "__main__" | ||||||||
> > | _if name_ == "__main__" | ||||||||
this executes the main code only if not imported into a main program
| |||||||||
Line: 415 to 415 | |||||||||
The syntax for creation of classes is similar to functions | |||||||||
Changed: | |||||||||
< < | ![]() | ||||||||
> > | ![]() | ||||||||
You may define a method with name __init__which is called when | |||||||||
Changed: | |||||||||
< < | the instance object of the class is created (in the above example: mc = !<a href="https://afnog.iotworkshop.africa/do/edit/AFNOG/MyClass?topicparent=AFNOG.IntroductionToPython;nowysiwyg=0" rel="nofollow" title="MyClass (this topic does not yet exist; you can create it)"> MyClass </a> () | ||||||||
> > | the instance object of the class is created (in the above example: mc = MyClass) | ||||||||
Changed: | |||||||||
< < | The short description of the class can be found in the instance variable _ _doc__ | ||||||||
> > | The short description of the class can be found in the instance variable __Doc.__ | ||||||||
Classes Example | |||||||||
Line: 435 to 435 | |||||||||
A very typical example of a python library is matplotlib for plotting. | |||||||||
Changed: | |||||||||
< < | ![]() | ||||||||
> > | ![]() ![]() | ||||||||
Callbacks![]() | |||||||||
Line: 460 to 462 | |||||||||
| |||||||||
Changed: | |||||||||
< < |
| ||||||||
> > |
| ||||||||
| |||||||||
Line: 475 to 477 | |||||||||
| |||||||||
Changed: | |||||||||
< < |
| ||||||||
> > |
| ||||||||
| |||||||||
Added: | |||||||||
> > |
|
Line: 1 to 1 | |||||||||
---|---|---|---|---|---|---|---|---|---|
![]() Slide 1: Introduction to Internet of Things (IoT) | |||||||||
Line: 6 to 6 | |||||||||
Introduction of Lecturers
| |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
The TWiki serverAll information about this tutorial is available on a TWiki server. | |||||||||
Line: 26 to 26 | |||||||||
Micropython Demos:
https://github.com/uraich/MicroPython_IoTDemos![]() https://github.com/uraich/MicropythonCayenneMQTTClient ![]() C++ version: https://github.com/uraich/C-IoTDemos ![]() | |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
Workshop Page![]() | |||||||||
Added: | |||||||||
> > | What is the “I” in IoT ? | ||||||||
Changed: | |||||||||
< < | The Internet of Things (IoT)When the Internet was invented it was used for communications between humans Typical applications where:
| ||||||||
> > | The “I” stands for Internet. This means: We need a processor (IoT node) that can connect to the Internet. It must be powerful enough to run Internet protocols and it needs an interface to the Internet.
Standard way to access the InternetUsually the Internet is used by humansTypical applications are
!IoT: “Things” communicate also without human intervention. Things, Sensors, Actuators
The IoT systemWe need a system with a number of processors that read out sensors and/or control actuatorsThese processors communicate with each other over the Internet with or without human intervention. Design decisions:
The Raspberry Pi
Arduino + WiFi shield![]()
The ideal IoT solution?
CommunicationMQTT (Message Queuing Telemetry Transport: a publish-subscribe basedMessage protocol running of top of TCP. A processor can subscribe to messages of a certain “topic” and/or it can push its results on a certain topic ![]() Programming language
| ||||||||
Introduction to PythonThe python programming language is a high level programming language that is very interactive and object oriented. | |||||||||
Line: 64 to 124 | |||||||||
For Python beginners: https://docs.python.org/3/tutorial/index.html![]() and for everybody the Python docs: https://docs.python.org/3/index.html ![]() | |||||||||
Added: | |||||||||
> > | |||||||||
Writing Python ProgramsPython is a programming language that lets you work more quickly and integrate your systems more effectively. | |||||||||
Line: 74 to 135 | |||||||||
| |||||||||
Added: | |||||||||
> > | |||||||||
Using the Command Line (Interactive mode)Simply type python in your terminal and press the enter key to start the interactive python mode. | |||||||||
Line: 83 to 145 | |||||||||
![]() | |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
Using the script modeUsing the interactive mode doesn’t keep the statements of code we wrote permanently . | |||||||||
Line: 95 to 157 | |||||||||
![]() ![]() | |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
Using ThonnyInstead of running a standard editor like nano or emacs you may want to run | |||||||||
Line: 109 to 171 | |||||||||
For basic description of Thonny check https://thonny.org/![]() ![]() | |||||||||
Added: | |||||||||
> > | |||||||||
Thonny Python Shell and EditorHere you see the 2 idle windows. | |||||||||
Line: 116 to 179 | |||||||||
The top one contains the editor, the second the Python shell
![]() | |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
Running a python scriptScript in python can be run from the Linux command shell with: | |||||||||
Line: 128 to 191 | |||||||||
any compiled C program or any bash script:
![]() | |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
Command Line ArgumentsPrograms can be called with arguments. | |||||||||
Line: 142 to 205 | |||||||||
![]() ![]() | |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
VariablesVariables are just memory allocations for storing values. | |||||||||
Line: 159 to 222 | |||||||||
The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. | |||||||||
Changed: | |||||||||
< < | ![]() | ||||||||
> > | ![]() | ||||||||
Data Types in PythonPrograms store data in one form or the other and must be of a certain type. | |||||||||
Line: 171 to 234 | |||||||||
| |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
Strings in PythonStrings in Python are identified as a contiguous set of characters represented in the quotation marks. | |||||||||
Line: 179 to 242 | |||||||||
Python accepts either pair of single, double quotes and triples(single/double) quotes.
![]() | |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
List in PythonThe list is a most versatile datatype available in Python. | |||||||||
Line: 193 to 256 | |||||||||
The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes starting at 0 in the beginning of the list and working their way to end -1. ![]() | |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
Tuple in PythonTuples are much more like a list. | |||||||||
Line: 205 to 268 | |||||||||
Thus tuples are read only.
![]() | |||||||||
Added: | |||||||||
> > | |||||||||
Dictionary in PythonA dictionary is a collection which is unordered, changeable and indexed. | |||||||||
Line: 220 to 284 | |||||||||
You can loop through all the key-value pairs, all the keys, or all the values.
![]() | |||||||||
Changed: | |||||||||
< < | |||||||||
> > | |||||||||
Basic OperatorsPython supports multiple operators including | |||||||||
Line: 231 to 295 | |||||||||
| |||||||||
Added: | |||||||||
> > | |||||||||
Arithmetic Operators:The arithmetic operators supported by python is addition(+) , subtraction(-),multiplication(* ), division(/), modulus(%), exponent(**) ![]() | |||||||||
Added: | |||||||||
> > | |||||||||
Python Bitwise OperatorsBitwise operator works on bits and performs bit-by-bit operation![]() | |||||||||
Added: | |||||||||
> > | Conditional StatementsWe have seen conditions already in the very first example![]() LoopsA loop statement allows us to execute a statement or group of statements multiple times. Python has two primitive loop commands:
![]() FunctionsPrograms are written in blocks of codes which are reusable but performs similar actions. Python comes with builtin functions such as print(). Users can define and use their own functions in the code. User defined functions begin with the keyword def followed by the name of the function. A function may take parameters![]() ModulesModules in a python are file with .py extensions containingdefinitions of functions or variables. We may want to keep function definitions in separate files and use these definitions in several main programs. In our example of the functions we can save the definitions in a file called function.py In order to use the definitions we must import them with import function In order to call the functions we have to use the module name: function.sum(20,30) or if we we want to import a single function: from function import sum sum(20,30) The module name is found in the variable name Modules Examples![]() Executing ModulesOften modules contain only function or class (see later) definitions However it is also possible to include the function calls (the main routine) into the module e.g. to demonstrate how the functions are to be used. In this case the name of the module changes to __main__We can therefore find out if the module is imported or executed by checking the name variable: if _name_ == "__main__" this executes the main code only if not imported into a main program PackagesPackages simple group of modules under one name. Each package is a directory which MUST contain a a specific file calle __init__.py which indicating the directory is a package. the init.py file may be empty. Package can be imported the same way as module. Suppose we have several modules prime.py, fibonacci.py, factorial.py in a directory, we may group them in a package called priff.![]() Classes
Almost everything in Python is an object, with its properties and methods.
A class defines the behavior of an object and the kind of information an object can store.
The information in a class is stored in attributes, and functions that belong to a class are called methods.
A child class inherits the attributes and methods from its parent class.
| ||||||||
%SLIDESHOWEND% | |||||||||
Line: 274 to 473 | |||||||||
| |||||||||
Added: | |||||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
![]() Slide 1: Introduction to Internet of Things (IoT) | ||||||||
Line: 261 to 261 | ||||||||
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
| |||||||
| ||||||||
Line: 271 to 271 | ||||||||
| ||||||||
Added: | ||||||||
> > |
|
Line: 1 to 1 | |||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
![]() Slide 1: Introduction to Internet of Things (IoT) | |||||||||||||||||
Line: 170 to 170 | |||||||||||||||||
| |||||||||||||||||
Changed: | |||||||||||||||||
< < |
| ||||||||||||||||
> > | |||||||||||||||||
Changed: | |||||||||||||||||
< < | String in Python | ||||||||||||||||
> > | Strings in Python | ||||||||||||||||
Strings in Python are identified as a contiguous set of characters represented in the quotation marks. Python accepts either pair of single, double quotes and triples(single/double) quotes. | |||||||||||||||||
Changed: | |||||||||||||||||
< < | ![]() | ||||||||||||||||
> > | ![]() | ||||||||||||||||
List in Python | |||||||||||||||||
Line: 193 to 192 | |||||||||||||||||
The values stored in a list can be accessed using the slice operator ([ ] and [:]) with indexes starting at 0 in the beginning of the list and working their way to end -1. | |||||||||||||||||
Changed: | |||||||||||||||||
< < | ![]() | ||||||||||||||||
> > | ![]() | ||||||||||||||||
Tuple in PythonTuples are much more like a list. | |||||||||||||||||
Line: 205 to 204 | |||||||||||||||||
Thus tuples are read only. | |||||||||||||||||
Changed: | |||||||||||||||||
< < | %SLIDESHOWEND% | ||||||||||||||||
> > | ![]() Dictionary in PythonA dictionary is a collection which is unordered, changeable and indexed. In Python dictionaries are written with curly brackets, and they have keys and values. Python's dictionaries allow you to connect pieces of related information. Each piece of information in a dictionary is stored as a key-value pair. When you provide a key, Python returns the value associated with that key. You can loop through all the key-value pairs, all the keys, or all the values.![]() Basic OperatorsPython supports multiple operators including
Arithmetic Operators:The arithmetic operators supported by python is addition(+) , subtraction(-),multiplication(* ), division(/), modulus(%), exponent(**) ![]() Python Bitwise OperatorsBitwise operator works on bits and performs bit-by-bit operation![]() %SLIDESHOWEND% | ||||||||||||||||
-- ![]() | |||||||||||||||||
Line: 226 to 263 | |||||||||||||||||
| |||||||||||||||||
Changed: | |||||||||||||||||
< < |
| ||||||||||||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
![]() Slide 1: Introduction to Internet of Things (IoT) | ||||||||
Line: 159 to 159 | ||||||||
The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. | ||||||||
Changed: | ||||||||
< < | ![]() | |||||||
> > | ![]() Data Types in PythonPrograms store data in one form or the other and must be of a certain type. We discuss the following data types
String in PythonStrings in Python are identified as a contiguous set of characters represented in the quotation marks. Python accepts either pair of single, double quotes and triples(single/double) quotes.![]() List in PythonThe list is a most versatile datatype available in Python. It can be written as a list of comma-separated values (items) between square [] brackets. A list need not be of the same type. The values present in a list are indexed starting from zero. The values stored in a list can be accessed using the slice operator ([ ] and [:]) withindexes starting at 0 in the beginning of the list and working their way to end -1. ![]() Tuple in PythonTuples are much more like a list. They are enclosed in brackets(). Their content cannot be changed unlike the list whose content can be changed. Thus tuples are read only. | |||||||
%SLIDESHOWEND% | ||||||||
Line: 167 to 211 | ||||||||
Comments | ||||||||
Changed: | ||||||||
< < | ||||||||
> > | ||||||||
| ||||||||
Line: 182 to 226 | ||||||||
| ||||||||
Added: | ||||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
![]() Slide 1: Introduction to Internet of Things (IoT) | ||||||||
Line: 96 to 96 | ||||||||
![]() | ||||||||
Changed: | ||||||||
< < | Using Idle | |||||||
> > | Using Thonny | |||||||
Instead of running a standard editor like nano or emacs you may want to run an Integrated Development Environment (IDE) created specifically for Python instead. | ||||||||
Changed: | ||||||||
< < | Lets try idle | |||||||
> > | Thonny is Easy to get started. Thonny comes with Python 3.7 built in, so just one simple installer is needed and you're ready to learn programming. | |||||||
Changed: | ||||||||
< < | ![]() | |||||||
> > | It is very suitable for beginners and programming micro-controllers | |||||||
Changed: | ||||||||
< < | Idle Python Shell and Editor | |||||||
> > | For basic description of Thonny check https://thonny.org/![]() ![]() Thonny Python Shell and Editor | |||||||
Here you see the 2 idle windows. The top one contains the editor, the second the Python shell | ||||||||
Changed: | ||||||||
< < | ![]() ![]() | |||||||
> > | ![]() | |||||||
Changed: | ||||||||
< < | Running the Program | |||||||
> > | Running a python script | |||||||
Script in python can be run from the Linux command shell with: | ||||||||
Line: 158 to 159 | ||||||||
The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. | ||||||||
Changed: | ||||||||
< < | ![]() | |||||||
> > | ![]() | |||||||
%SLIDESHOWEND% | ||||||||
Line: 179 to 180 | ||||||||
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
![]() Slide 1: Introduction to Internet of Things (IoT) | ||||||||
Line: 21 to 21 | ||||||||
https://afnog.iotworkshop.africa/do/view | ||||||||
Added: | ||||||||
> > | Other pages for class resources
Micropython Demos:
https://github.com/uraich/MicroPython_IoTDemos![]() https://github.com/uraich/MicropythonCayenneMQTTClient ![]() C++ version: https://github.com/uraich/C-IoTDemos ![]() | |||||||
Workshop Page![]() | ||||||||
Line: 56 to 62 | ||||||||
| ||||||||
Added: | ||||||||
> > | For Python beginners: https://docs.python.org/3/tutorial/index.html![]() and for everybody the Python docs: https://docs.python.org/3/index.html ![]() | |||||||
Writing Python ProgramsPython is a programming language that lets you work more quickly and integrate your systems more effectively. | ||||||||
Line: 171 to 179 | ||||||||
| ||||||||
Changed: | ||||||||
< < |
| |||||||
> > |
|
Line: 1 to 1 | |||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
![]() Slide 1: Introduction to Internet of Things (IoT) | |||||||||||||||||||||||
Line: 41 to 41 | |||||||||||||||||||||||
This is what we call the Internet of Things (IoT) | |||||||||||||||||||||||
Added: | |||||||||||||||||||||||
> > | Introduction to PythonThe 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?
Writing Python ProgramsPython is a programming language that lets you work more quickly and integrate your systems more effectively.
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.![]() Using the script modeUsing the interactive mode doesn’t keep the statements of code we wrote permanently . But in an ideal situation we might want to keep the codes for future reference. Hence we make use of an editor like the nano, emacs, etc.![]() ![]() Using IdleInstead of running a standard editor like nano or emacs you may want to run an Integrated Development Environment (IDE) created specifically for Python instead. Lets try idle![]() Idle Python Shell and EditorHere you see the 2 idle windows. The top one contains the editor, the second the Python shell![]() ![]() Running the ProgramScript 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:![]() Command Line ArgumentsPrograms can be called with arguments. Python has a module that helps users parse command-line options and arguments. Many programs can be run to provide basic information about how theyshould be run and it employs the use of command line arguments. The Python sys module provides access to any command-line arguments via the sys.argv . ![]() ![]() VariablesVariables are just memory allocations for storing values. Every variable created has a space in memory allocated for it. Based on the data type of a variable, the interpreter allocates memory anddecides what can be stored in the reserved memory. Python variables do not need explicit declaration to reserve memory space. The declaration happens automatically when you assign a value to a variable. The equal sign (=) is used to assign values to variables. The operand to the left of the = operator is the name of the variable and the operand to the right of the = operator is the value stored in the variable. ![]() | ||||||||||||||||||||||
%SLIDESHOWEND%
-- ![]() | |||||||||||||||||||||||
Line: 50 to 161 | |||||||||||||||||||||||
| |||||||||||||||||||||||
Added: | |||||||||||||||||||||||
> > |
|
Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Added: | ||||||||
> > |
![]() Slide 1: Introduction to Internet of Things (IoT)Session 1: Introduction to IoT and Python
|
META FILEATTACHMENT | attachment="workshop.png" attr="" comment="" date="1559196142" name="workshop.png" path="workshop.png" size="256416" user="IsaacArmahMensah" version="1" |
---|