systemd files, documentation and a bug fix

Change-Id: I66e34059e0c1d604b82fba558bfeadee2ace093c
diff --git a/camera/README.md b/camera/README.md
new file mode 100644
index 0000000..cbe481f
--- /dev/null
+++ b/camera/README.md
@@ -0,0 +1,4 @@
+sudo systemctl status openvino-camera@*
+sudo systemctl [status|start|stop|restart] openvino-mqtt.service
+sudo systemctl [status|start|stop|restart] openvino-camera@low.service
+sudo systemctl [status|start|stop|restart] openvino-camera@high.service
diff --git a/camera/openvino-camera.sh b/camera/openvino-camera.sh
index 08d8a79..f389406 100644
--- a/camera/openvino-camera.sh
+++ b/camera/openvino-camera.sh
@@ -13,8 +13,10 @@
     width="320"
     height="240"
 else
-    width="640"
-    height="480"
+    width="1280"
+    height="960"
+#    width="640"
+#    height="480"
 fi
 host="$2"
 port="$3"
diff --git a/camera/openvino-camera@.service b/camera/openvino-camera@.service
new file mode 100644
index 0000000..53d139e
--- /dev/null
+++ b/camera/openvino-camera@.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=OpenVINO application camera
+After=multi-user.target
+
+[Service]
+ExecStart=/home/pi/openvino-camera/openvino-camera.sh %I 10.92.2.22 5000
+#ExecStart=/home/pi/openvino-camera/openvino-camera.sh %I 10.128.99.49 5000
+User=root
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/camera/openvino-mqtt.service b/camera/openvino-mqtt.service
new file mode 100644
index 0000000..3225249
--- /dev/null
+++ b/camera/openvino-mqtt.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=OpenVINO application camera
+After=multi-user.target
+
+[Service]
+ExecStart=/usr/bin/python3 /home/pi/openvino-camera/openvino-mqtt.py 10.92.2.22 5000
+#ExecStart=/usr/bin/python3 /home/pi/openvino-camera/openvino-mqtt.py 10.128.99.49 5000
+User=root
+Restart=on-failure
+
+[Install]
+WantedBy=multi-user.target
diff --git a/person_detection/app.py b/person_detection/app.py
index 0ed28eb..2ef9b87 100644
--- a/person_detection/app.py
+++ b/person_detection/app.py
@@ -3,8 +3,6 @@
 SPDX-FileCopyrightText: 2020-present Open Networking Foundation <info@opennetworking.org>
 SPDX-License-Identifier: LicenseRef-ONF-Member-1.01
 """
-from importlib import import_module
-import os
 import logging as log
 import sys
 import flask
@@ -24,6 +22,7 @@
     log.info("{} - connected".format(flask.request.remote_addr))
     return flask.render_template('index.html', devices=config.cameras)
 
+
 def gen(camera):
     """Video streaming generator function."""
     while True:
@@ -31,6 +30,7 @@
         yield (b'--frame\r\n'
                b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n')
 
+
 @app.route('/video_feed/<device>')
 def video_feed(device):
     """Video streaming route. Put this in the src attribute of an img tag."""
@@ -38,11 +38,13 @@
     log.debug("{} - video feed {}".format(flask.request.remote_addr, device))
     camera = Camera(device, flask.request.remote_addr, args)
     return flask.Response(gen(camera),
-                    mimetype='multipart/x-mixed-replace; boundary=frame')
+                          mimetype='multipart/x-mixed-replace; boundary=frame')
+
 
 def name_to_port(name):
     return int(name)
 
+
 def build_argparser():
     parser = ArgumentParser(add_help=False)
     args = parser.add_argument_group('Options')
@@ -75,17 +77,17 @@
             help = "ROC password",
             type = str)
     args.add_argument("--mbrlow",
-            help = "Low range of MBR",
-            default = 7000000,
-            type = int)
+                      help="Low range of MBR",
+                      default=7000000,
+                      type=int)
     args.add_argument("--mbrhigh",
-            help = "High range of MBR",
-            default = 10000000,
-            type = int)
+                      help="High range of MBR",
+                      default=10000000,
+                      type=int)
     args.add_argument("--devicegroup",
-            help = "Camera device group",
-            default = "menlo-4g-cameras",
-            type = str)
+                      help="Camera device group",
+                      default="menlo-4g-cameras",
+                      type=str)
 
     return parser
 
@@ -104,7 +106,7 @@
         key = args.key
         if key is None:
             if args.user is not None and args.password is not None:
-                roc = Roc(args.user, args.password)
+                roc = Roc(config.url, args.user, args.password, config.enterprise, config.site)
                 key = roc.get_key()
             else:
                 log.error("Either key or user/password required")
diff --git a/person_detection/base_camera.py b/person_detection/base_camera.py
index 53525ab..e2e85b6 100644
--- a/person_detection/base_camera.py
+++ b/person_detection/base_camera.py
@@ -1,12 +1,8 @@
 import paho.mqtt.client as mqtt
 import time
-import os
-import sys
 import threading
 import logging as log
-from multiprocessing import Process, Queue, Value, Array, Lock
-import threading
-from collections import defaultdict
+from multiprocessing import Process, Queue, Value, Lock
 
 from roc import Roc
 import config
@@ -79,8 +75,8 @@
         self.mbrhigh = mbrhigh
         self.devicegroup = devicegroup
         self.noroc = noroc
-        self.roc = Roc(user, password)
 
+        self.roc = Roc(config.url, user, password, config.enterprise, config.site)
 
         """Start the background camera process if it isn't running yet."""
         if BaseCamera.cameras[int(self.device)] == 0:
@@ -115,14 +111,12 @@
             BaseCamera.event[self.device].set()  # send signal to clients
             time.sleep(0)
 
-
     def _process(self):
         """Camera background process."""
         frames_iterator = self.frames()
         for frame in frames_iterator:
             BaseCamera.deviceQ[self.device].put(frame, block=True)
 
-
     def person_detected(self, num):
         self.last_detected = time.time()
         if not self.detected:
@@ -139,7 +133,7 @@
         self.detected = False
         self.timer = None
         BaseCamera.lock.acquire()
-        BaseCamera.activity_counter.value -=1
+        BaseCamera.activity_counter.value -= 1
         if BaseCamera.activity_counter.value <= 0:
             BaseCamera.activity_counter.value = 0
             self.set_resolution_low()
@@ -147,30 +141,25 @@
                 self.roc.set_mbr(self.devicegroup, self.mbrlow)
         BaseCamera.lock.release()
 
-
     def start_timer(self):
         # log.info("Start timer for device {}".format(device))
         self.timer = threading.Timer(10.0, self.timer_expiry)
         self.timer.start()
 
-
     def set_resolution_high(self):
         for device in range(0, len(config.cameras)):
             self.set_resolution(str(device), "high")
 
-
     def set_resolution_low(self):
         for device in range(0, len(config.cameras)):
             self.set_resolution(str(device), "low")
 
-
     def set_resolution(self, device, level):
         log.info("Setting camera {} resolution to {}".format(device, level))
         client = mqtt.Client()
         client.connect(self.mqttBroker)
         client.publish("camera/" + str(5000 + int(device)), level)
 
-
     def timer_expiry(self):
         now = time.time()
         diff = now - self.last_detected
diff --git a/person_detection/config.py b/person_detection/config.py
index ab510fa..72450c6 100644
--- a/person_detection/config.py
+++ b/person_detection/config.py
@@ -3,4 +3,7 @@
 SPDX-License-Identifier: LicenseRef-ONF-Member-1.01
 """
 
-cameras = {"0": "Ain's desk", "1":"HungWei's desk", "2":"Shad's desk"}
+cameras = {"0": "Ain's desk", "1": "HungWei's desk", "2": "Shad's desk"}
+url = "https://roc.menlo.aetherproject.org/aether-roc-api/aether/v2.0.0/connectivity-service-v2/"
+enterprise = 'aether-onf'
+site = 'menlo-4g'