]> git.gag.com Git - fw/quantimotor/commitdiff
add an endpoint to store user-provided test metadata
authorBdale Garbee <bdale@gag.com>
Sun, 25 May 2025 23:41:11 +0000 (17:41 -0600)
committerBdale Garbee <bdale@gag.com>
Sun, 25 May 2025 23:41:11 +0000 (17:41 -0600)
ui/app.py

index ced6ad8fc6beed7e611c63270bee6e5b64738d06..48bf7e71785a7d8f2f8ca95966e8cdf1417d36ba 100755 (executable)
--- a/ui/app.py
+++ b/ui/app.py
@@ -10,10 +10,14 @@ from cherrypy.lib.static import serve_file
 import gpiod
 from gpiod.line import Direction, Value
 import iio
+import json
 import signal
 import sys
 import time
 
+# where we'll store all our test data
+DATAPATH = "/var/lib/quantimotor/"
+
 n = 0
 pressure = 0
 thrust = 0
@@ -75,6 +79,8 @@ config = {
     'server.socket_host' : '0.0.0.0',
     'server.socket_port' : 80,
     'server.thread_pool' : 8,
+    'log.access_file': '/var/log/access.log',
+    'log.error_file': '/var/log/error.log',
   },
   '/': {
     'tools.staticdir.on': True,
@@ -85,13 +91,27 @@ config = {
 
 class App:
 
+  # main user interface home page
   @cherrypy.expose
   def index(self):
     return serve_file(os.path.join(path, 'index.html')) 
 
+  # end point for accepting and saving test metadata
+  @cherrypy.expose
+  @cherrypy.tools.json_in()
+  def metadata(self):
+    if cherrypy.request.method == 'PUT':
+      jsondata = cherrypy.request.json
+      metadata_path = DATAPATH + "metadata.json"
+      with open(metadata_path, 'w') as json_file:
+        json.dump(jsondata, json_file, indent=2)
+      return "Data received and processed"
+    else:
+      return "Method not allowed", 405
+
+  # end point for handling AJAX requests for current status
   @cherrypy.expose
   @cherrypy.tools.json_out()
-
   def getData(self):
     global n
     global pressure