#!/usr/bin/env python
# Log wifi strength for our routers
# 2020-04-14 Original version
# 2020-04-23 changed name to start with PI_
# 2020-07-01 Option to run once or continuously
# 2020-11-12 Save strength and address
# 2020-11-17 Show adress of connected access point
# 2020-11-28 Save line if no connection found
# 2021-08-09 Use platform to determine RPI's name
# 2022-01-05 Changed version number

from __future__ import print_function
import sys
import subprocess
import time
import MySQLdb
Server="localhost"           # Server for database

def db_connect() :
  return MySQLdb.connect(Server,"verbruik","Verbruik1","wifi" )
    
#------------------------------------------------------------------------------
# Start program
#------------------------------------------------------------------------------

# Time of program start
lt = time.localtime(time.time())
timestr='%4i-%02i-%02i %02i:%02i:%02i' % (lt.tm_year,lt.tm_mon,lt.tm_mday,lt.tm_hour,lt.tm_min,lt.tm_sec)

# Print start of program to console or logfile
print(timestr,'\t','TestPython')

print('Python versie ',sys.version)
print('MySQLdb library ',MySQLdb.__file__)

db = db_connect()
cursor = db.cursor()
cursor.execute("SELECT VERSION()")
data = cursor.fetchone()
print('MySQLdb versie ',data)
db.close()

print ('Program ended')
