Adds startup script

This commit is contained in:
Patrick McDonagh
2016-12-05 12:28:54 -06:00
parent c143f7ca6e
commit 29c406eaa3
2 changed files with 77 additions and 36 deletions

View File

@@ -35,9 +35,9 @@ main_plc = {}
# ---------- MAP FUNCTIONS ---------- #
maps = {
'modeMap': { 0: "Error", 1: "Auto", 2: "POC", 3: "Timer", 4: "Manual", 5: "DH PID"},
'card_type_map': { 0: "Normal", 1: "Shutdown", 2: "Alarm", 3: "Startup", 4: "Low Fillage"},
'statusMap': { 0: 'Stopped', 1: 'Running', 2: 'Pumped Off', 3: 'Faulted', 4: 'Starting', 5: 'Recovering', 100: 'Read Error', 1000: 'PLC Error', 9999: 'No Response'},
'modeMap': {0: "Error", 1: "Auto", 2: "POC", 3: "Timer", 4: "Manual", 5: "DH PID"},
'card_type_map': {0: "Normal", 1: "Shutdown", 2: "Alarm", 3: "Startup", 4: "Low Fillage"},
'statusMap': {0: 'Stopped', 1: 'Running', 2: 'Pumped Off', 3: 'Faulted', 4: 'Starting', 5: 'Recovering', 100: 'Read Error', 1000: 'PLC Error', 9999: 'No Response'},
None: None,
'null': None
}
@@ -86,6 +86,7 @@ def readConfig():
return True
def getDeviceTypes():
global API_BASE_URL
req = requests.get('{}/device_types'.format(API_BASE_URL), verify=False)
@@ -162,56 +163,29 @@ def readGaugeOffData():
print("Did not get a valid JSON object back, got: {}".format(post_req.text))
return False
def evalTapers():
return True
# TODO: Read taper data
# global main_plc
# ts = time.time()
# numTapers = int(readTag(main_plc['address'], 'Card_Current.Params.Num_Tapers')[0])
# for t in range(1, numTapers + 1):
# taper_length = readTag(main_plc['address'], 'Taper.Taper[{}].Setup.Length'.format(t))[0]
# taper_diameter = readTag(main_plc['address'], 'Taper.Taper[{}].Setup.Diameter'.format(t))[0]
# taper_material = readTag(main_plc['address'], 'Taper.Taper[{}].Setup.Material'.format(t))[0]
# if (taper_material == 1):
# taper_material = "Steel"
# elif (taper_material == 2):
# taper_material = "Fiberglass"
#
# tStr = "{{'taper':{}, 'length': {}, 'diameter': {}, 'material':'{}'}}".format(t, taper_length, taper_diameter, taper_material)
# tQuery = 'INSERT INTO well_config (tstamp, type, val) VALUES ({}, "taper", "{}")'.format(ts, tStr)
# print(tQuery)
# con.connect()
# cur = con.cursor()
# cur.execute(tQuery)
# con.commit()
#
# pump_diameter = readTag(main_plc['address'], 'UnitConfig.Pump_Diameter')[0]
# cfgQuery = "INSERT INTO well_config (tstamp, type, val) VALUES ({}, 'pump_diameter', '{}')".format(ts, pump_diameter)
# con.connect()
# cur = con.cursor()
# cur.execute(cfgQuery)
# con.commit()
# print("TAPER DATA READ!")
# return True
def readPoints():
global main_plc
num_points = readTag(main_plc['address'], "Card_Past[1].Num_Points")[0]
surf_pos = readArray(main_plc['address'], "Card_Past[1].Surface_Position", num_points + 1)[1:]
if len(surf_pos) > 1:
surf_pos = [round(i,2) for i in surf_pos]
surf_pos = [round(i, 2) for i in surf_pos]
surf_pos.append(surf_pos[0])
surf_lod = readArray(main_plc['address'], "Card_Past[1].Surface_Load", num_points + 1)[1:]
if len(surf_lod) > 1:
surf_lod = [round(i,2) for i in surf_lod]
surf_lod = [round(i, 2) for i in surf_lod]
surf_lod.append(surf_lod[0])
down_pos = readArray(main_plc['address'], "Card_Past[1].Downhole_Position", num_points + 1)[1:]
if len(down_pos) > 1:
down_pos = [round(i,2) for i in down_pos]
down_pos = [round(i, 2) for i in down_pos]
down_pos.append(down_pos[0])
down_lod = readArray(main_plc['address'], "Card_Past[1].Downhole_Load", num_points + 1)[1:]
if len(down_pos) > 1:
down_pos = [round(i,2) for i in down_pos]
down_pos = [round(i, 2) for i in down_pos]
down_lod.append(down_lod[0])
return([surf_pos, surf_lod, down_pos, down_lod])

67
datalogger.sh Executable file
View File

@@ -0,0 +1,67 @@
#!/bin/sh
### BEGIN INIT INFO
# Provides: datalogger
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Runs the Henry Pump datalogger
### END INIT INFO
SCRIPT="python /root/datalogger/dataLogger.py"
RUNAS=poconsole
PIDFILE=/root/datalogger.pid
LOGFILE=/root/datalogger.log
start() {
if [ -f "$PIDFILE" ] && kill -0 $(cat $PIDFILE); then
echo 'Service already running' >&2
return 1
fi
echo 'Starting service…' >&2
local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
su -c "$CMD" $RUNAS > /dev/null
echo 'Service started' >&2
}
stop() {
if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
echo 'Service not running' >&2
return 1
fi
echo 'Stopping service…' >&2
kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
echo 'Service stopped' >&2
}
uninstall() {
echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
local SURE
read SURE
if [ "$SURE" = "yes" ]; then
stop
rm -f "$PIDFILE"
echo "Notice: log file is not be removed: '$LOGFILE'" >&2
update-rc.d -f datalogger remove
rm -fv "$0"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
uninstall)
uninstall
;;
retart)
stop
start
;;
*)
echo "Usage: $0 {start|stop|restart|uninstall}"
esac