Project

Implement a function to wait for data, this will simulate our actuator in case no physical actuator is available

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

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

import psutil
import signal
import sys
import time

def functionDataActuator():
    print "Data Actuator"

def functionDataSensor():
    netdata = psutil.net_io_counters()
    data = netdata.packets_sent + netdata.packets_recv
    return data

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

if __name__ == '__main__':

    signal.signal(signal.SIGINT, functionSignalHandler)

    while True:
        print "Hello Internet of Things 101"
        print "Data Sensor: %s " % functionDataSensor()
        time.sleep(5)

# End of File
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# python main.py 
Hello Internet of Things 101
Data Sensor: 2380 
^Z
[3]+  Stopped(SIGTSTP)        python main.py
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git add main.py 
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git commit -s
Internet of Things 101: 5.2.2 Actuators: Project: Data Wait

Implement a function to wait for data, this will simulate our actuator
in case no physical actuator is available

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 9a1b981] Internet of Things 101: 5.2.2 Actuators: Project: Data Wait
 1 file changed, 3 insertions(+)
root@edison:~/TheIoTLearningInitiative/InternetOfThings101#
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git push
Username for 'https://github.com': xe1gyq
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), 597 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
To https://github.com/xe1gyq/TheIoTLearningInitiative.git
   f928476..9a1b981  master -> master
root@edison:~/TheIoTLearningInitiative/InternetOfThings101#
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git show
commit 9a1b981c1d0bbd000888c809c6cb310fa487c046
Author: Abraham Arce <xe1gyq@gmail.com>
Date:   Sat Apr 30 23:20:24 2016 +0000

    Internet of Things 101: 5.2.2 Actuators: Project: Data Wait

    Implement a function to wait for data, this will simulate our actuator
    in case no physical actuator is available

    Signed-off-by: Abraham Arce <xe1gyq@gmail.com>

diff --git a/InternetOfThings101/main.py b/InternetOfThings101/main.py
index 2b727e6..f6cdffa 100644
--- a/InternetOfThings101/main.py
+++ b/InternetOfThings101/main.py
@@ -5,6 +5,9 @@ import signal
 import sys
 import time

+def functionDataActuator():
+    print "Data Actuator"
+
 def functionDataSensor():
     netdata = psutil.net_io_counters()
     data = netdata.packets_sent + netdata.packets_recv
(END)

Last updated