diff --git a/SendingMechanism/keepalive-daemon.py b/SendingMechanism/keepalive-daemon.py index 1c6ba9d..32f4054 100644 --- a/SendingMechanism/keepalive-daemon.py +++ b/SendingMechanism/keepalive-daemon.py @@ -2,7 +2,7 @@ import time import requests -IP = "47.21.28.174:5050" +IP = "0.0.0.0" NAME = "TEST-daemon" INTERVAL = 10 # seconds diff --git a/SendingMechanism/keepalive-send.py b/SendingMechanism/keepalive-send.py new file mode 100644 index 0000000..15b17db --- /dev/null +++ b/SendingMechanism/keepalive-send.py @@ -0,0 +1,24 @@ +import requests +import logging + +# Set up optional logging to a file +logging.basicConfig( + filename="keepalive.log", + level=logging.INFO, + format="%(asctime)s - %(message)s" +) + +# Set your target IP and device name +IP = "0.0.0.0" +NAME = "test-device" + +def main(): + try: + url = f"http://{IP}/{NAME}/" + response = requests.post(url) + logging.info(f"POST to {url}, status {response.status_code}") + except Exception as e: + logging.error(f"Error sending POST to {url}: {e}") + +if __name__ == "__main__": + main() diff --git a/app/db/keepalive.db b/app/db/keepalive.db index 3c41ff9..7a6ce16 100644 Binary files a/app/db/keepalive.db and b/app/db/keepalive.db differ diff --git a/app/keep.py b/app/keep.py index b9ebbaf..bdd9db6 100644 --- a/app/keep.py +++ b/app/keep.py @@ -1,4 +1,4 @@ -from flask import Blueprint, render_template, request, g +from flask import Blueprint, render_template, request, g, url_for, redirect from datetime import datetime, date import sqlite3 @@ -35,19 +35,26 @@ def dispkeepalive(): return render_template("keepaliveshowpage.html", items=items) -@keep.route('//', methods=["POST"]) +@keep.route('/loc//', methods=["POST"]) def getalive(location): - if request.method == "POST": - conn = get_db() - c = conn.cursor() - c.execute("""INSERT INTO keepalive2 - (location, date, time) - VALUES (?,?,?)""", - ( - location, - date.today().strftime("%m/%d/%y"), - datetime.now().strftime("%H:%M:%S") - ) - ) - conn.commit() - return location \ No newline at end of file + conn = get_db() + c = conn.cursor() + c.execute("""CREATE TABLE IF NOT EXISTS keepalive2 ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + location TEXT, + date TEXT, + time TEXT)""") + c.execute("""INSERT INTO keepalive2 (location, date, time) + VALUES (?, ?, ?)""", + (location, + date.today().strftime("%m/%d/%y"), + datetime.now().strftime("%H:%M:%S"))) + conn.commit() + conn.close() + + # Redirect to the same route with GET method + return f"Keepalive recorded for {location}" + +@keep.route('/loc//', methods=["GET"]) +def show_location(location): + return f"

Received keepalive from: {location}

" \ No newline at end of file