Internet Of Things 101 Intel® Edison
  • Cover
  • Summary
  • About This Traning
    • Objectives
    • Skills
    • Prerequisites
    • Requirements
  • Once Upon A Time ...
  • Internet Of Things
    • Examples
    • Consortiums
    • Resources
      • Architecture
      • Associations
      • Awards
      • Contests
      • Events
      • Investors
      • Job Roles
      • People
      • Programming Languages
      • Projects
      • Standards
      • Tendencies
      • Training
        • Coursera
      • Licensing
      • Sites
    • Key Players
      • Amazon
      • Apple
      • ARM
      • AT&T
      • Atari
      • Axeda
      • Bosch
      • Cisco
      • Dell
      • Eclipse
      • Facebook
      • General Electric
      • Google
      • Hewlett Packard
      • Huawei
      • IBM
      • Intel
        • Tools
      • IoT Ticket
      • Libelium
      • Oracle
      • Others
      • Mediatek
      • Micrium
      • Microchip
      • Microsoft
      • Mozilla
      • NXP
      • NVIDIA
      • Nokia
      • Predixion
      • PTC
      • Qualcomm
      • RedHat
      • Renesas
      • Salesforce
      • Samsung
      • SAP
      • Schneider Electric
      • Telefonica
      • Texas Instruments
      • ThingWorx
      • Verizon
      • Vodafone
      • C2M
  • Architecture
    • Thing
      • Boards
        • Arduino
        • Beagleboard
        • C.H.I.P.
        • Raspberry Pi
        • ESP8266
        • Intel Architecture
          • Development Workstation
      • Boot Loaders
        • Labs
      • Operating Systems
      • Embedded Linux
        • Board Support Package
          • Labs
        • Boot Up
          • Labs
        • Command Line Interface
          • Labs
        • File Systems
          • Labs
        • Text Editors
          • Labs
        • Package Management System
          • Labs
        • Version Control Systems
          • Labs
        • Programming Languages
          • Python
          • PiP Package Management System
          • Labs
        • Libraries
          • Labs
      • Integrated Development Environments
    • Data
      • Sensors
        • Labs
        • Project
      • Actuators
        • Labs
        • Project
      • Local Operations
      • Frameworks
    • Gateways
      • Intel® IoT Gateways
    • Communications
      • Connectivity
        • Labs
      • Protocols
        • RESTful
          • Labs
        • MQTT
          • Labs
          • Project
    • Cloud Computing
      • Application Programming Interface
        • Labs
        • Project
      • Services
        • Labs
      • Platforms
        • Labs
  • Wrap-Up
    • Online Training
    • Challenge
  • SandBox
    • Sandbox-NonIT
    • IoTPy
    • Analytics
    • Security
    • Cloud
Powered by GitBook
On this page
  • Programming Languages Labs
  • Project: Base Code Hello
  • Project: Signal Handler
  1. Architecture
  2. Thing
  3. Embedded Linux
  4. Programming Languages

Labs

Programming Languages Labs

Project: Base Code Hello

Go to your git "TheIoTLearningInitiative" repository, under "InternetOfThings101" directory

    root@board:~# cd TheIoTLearningInitiative/InternetOfThings101
    root@board:~/TheIoTLearningInitiative/InternetOfThings101#

Create a file called main.py to host our project code and print in console "Hello Internet of Things 101"

    root@board:~/TheIoTLearningInitiative/InternetOfThings101# vi main.py
#!/usr/bin/python

import time

if __name__ == '__main__':

    while True:
        print "Hello Internet of Things 101"
        time.sleep(5)

# End of File
    root@board:~/TheIoTLearningInitiative/InternetOfThings101# python main.py
    Hello Internet of Things 101
    ^C
    Traceback (most recent call last):
      File "main.py", line 11, in <module>
        time.sleep(5)
    KeyboardInterrupt
    root@board:~/TheIoTLearningInitiative/InternetOfThings101#
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git status
On branch master
Your branch is up-to-date with 'origin/master'.

Untracked files:
  (use "git add <file>..." to include in what will be committed)

        main.py

nothing added to commit but untracked files present (use "git add" to track)
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git add main.py 
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        new file:   main.py                                                                          
root@edison:~/TheIoTLearningInitiative/InternetOfThings101#
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git commit -s
Internet of Things 101: 5.1.4.6 PL: Project: Base Code Hello

Create a file called main.py to host our project code and print in
console "Hello Internet of Things 101"

Signed-off-by: Name LastName <email@gmail.com>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is up-to-date with 'origin/master'.
#
# Changes to be committed:
#       new file:   main.py
#
[master 4d18e65] Internet of Things 101: 5.1.4.6 PL: Project: Base Code Hello
 1 file changed, 11 insertions(+)
 create mode 100644 InternetOfThings101/main.py
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git status
On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

nothing to commit, working directory clean
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git push
Username for 'https://github.com': 
Password for 'https://xe1gyq@github.com': 
Counting objects: 4, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 648 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)
To https://github.com/xe1gyq/TheIoTLearningInitiative.git
   7b6f34c..b197227  master -> master
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git show
commit b1972276af178f5542e4c6a1219dfd363bb16e1b
Author: Name LastName <email@gmail.com>
Date:   Sat Apr 30 22:21:44 2016 +0000

    Internet of Things 101: 5.1.4.6 PL: Project: Base Code Hello

    Create a file called main.py to host our project code and print in
    console "Hello Internet of Things 101"

    Signed-off-by: Name LastName <email@gmail.com>

diff --git a/InternetOfThings101/main.py b/InternetOfThings101/main.py
new file mode 100644
index 0000000..0311096
--- /dev/null
+++ b/InternetOfThings101/main.py
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+
+import time
+
+if __name__ == '__main__':
+
+    while True:
+        print "Hello Internet of Things 101"
+        time.sleep(5)
+
+# End of File
(END)

Project: Signal Handler

Add function to handle signals e.g. CTRL-Z

    root@edison:~/TheIoTLearningInitiative/InternetOfThings101# vi main.py
#!/usr/bin/python

import signal
import sys
import time

def functionSignalHandler(signal, frame):
    sys.exit(0)

if __name__ == '__main__':

    signal.signal(signal.SIGINT, functionSignalHandler)

    while True:
        print "Hello Internet of Things 101"
        time.sleep(5)

# End of File
    root@edison:~/TheIoTLearningInitiative/InternetOfThings101# python main.py 
    Hello Internet of Things 101
    ^Z
    [1]+  Stopped(SIGTSTP)        python main.py
    root@edison:~/TheIoTLearningInitiative/InternetOfThings101#
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   main.py

no changes added to commit (use "git add" and/or "git commit -a")
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git add main.py 
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   main.py
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git commit -s
Internet of Things 101: 5.1.4.6 PL: Project: Signal Handler

Add function to handle signals e.g. CTRL-Z

Signed-off-by: Name LastName <email@gmail.com>

# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
# On branch master
# Your branch is up-to-date with 'origin/master'.
#
# Changes to be committed:
#       modified:   main.py
[master ce05cfa] Internet of Things 101: 5.1.4.6 PL: Project: Signal Handler
 1 file changed, 7 insertions(+)
root@edison:~/TheIoTLearningInitiative/InternetOfThings101#
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git push
Username for 'https://github.com':                                    
Password for 'https://xe1gyq@github.com':
Counting objects: 4, done.                                                              
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 679 bytes | 0 bytes/s, done.
Total 4 (delta 0), reused 0 (delta 0)                                              
To https://github.com/xe1gyq/TheIoTLearningInitiative.git
   b197227..ce05cfa  master -> master                                              
root@edison:~/TheIoTLearningInitiative/InternetOfThings101#
commit ce05cfa63558da802eed7e79d66b7bbae6c677b9
Author: Name LastName <email@gmail.com>
Date:   Sat Apr 30 22:38:39 2016 +0000
    Internet of Things 101: 5.1.4.6 PL: Project: Signal Handler

    Add function to handle signals e.g. CTRL-Z

    Signed-off-by: Name LastName <email@gmail.com>

diff --git a/InternetOfThings101/main.py b/InternetOfThings101/main.py
index 0311096..f2f1045 100644
--- a/InternetOfThings101/main.py
+++ b/InternetOfThings101/main.py
@@ -1,9 +1,16 @@
 #!/usr/bin/python

+import signal
+import sys
 import time

+def functionSignalHandler(signal, frame):
+    sys.exit(0)
+
 if __name__ == '__main__':

+    signal.signal(signal.SIGINT, functionSignalHandler)
+
     while True:
         print "Hello Internet of Things 101"
         time.sleep(5)
(END)

Your github repository directory structure shall be at this point as follows:

TheIoTLearningInitiative Github Repository
https://github.com/YourGithubUserName/TheIoTLearningInitiative
├── LICENSE
├── README.md
├── InternetOfThings101
│   ├── README.md
│   ├── main.py
PreviousPiP Package Management SystemNextLibraries

Last updated 7 years ago