a1eaiactaest / rere

rere is an easy to use, nature conditions monitoring software.
MIT License
0 stars 0 forks source link

patch later #6

Closed a1eaiactaest closed 3 years ago

a1eaiactaest commented 3 years ago
commit 83f4672a33eac9123e038a2abd2f4e86158742fa
Author: Piotrek <piotrrybiec28@gmail.com>
Date:   Thu Sep 30 10:52:05 2021 +0200

    take port in right place

diff --git a/connection.py b/connection.py
index 9309e9e..285bec9 100755
--- a/connection.py
+++ b/connection.py
@@ -13,7 +13,7 @@ import json

 class Connection:
   def __init__(self, port):
-    self.port = port #/dev/tty*
+    self.port = port #/dev/ttyXXXX
     self.s = serial.Serial(port, 9600)
     self.s.reset_input_buffer()

diff --git a/db.py b/db.py
index 17cd7c8..542d12a 100755
--- a/db.py
+++ b/db.py
@@ -4,14 +4,15 @@ import sqlite3
 from connection import Connection
 import time
 import os
+import sys

 READ = os.getenv('READ', None) is not None
 WRITE = os.getenv('WRITE', None) is not None
 CLEAR = os.getenv('CLEAR', None) is not None

 class Database:
-  def __init__(self):
-    self.serial_connection = Connection('/dev/ttyACM0')
+  def __init__(self, port):
+    self.serial_connection = Connection(port)
     self.conn = sqlite3.connect('serial_archive.db', check_same_thread=False)
     self.cur = self.conn.cursor() 
     self.init_db()
@@ -65,11 +66,11 @@ class Database:

 if __name__ == "__main__":
-  db = Database()
+  db = Database(sys.argv[1])
   if WRITE:
     while (1):
       #db.write_db(300) # every 5 minutes 
-      db.write_db(900)
+      db.write_db(20)
   if READ:
     # usage:
     # n -> returns last n elements
diff --git a/run.sh b/run.sh
index b581869..e8a09bb 100755
--- a/run.sh
+++ b/run.sh
@@ -8,16 +8,15 @@ function ctrl_c() {

 trap ctrl_c 2 # 2 for SIGINT

-if [ -z "$1" ]; then
-  echo "please supply device port as argument"
-  exit
-fi
+PORT=$(readlink -f /dev/serial/by-id/*)

-if  [ "`stat -c '%a' $1`" == "660" ] ; then
-  echo changing permissions of $1 to 660
-  sudo chmod a+rw $1
+if  [ "`stat -c '%a' $PORT`" == "660" ] ; then
+  echo changing permissions of $PORT to 660
+  sudo chmod a+rw $PORT
 fi

-WRITE=1 ./db.py & 
+# find port, may be prone to bugs, will see
+
+WRITE=1 ./db.py $PORT & 
 pid=$!
-./serve.py 
+./serve.py $PORT
diff --git a/serve.py b/serve.py
index dc42fe6..45a9d06 100755
--- a/serve.py
+++ b/serve.py
@@ -3,27 +3,12 @@
 import os
 import sys
 import json
-import threading
 import time
 from flask import Flask, render_template, jsonify, request
 from db import Database

-
-class Thread(object):
-  def __init__(self, delay=100000):
-    self.acc = 0
-    self.delay = delay
-    t = threading.Thread(target=self.run, args=())
-    t.daemon = True
-    t.start()
-
-  def run(self):
-    while(1):
-      d.write_db(900, True)
-
-d = Database()
+d = Database(sys.argv[1])
 app = Flask(__name__)
-#tr = Thread()

 @app.route('/')
 def hello():
diff --git a/static/index.js b/static/index.js
index d46896a..f3ea66c 100644
--- a/static/index.js
+++ b/static/index.js
@@ -33,5 +33,5 @@ function write_to_table(values_arr){

 var intervalId = window.setInterval(function(){
   fetch_data();
-}, 900000); 
+}, 20000); 

diff --git a/tools/launch_client.sh b/tools/launch_client.sh
index 462b439..b5e521d 100755
--- a/tools/launch_client.sh
+++ b/tools/launch_client.sh
@@ -1,6 +1,3 @@
 #!/bin/bash

-# find port, may be prone to bugs, will see
-PORT=$(readlink -f /dev/serial/by-id/*)
-
-(cd .. && ./run.sh $PORT)
+(cd .. && ./run.sh)
a1eaiactaest commented 3 years ago

patched already in this one i guess dfef6e05b0facda7b5bf65f9b8b3cf8e652bb7dc