old_contents: #!/usr/bin/python
  
  import paho.mqtt.client as paho
  import psutil
  import signal
  import sys
  import time
  
  from flask import Flask
  from flask_restful import Api, Resource
  from threading import Thread
  
  def interruptHandler(signal, frame):
      sys.exit(0)
  
  def on_publish(mosq, obj, msg):
      pass
  
  def dataNetwork():
      netdata = psutil.net_io_counters()
      return netdata.packets_sent + netdata.packets_recv
  
  def dataNetworkHandler():
      idDevice = "ThisDevice"
      mqttclient = paho.Client()
      mqttclient.on_publish = on_publish
      mqttclient.connect("test.mosquitto.org", 1883, 60)
      while True:
          packets = dataNetwork()
          message = idDevice + " " + str(packets)
          print "dataNetworkHandler " + message  
          mqttclient.publish("IoT101/Network", message)
          time.sleep(1)
  
  def on_message(mosq, obj, msg):
      print "dataMessageHandler %s %s" % (msg.topic, msg.payload)
  
  def dataMessageHandler():
      mqttclient = paho.Client()
      mqttclient.on_message = on_message
      mqttclient.connect("test.mosquitto.org", 1883, 60)
      mqttclient.subscribe("IoT101/Message", 0)
      while mqttclient.loop() == 0:
          pass
  
  class Network(Resource):
      def get(self):
          data = dataNetwork()
          return data
  
  if __name__ == '__main__':
  
      signal.signal(signal.SIGINT, interruptHandler)
  
      threadx = Thread(target=dataNetworkHandler)
      threadx.start()
  
      threadx = Thread(target=dataMessageHandler)
      threadx.start()
  
      app = Flask(__name__)
      api = Api(app)
      api.add_resource(Network, '/network')
      #app.run(debug=True)
  
      while True:
          print "Hello Internet of Things 101"
          time.sleep(5)
          
  
  # End of File
  
  
  
new_contents: #!/usr/bin/python
  
  import paho.mqtt.client as paho
  import psutil
  import signal
  import sys
  import time
  
  from threading import Thread
  
  def interruptHandler(signal, frame):
      sys.exit(0)
  
  def on_publish(mosq, obj, msg):
      pass
  
  def dataNetwork():
      netdata = psutil.net_io_counters()
      return netdata.packets_sent + netdata.packets_recv
  
  def dataNetworkHandler():
      idDevice = "ThisDevice"
      mqttclient = paho.Client()
      mqttclient.on_publish = on_publish
      mqttclient.connect("test.mosquitto.org", 1883, 60)
      while True:
          packets = dataNetwork()
          message = idDevice + " " + str(packets)
          print "dataNetworkHandler " + message  
          mqttclient.publish("IoT101/Network", message)
          time.sleep(1)
  
  def on_message(mosq, obj, msg):
      print "dataMessageHandler %s %s" % (msg.topic, msg.payload)
  
  def dataMessageHandler():
      mqttclient = paho.Client()
      mqttclient.on_message = on_message
      mqttclient.connect("test.mosquitto.org", 1883, 60)
      mqttclient.subscribe("IoT101/Message", 0)
      while mqttclient.loop() == 0:
          pass
  
  if __name__ == '__main__':
  
      signal.signal(signal.SIGINT, interruptHandler)
  
      threadx = Thread(target=dataNetworkHandler)
      threadx.start()
  
      threadx = Thread(target=dataMessageHandler)
      threadx.start()
  
      while True:
          print "Hello Internet of Things 101"
          time.sleep(5)
          
  
  # End of File
  
  
  
subject: Revert "Code: Main Flask"