main
Bryan Cerrati 2025-06-19 14:45:56 -04:00
parent c0be695c2f
commit c0498b96db
4 changed files with 48 additions and 17 deletions

View File

@ -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

View File

@ -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()

Binary file not shown.

View File

@ -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('/<location>/', methods=["POST"])
@keep.route('/loc/<location>/', 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,
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")
)
)
datetime.now().strftime("%H:%M:%S")))
conn.commit()
return location
conn.close()
# Redirect to the same route with GET method
return f"Keepalive recorded for {location}"
@keep.route('/loc/<location>/', methods=["GET"])
def show_location(location):
return f"<h1>Received keepalive from: {location}</h1>"