Skip to content
Snippets Groups Projects
Commit 10c7d660 authored by 42loop's avatar 42loop
Browse files

Initial

parents
Branches
No related tags found
No related merge requests found
#!/bin/bash
#in rc.local:
# create backup of database
# init udp receiver
# /usr/bin/socat -u tcp-l:7777,fork system:/home/pi/getmsg.sh &
read MESSAGE
#echo "$MESSAGE"
#' check message length ?'
ts=$(($(date +%s%N)/1000000))
#call script to enter into sqlite table:
python /home/pi/write_to_db.py $ts
!#/usr/bin/python3
import sqlite3 as lite
con = lite.connect('udp_pings.db')
def db_purge():
global con
with con:
cur = con.cursor()
cur.execute("DELETE FROM udp_pings")
def db_insert(ts):
global con
with con:
cur = con.cursor()
sql="INSERT INTO pings(ts) VALUES('"+str(ts)+"')"
cur.execute(sql)
def db_dump():
global con
with con:
cur = con.cursor()
cur.execute("SELECT * FROM pings")
rows = cur.fetchall()
for row in rows:
print(row)
def db_create():
global con
with con:
cur = con.cursor()
cur.execute("DROP TABLE IF EXISTS pings")
cur.execute("CREATE TABLE pings(id INTEGER PRIMARY KEY,ts varchar(20) NOT NULL)")
def millis():
return int(round(time.time() * 1000))
if __name__ == '__main__':
# db_create()
# db_purge()
# db_dump()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment