one off
parent
c0be695c2f
commit
c0498b96db
|
|
@ -2,7 +2,7 @@
|
||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
IP = "47.21.28.174:5050"
|
IP = "0.0.0.0"
|
||||||
NAME = "TEST-daemon"
|
NAME = "TEST-daemon"
|
||||||
INTERVAL = 10 # seconds
|
INTERVAL = 10 # seconds
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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.
39
app/keep.py
39
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
|
from datetime import datetime, date
|
||||||
import sqlite3
|
import sqlite3
|
||||||
|
|
||||||
|
|
@ -35,19 +35,26 @@ def dispkeepalive():
|
||||||
return render_template("keepaliveshowpage.html", items=items)
|
return render_template("keepaliveshowpage.html", items=items)
|
||||||
|
|
||||||
|
|
||||||
@keep.route('/<location>/', methods=["POST"])
|
@keep.route('/loc/<location>/', methods=["POST"])
|
||||||
def getalive(location):
|
def getalive(location):
|
||||||
if request.method == "POST":
|
conn = get_db()
|
||||||
conn = get_db()
|
c = conn.cursor()
|
||||||
c = conn.cursor()
|
c.execute("""CREATE TABLE IF NOT EXISTS keepalive2 (
|
||||||
c.execute("""INSERT INTO keepalive2
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
(location, date, time)
|
location TEXT,
|
||||||
VALUES (?,?,?)""",
|
date TEXT,
|
||||||
(
|
time TEXT)""")
|
||||||
location,
|
c.execute("""INSERT INTO keepalive2 (location, date, time)
|
||||||
date.today().strftime("%m/%d/%y"),
|
VALUES (?, ?, ?)""",
|
||||||
datetime.now().strftime("%H:%M:%S")
|
(location,
|
||||||
)
|
date.today().strftime("%m/%d/%y"),
|
||||||
)
|
datetime.now().strftime("%H:%M:%S")))
|
||||||
conn.commit()
|
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>"
|
||||||
Loading…
Reference in New Issue