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
  1. Architecture
  2. Data
  3. Sensors

Project

Implement a function to simulate a Sensor, data will be based on system-wide network I/O statistics using psutil python library, the Simulated Sensor is implemented in case no physical sensor 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 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: 1877 
^Z
[2]+  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.1 Sensors: Project: Data Collection

Implement a function to collect data, data will be based on system-wide
network I/O statistics using psutil python library, this will simulate
our sensor in case no physical sensor 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 15b9441] Internet of Things 101: 5.2.1 Sensors: Project: Data Collection
 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), 737 bytes | 0 bytes/s, done.
Total 4 (delta 1), reused 0 (delta 0)
To https://github.com/xe1gyq/TheIoTLearningInitiative.git
   ce05cfa..15b9441  master -> master
root@edison:~/TheIoTLearningInitiative/InternetOfThings101#
root@edison:~/TheIoTLearningInitiative/InternetOfThings101# git show
commit 92e8b9f26a239952b9be9f9a06502c4334a66698
Author: Name LastName <email@gmail.com>
Date:   Sat Apr 30 23:00:38 2016 +0000

    Internet of Things 101: 5.2.1 Sensors: Project: Data Collection

    Implement a function to collect data, data will be based on system-wide
    network I/O statistics using psutil python library, this will simulate
    our sensor in case no physical sensor is available

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

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

+import psutil
 import signal
 import sys
 import time

+def functionDataSensor():
+    netdata = psutil.net_io_counters()
+    data = netdata.packets_sent + netdata.packets_recv
+    return data
+
 def functionSignalHandler(signal, frame):
     sys.exit(0)

@@ -13,6 +19,7 @@ if __name__ == '__main__':

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

 # End of File
(END)
PreviousLabsNextActuators

Last updated 7 years ago