kopia lustrzana https://github.com/DL7AD/pecanpico10
Switched from SQLite to MariaDB
rodzic
474bf25841
commit
c8be52415a
|
@ -5,7 +5,7 @@ import sys
|
|||
import argparse
|
||||
import telnetlib
|
||||
import time
|
||||
import sqlite3
|
||||
import mysql.connector as mariadb
|
||||
import image
|
||||
import position
|
||||
|
||||
|
@ -18,64 +18,64 @@ parser.add_argument('-v', '--verbose', help='Activates more debug messages', act
|
|||
args = parser.parse_args()
|
||||
|
||||
# Open SQLite database
|
||||
sqlite = sqlite3.connect("decoder.sqlite")
|
||||
sqlite.cursor().execute("""
|
||||
CREATE TABLE IF NOT EXISTS position
|
||||
db = mariadb.connect(user='decoder', password='decoder', database='decoder')
|
||||
db.cursor().execute("""
|
||||
CREATE TABLE IF NOT EXISTS `position`
|
||||
(
|
||||
call TEXT,
|
||||
rxtime INTEGER,
|
||||
org TEXT,
|
||||
`call` VARCHAR(10),
|
||||
`rxtime` INTEGER,
|
||||
`org` VARCHAR(3),
|
||||
|
||||
reset INTEGER,
|
||||
id INTEGER,
|
||||
time INTEGER,
|
||||
`reset` INTEGER,
|
||||
`id` INTEGER,
|
||||
`time` INTEGER,
|
||||
|
||||
adc_vsol INTEGER,
|
||||
adc_vbat INTEGER,
|
||||
pac_vsol INTEGER,
|
||||
pac_vbat INTEGER,
|
||||
pac_pbat INTEGER,
|
||||
pac_psol INTEGER,
|
||||
`adc_vsol` INTEGER,
|
||||
`adc_vbat` INTEGER,
|
||||
`pac_vsol` INTEGER,
|
||||
`pac_vbat` INTEGER,
|
||||
`pac_pbat` INTEGER,
|
||||
`pac_psol` INTEGER,
|
||||
|
||||
light_intensity INTEGER,
|
||||
`light_intensity` INTEGER,
|
||||
|
||||
gps_time INTEGER,
|
||||
gps_lock INTEGER,
|
||||
gps_sats INTEGER,
|
||||
gps_ttff INTEGER,
|
||||
gps_pdop INTEGER,
|
||||
gps_alt INTEGER,
|
||||
gps_lat INTEGER,
|
||||
gps_lon INTEGER,
|
||||
`gps_time` INTEGER,
|
||||
`gps_lock` INTEGER,
|
||||
`gps_sats` INTEGER,
|
||||
`gps_ttff` INTEGER,
|
||||
`gps_pdop` INTEGER,
|
||||
`gps_alt` INTEGER,
|
||||
`gps_lat` INTEGER,
|
||||
`gps_lon` INTEGER,
|
||||
|
||||
sen_i1_press INTEGER,
|
||||
sen_e1_press INTEGER,
|
||||
sen_e2_press INTEGER,
|
||||
sen_i1_temp INTEGER,
|
||||
sen_e1_temp INTEGER,
|
||||
sen_e2_temp INTEGER,
|
||||
sen_i1_hum INTEGER,
|
||||
sen_e1_hum INTEGER,
|
||||
sen_e2_hum INTEGER,
|
||||
`sen_i1_press` INTEGER,
|
||||
`sen_e1_press` INTEGER,
|
||||
`sen_e2_press` INTEGER,
|
||||
`sen_i1_temp` INTEGER,
|
||||
`sen_e1_temp` INTEGER,
|
||||
`sen_e2_temp` INTEGER,
|
||||
`sen_i1_hum` INTEGER,
|
||||
`sen_e1_hum` INTEGER,
|
||||
`sen_e2_hum` INTEGER,
|
||||
|
||||
stm32_temp INTEGER,
|
||||
si4464_temp INTEGER,
|
||||
`stm32_temp` INTEGER,
|
||||
`si4464_temp` INTEGER,
|
||||
|
||||
sys_time INTEGER,
|
||||
sys_error INTEGER,
|
||||
PRIMARY KEY (call,reset,id,time)
|
||||
`sys_time` INTEGER,
|
||||
`sys_error` INTEGER,
|
||||
PRIMARY KEY (`call`,`reset`,`id`,`time`)
|
||||
)
|
||||
""")
|
||||
sqlite.cursor().execute("""
|
||||
CREATE TABLE IF NOT EXISTS image
|
||||
db.cursor().execute("""
|
||||
CREATE TABLE IF NOT EXISTS `image`
|
||||
(
|
||||
id INTEGER,
|
||||
call TEXT,
|
||||
rxtime INTEGER,
|
||||
imageID INTEGER,
|
||||
packetID INTEGER,
|
||||
data TEXT,
|
||||
PRIMARY KEY (call,id,packetID)
|
||||
`id` INTEGER,
|
||||
`call` VARCHAR(10),
|
||||
`rxtime` INTEGER,
|
||||
`imageID` INTEGER,
|
||||
`packetID` INTEGER,
|
||||
`data` VARCHAR(1024),
|
||||
PRIMARY KEY (`call`,`id`,`packetID`)
|
||||
)
|
||||
""")
|
||||
|
||||
|
@ -105,7 +105,7 @@ def received_data(data):
|
|||
if pos: # Position packet (with comment and telementry)
|
||||
|
||||
comm = pos.group(4)
|
||||
position.insert_position(sqlite, call, comm, 'pos')
|
||||
position.insert_position(db, call, comm, 'pos')
|
||||
|
||||
elif dat: # Data packet
|
||||
|
||||
|
@ -113,9 +113,9 @@ def received_data(data):
|
|||
data = dat.group(4)
|
||||
|
||||
if typ is 'I': # Image packet
|
||||
image.insert_image(sqlite, rxer, call, data)
|
||||
image.insert_image(db, rxer, call, data)
|
||||
elif typ is 'L': # Log packet
|
||||
position.insert_position(sqlite, call, data, 'log')
|
||||
position.insert_position(db, call, data, 'log')
|
||||
|
||||
if args.device == 'I': # Source APRS-IS
|
||||
|
||||
|
|
|
@ -1,46 +1,50 @@
|
|||
<?php
|
||||
require_once "Tracker.class.php";
|
||||
|
||||
class Database extends SQLite3 {
|
||||
class Database extends mysqli {
|
||||
private static $instance = null;
|
||||
|
||||
function __construct() {
|
||||
$this->open("/var/www/dl7ad/pecanpico10/decoder/decoder.sqlite");
|
||||
if($this->lastErrorCode())
|
||||
echo $this->lastErrorMsg();
|
||||
private function __construct() {
|
||||
$this->con = parent::__construct("localhost", "decoder", "decoder", "decoder");
|
||||
if(mysqli_connect_errno())
|
||||
die(mysql_error());
|
||||
}
|
||||
|
||||
function __destruct() {
|
||||
parent::close();
|
||||
public function __destruct() {
|
||||
$this->close();
|
||||
}
|
||||
|
||||
static function getInstance() {
|
||||
public static function getInstance() {
|
||||
if(self::$instance == null)
|
||||
self::$instance = new Database();
|
||||
return self::$instance;
|
||||
}
|
||||
|
||||
function close() {
|
||||
public function close() {
|
||||
if(is_null($this->con))
|
||||
return;
|
||||
parent::close();
|
||||
$this->con = null;
|
||||
}
|
||||
|
||||
function getTracker() {
|
||||
public function getTracker() {
|
||||
$tracker = array();
|
||||
|
||||
$query = $this->query("
|
||||
SELECT call,MAX(rxtime)
|
||||
SELECT `call`,MAX(`rxtime`)
|
||||
FROM (
|
||||
SELECT call,rxtime FROM position
|
||||
SELECT `call`,`rxtime` FROM `position`
|
||||
UNION ALL
|
||||
SELECT call,rxtime FROM image
|
||||
)
|
||||
GROUP BY call
|
||||
ORDER BY rxtime DESC
|
||||
SELECT `call`,`rxtime` FROM `image`
|
||||
) AS d
|
||||
GROUP BY `call`
|
||||
ORDER BY `rxtime` DESC
|
||||
");
|
||||
while($row = $query->fetchArray(SQLITE3_ASSOC))
|
||||
while($row = $query->fetch_assoc())
|
||||
$tracker[] = new Tracker($row['call']);
|
||||
|
||||
return $tracker;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
|
|
@ -1,56 +1,56 @@
|
|||
<?php
|
||||
class Telemetry {
|
||||
function __construct($sqlResult) {
|
||||
$this->reset = $sqlResult['reset'];
|
||||
$this->id = $sqlResult['id'];
|
||||
$this->reset = (int)$sqlResult['reset'];
|
||||
$this->id = (int)$sqlResult['id'];
|
||||
$this->org = $sqlResult['org'];
|
||||
|
||||
$this->rxtime = $sqlResult['rxtime'];
|
||||
$this->rxtime = (int)$sqlResult['rxtime'];
|
||||
|
||||
$this->call = $sqlResult['call'];
|
||||
|
||||
$this->adc_vsol = $sqlResult['adc_vsol'];
|
||||
$this->adc_vbat = $sqlResult['adc_vbat'];
|
||||
$this->pac_vsol = $sqlResult['pac_vsol'];
|
||||
$this->pac_vbat = $sqlResult['pac_vbat'];
|
||||
$this->pac_pbat = $sqlResult['pac_pbat'];
|
||||
$this->pac_psol = $sqlResult['pac_psol'];
|
||||
$this->adc_vsol = (int)$sqlResult['adc_vsol'];
|
||||
$this->adc_vbat = (int)$sqlResult['adc_vbat'];
|
||||
$this->pac_vsol = (int)$sqlResult['pac_vsol'];
|
||||
$this->pac_vbat = (int)$sqlResult['pac_vbat'];
|
||||
$this->pac_pbat = (int)$sqlResult['pac_pbat'];
|
||||
$this->pac_psol = (int)$sqlResult['pac_psol'];
|
||||
|
||||
$this->gps_time = $sqlResult['gps_time'];
|
||||
$this->gps_lock = $sqlResult['gps_lock'];
|
||||
$this->gps_sats = $sqlResult['gps_sats'];
|
||||
$this->gps_ttff = $sqlResult['gps_ttff'];
|
||||
$this->gps_pdop = $sqlResult['gps_pdop'];
|
||||
$this->gps_alt = $sqlResult['gps_alt'];
|
||||
$this->gps_lat = $sqlResult['gps_lat'];
|
||||
$this->gps_lon = $sqlResult['gps_lon'];
|
||||
$this->gps_time = (int)$sqlResult['gps_time'];
|
||||
$this->gps_lock = (int)$sqlResult['gps_lock'];
|
||||
$this->gps_sats = (int)$sqlResult['gps_sats'];
|
||||
$this->gps_ttff = (int)$sqlResult['gps_ttff'];
|
||||
$this->gps_pdop = (int)$sqlResult['gps_pdop'];
|
||||
$this->gps_alt = (int)$sqlResult['gps_alt'];
|
||||
$this->gps_lat = (int)$sqlResult['gps_lat'];
|
||||
$this->gps_lon = (int)$sqlResult['gps_lon'];
|
||||
|
||||
$this->sen_i1_press = $sqlResult['sen_i1_press'];
|
||||
$this->sen_e1_press = $sqlResult['sen_e1_press'];
|
||||
$this->sen_e2_press = $sqlResult['sen_e2_press'];
|
||||
$this->sen_i1_temp = $sqlResult['sen_i1_temp'];
|
||||
$this->sen_e1_temp = $sqlResult['sen_e1_temp'];
|
||||
$this->sen_e2_temp = $sqlResult['sen_e2_temp'];
|
||||
$this->sen_i1_hum = $sqlResult['sen_i1_hum'];
|
||||
$this->sen_e1_hum = $sqlResult['sen_e1_hum'];
|
||||
$this->sen_e2_hum = $sqlResult['sen_e2_hum'];
|
||||
$this->sen_i1_press = (int)$sqlResult['sen_i1_press'];
|
||||
$this->sen_e1_press = (int)$sqlResult['sen_e1_press'];
|
||||
$this->sen_e2_press = (int)$sqlResult['sen_e2_press'];
|
||||
$this->sen_i1_temp = (int)$sqlResult['sen_i1_temp'];
|
||||
$this->sen_e1_temp = (int)$sqlResult['sen_e1_temp'];
|
||||
$this->sen_e2_temp = (int)$sqlResult['sen_e2_temp'];
|
||||
$this->sen_i1_hum = (int)$sqlResult['sen_i1_hum'];
|
||||
$this->sen_e1_hum = (int)$sqlResult['sen_e1_hum'];
|
||||
$this->sen_e2_hum = (int)$sqlResult['sen_e2_hum'];
|
||||
|
||||
$this->stm32_temp = $sqlResult['stm32_temp'];
|
||||
$this->si4464_temp = $sqlResult['si4464_temp'];
|
||||
$this->stm32_temp = (int)$sqlResult['stm32_temp'];
|
||||
$this->si4464_temp = (int)$sqlResult['si4464_temp'];
|
||||
|
||||
$this->light_intensity = $sqlResult['light_intensity'];
|
||||
$this->light_intensity = (int)$sqlResult['light_intensity'];
|
||||
|
||||
$this->sys_time = $sqlResult['sys_time'];
|
||||
$this->sys_error = $sqlResult['sys_error'];
|
||||
$this->sys_time = (int)$sqlResult['sys_time'];
|
||||
$this->sys_error = (int)$sqlResult['sys_error'];
|
||||
|
||||
$this->err_i2c1 = ($this->sys_error >> 0) & 0x1;
|
||||
$this->err_i2c2 = ($this->sys_error >> 1) & 0x1;
|
||||
$this->err_eva7m = ($this->sys_error >> 2) & 0x1;
|
||||
$this->err_pac1720 = ($this->sys_error >> 3) & 0x3;
|
||||
$this->err_ov5640 = ($this->sys_error >> 5) & 0x3;
|
||||
$this->err_bme280_i1 = ($this->sys_error >> 8) & 0x1;
|
||||
$this->err_bme280_e1 = ($this->sys_error >> 9) & 0x1;
|
||||
$this->err_bme280_e2 = ($this->sys_error >> 10) & 0x1;
|
||||
$this->err_i2c1 = ((int)$this->sys_error >> 0) & 0x1;
|
||||
$this->err_i2c2 = ((int)$this->sys_error >> 1) & 0x1;
|
||||
$this->err_eva7m = ((int)$this->sys_error >> 2) & 0x1;
|
||||
$this->err_pac1720 = ((int)$this->sys_error >> 3) & 0x3;
|
||||
$this->err_ov5640 = ((int)$this->sys_error >> 5) & 0x3;
|
||||
$this->err_bme280_i1 = ((int)$this->sys_error >> 8) & 0x1;
|
||||
$this->err_bme280_e1 = ((int)$this->sys_error >> 9) & 0x1;
|
||||
$this->err_bme280_e2 = ((int)$this->sys_error >> 10) & 0x1;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,21 +14,19 @@ class Tracker {
|
|||
function getLastActivity() {
|
||||
$act = array();
|
||||
|
||||
$stmt = Database::getInstance()->prepare("
|
||||
$query = Database::getInstance()->query("
|
||||
SELECT * FROM (
|
||||
SELECT CAST(STRFTIME('%s', 'now') as DECIMAL) - rxtime as lasttime,'pos' as type FROM position WHERE call = :call AND org = 'pos'
|
||||
SELECT UNIX_TIMESTAMP() - `rxtime` as `lasttime`,'pos' as `type` FROM `position` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `org` = 'pos'
|
||||
UNION ALL
|
||||
SELECT CAST(STRFTIME('%s', 'now') as DECIMAL) - rxtime as lasttime,'img' as type FROM image WHERE call = :call
|
||||
SELECT UNIX_TIMESTAMP() - `rxtime` as `lasttime`,'img' as `type` FROM `image` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "'
|
||||
UNION ALL
|
||||
SELECT CAST(STRFTIME('%s', 'now') as DECIMAL) - rxtime as lasttime,'log' as type FROM position WHERE call = :call AND org = 'log'
|
||||
)
|
||||
GROUP BY type
|
||||
ORDER BY lasttime DESC
|
||||
SELECT UNIX_TIMESTAMP() - `rxtime` as `lasttime`,'log' as `type` FROM `position` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `org` = 'log'
|
||||
) AS d
|
||||
GROUP BY `type`
|
||||
ORDER BY `lasttime` DESC
|
||||
");
|
||||
$stmt->bindValue(':call', $this->call, SQLITE3_TEXT);
|
||||
$query = $stmt->execute();
|
||||
|
||||
while($row = $query->fetchArray(SQLITE3_ASSOC))
|
||||
while($row = $query->fetch_assoc())
|
||||
$act[$row['type']] = $row['lasttime'];
|
||||
|
||||
return $act;
|
||||
|
@ -43,38 +41,31 @@ class Tracker {
|
|||
if($from - $to > 64281600)
|
||||
$from = $from + 64281600; // Max. 744 days (2 non leap years + 14 weeks)
|
||||
|
||||
$stmt = Database::getInstance()->prepare("
|
||||
SELECT t.id,call,MIN(rxtime) as time_first,MAX(rxtime) as time_last,
|
||||
COUNT(*) as count,imageID,MAX(packetID) as packetID
|
||||
$query = Database::getInstance()->query("
|
||||
SELECT t.`id`,`call`,MIN(`rxtime`) as `time_first`,MAX(`rxtime`) as `time_last`,
|
||||
COUNT(*) as `count`,`imageID`,MAX(`packetID`) as `packetID`
|
||||
FROM (
|
||||
SELECT id
|
||||
FROM image
|
||||
WHERE :from <= rxtime
|
||||
AND rxtime <= :to
|
||||
AND call = :call
|
||||
GROUP BY id
|
||||
ORDER BY id ASC
|
||||
SELECT `id`
|
||||
FROM `image`
|
||||
WHERE " . intval($from) . " <= `rxtime`
|
||||
AND `rxtime` <= " . intval($to) . "
|
||||
AND `call` = '" . Database::getInstance()->escape_string($this->call) . "'
|
||||
GROUP BY `id`
|
||||
ORDER BY `id` ASC
|
||||
) as s
|
||||
JOIN image t ON t.id = s.id
|
||||
GROUP BY t.id
|
||||
JOIN image t ON t.`id` = s.`id`
|
||||
GROUP BY t.`id`
|
||||
");
|
||||
$stmt->bindValue(':call', $this->call, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':from', $from, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':to', $to, SQLITE3_INTEGER);
|
||||
$query = $stmt->execute();
|
||||
|
||||
$pics = array();
|
||||
while($row = $query->fetchArray(SQLITE3_ASSOC))
|
||||
while($row = $query->fetch_assoc())
|
||||
$pics[] = new Image($row);
|
||||
|
||||
return $pics;
|
||||
}
|
||||
function getLastTelemetry() {
|
||||
$stmt = Database::getInstance()->prepare("SELECT * FROM position WHERE call = :call ORDER BY rxtime DESC LIMIT 1");
|
||||
$stmt->bindValue(':call', $this->call, SQLITE3_TEXT);
|
||||
$query = $stmt->execute();
|
||||
|
||||
return new Telemetry($query->fetchArray(SQLITE3_ASSOC));
|
||||
$query = Database::getInstance()->query("SELECT * FROM `position` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' ORDER BY `rxtime` DESC LIMIT 1");
|
||||
return new Telemetry($query->fetch_assoc());
|
||||
}
|
||||
function getTelemetry($from, $to=NULL) {
|
||||
if(is_null($to))
|
||||
|
@ -86,70 +77,65 @@ class Tracker {
|
|||
if($from - $to > 64281600)
|
||||
$from = $from + 64281600; // Max. 744 days (2 non leap years + 14 weeks)
|
||||
|
||||
$stmt = Database::getInstance()->prepare("
|
||||
$query = Database::getInstance()->query("
|
||||
SELECT *,
|
||||
CASE
|
||||
WHEN org = 'pos' THEN rxtime
|
||||
WHEN org = 'log' THEN gps_time
|
||||
END AS ordertime,
|
||||
MAX(org) as org
|
||||
FROM position
|
||||
WHEN `org` = 'pos' THEN `rxtime`
|
||||
WHEN `org` = 'log' THEN `gps_time`
|
||||
END AS `ordertime`,
|
||||
MAX(`org`) as `org`
|
||||
FROM `position`
|
||||
WHERE ((
|
||||
:from <= rxtime
|
||||
AND rxtime <= :to
|
||||
AND org = 'pos'
|
||||
" . intval($from) . " <= `rxtime`
|
||||
AND `rxtime` <= " . intval($to) . "
|
||||
AND `org` = 'pos'
|
||||
) OR (
|
||||
:from <= gps_time
|
||||
AND gps_time <= :to
|
||||
AND org = 'log'
|
||||
" . intval($from) . " <= `gps_time`
|
||||
AND `gps_time` <= " . intval($to) . "
|
||||
AND `org` = 'log'
|
||||
))
|
||||
AND call = :call
|
||||
GROUP BY reset,id
|
||||
ORDER BY ordertime ASC
|
||||
AND `call` = '" . Database::getInstance()->escape_string($this->call) . "'
|
||||
GROUP BY `reset`,`id`
|
||||
ORDER BY `ordertime` ASC
|
||||
");
|
||||
$stmt->bindValue(':call', $this->call, SQLITE3_TEXT);
|
||||
$stmt->bindValue(':from', $from, SQLITE3_INTEGER);
|
||||
$stmt->bindValue(':to', $to, SQLITE3_INTEGER);
|
||||
$query = $stmt->execute();
|
||||
|
||||
$datasets = array();
|
||||
while($row = $query->fetchArray(SQLITE3_ASSOC)) {
|
||||
while($row = $query->fetch_assoc()) {
|
||||
$datasets[] = new Telemetry($row);
|
||||
}
|
||||
|
||||
return $datasets;
|
||||
}
|
||||
function getPacketCount() {
|
||||
$stmt = Database::getInstance()->prepare("SELECT *
|
||||
$query = Database::getInstance()->query("SELECT *
|
||||
FROM (
|
||||
SELECT COUNT(*) as cnt86400,'pos' as type FROM position WHERE call = :call AND org = 'pos' AND rxtime+86400 > CAST(STRFTIME('%s', 'now') as DECIMAL)
|
||||
SELECT COUNT(*) as `cnt86400`,'pos' as `type` FROM `position` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `org` = 'pos' AND `rxtime`+86400 > UNIX_TIMESTAMP()
|
||||
UNION ALL
|
||||
SELECT COUNT(*) as cnt86400,'img' as type FROM image WHERE call = :call AND rxtime+86400 > CAST(STRFTIME('%s', 'now') as DECIMAL)
|
||||
SELECT COUNT(*) as `cnt86400`,'img' as `type` FROM `image` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `rxtime`+86400 > UNIX_TIMESTAMP()
|
||||
UNION ALL
|
||||
SELECT COUNT(*) as cnt86400,'log' as type FROM position WHERE call = :call AND org = 'log' AND rxtime+86400 > CAST(STRFTIME('%s', 'now') as DECIMAL)
|
||||
SELECT COUNT(*) as `cnt86400`,'log' as `type` FROM `position` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `org` = 'log' AND `rxtime`+86400 > UNIX_TIMESTAMP()
|
||||
) AS a
|
||||
JOIN (
|
||||
SELECT COUNT(*) as cnt3600,'pos' as type FROM position WHERE call = :call AND org = 'pos' AND rxtime+3600 > CAST(STRFTIME('%s', 'now') as DECIMAL)
|
||||
SELECT COUNT(*) as `cnt3600`,'pos' as `type` FROM `position` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `org` = 'pos' AND `rxtime`+3600 > UNIX_TIMESTAMP()
|
||||
UNION ALL
|
||||
SELECT COUNT(*) as cnt3600,'img' as type FROM image WHERE call = :call AND rxtime+3600 > CAST(STRFTIME('%s', 'now') as DECIMAL)
|
||||
SELECT COUNT(*) as `cnt3600`,'img' as `type` FROM `image` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `rxtime`+3600 > UNIX_TIMESTAMP()
|
||||
UNION ALL
|
||||
SELECT COUNT(*) as cnt3600,'log' as type FROM position WHERE call = :call AND org = 'log' AND rxtime+3600 > CAST(STRFTIME('%s', 'now') as DECIMAL)
|
||||
SELECT COUNT(*) as `cnt3600`,'log' as `type` FROM `position` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `org` = 'log' AND `rxtime`+3600 > UNIX_TIMESTAMP()
|
||||
) AS b
|
||||
JOIN (
|
||||
SELECT COUNT(*) as cnt300,'pos' as type FROM position WHERE call = :call AND org = 'pos' AND rxtime+300 > CAST(STRFTIME('%s', 'now') as DECIMAL)
|
||||
SELECT COUNT(*) as `cnt300`,'pos' as `type` FROM `position` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `org` = 'pos' AND `rxtime`+300 > UNIX_TIMESTAMP()
|
||||
UNION ALL
|
||||
SELECT COUNT(*) as cnt300,'img' as type FROM image WHERE call = :call AND rxtime+300 > CAST(STRFTIME('%s', 'now') as DECIMAL)
|
||||
SELECT COUNT(*) as `cnt300`,'img' as `type` FROM `image` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `rxtime`+300 > UNIX_TIMESTAMP()
|
||||
UNION ALL
|
||||
SELECT COUNT(*) as cnt300,'log' as type FROM position WHERE call = :call AND org = 'log' AND rxtime+300 > CAST(STRFTIME('%s', 'now') as DECIMAL)
|
||||
SELECT COUNT(*) as `cnt300`,'log' as `type` FROM `position` WHERE `call` = '" . Database::getInstance()->escape_string($this->call) . "' AND `org` = 'log' AND `rxtime`+300 > UNIX_TIMESTAMP()
|
||||
) AS c
|
||||
WHERE a.type = b.type
|
||||
AND a.type = c.type
|
||||
WHERE a.`type` = b.`type`
|
||||
AND a.`type` = c.`type`
|
||||
");
|
||||
$stmt->bindValue(':call', $this->call, SQLITE3_TEXT);
|
||||
$query = $stmt->execute();
|
||||
|
||||
|
||||
$ret = array();
|
||||
while($row = $query->fetchArray(SQLITE3_ASSOC))
|
||||
while($row = $query->fetch_assoc())
|
||||
$ret[$row['type']] = $row;
|
||||
|
||||
return $ret;
|
||||
|
|
|
@ -210,7 +210,7 @@ function loadRecentData() {
|
|||
|
||||
var time = new Date(data['org'] == 'pos' ? data['rxtime']*1000 : data['gps_time']*1000);
|
||||
|
||||
if(last != null && time - last > 1210000) {
|
||||
if(last != null && time - last > 1810000) {
|
||||
dataBattery.addRow([null, null, null, null]);
|
||||
dataSolar.addRow([null, null, null, null]);
|
||||
dataTemp.addRow([null,null,null,null,null,null]);
|
||||
|
@ -428,16 +428,6 @@ include "sidebar.inc.php";
|
|||
</td>
|
||||
</tr>
|
||||
<tr height="5"></tr>
|
||||
<tr>
|
||||
<th>GPS:</th>
|
||||
<td colspan="5">
|
||||
<b><span id="gps_lock"></span></b><br>
|
||||
<span id="gps_sats"></span> Sats, TTFF <span id="gps_ttff"></span>s, pDOP <span id="gps_pdop"></span><br>
|
||||
Time: <span id="gps_time"></span><br>
|
||||
<span id="gps_lat"></span> <span id="gps_lon"></span> <span id="gps_alt"></span>m
|
||||
</td>
|
||||
</tr>
|
||||
<tr height="5"></tr>
|
||||
<tr>
|
||||
<th>Packets:</th>
|
||||
<td></td>
|
||||
|
@ -491,6 +481,17 @@ include "sidebar.inc.php";
|
|||
<td><span id="adc_vsol"></span>mV<sub>STM</sub>, <span id="pac_vsol"></span>mV<sub>PAC</sub>, <span id="pac_psol"></span>mW<sub>PAC</sub></td>
|
||||
</tr>
|
||||
<tr height="5"></tr>
|
||||
<tr>
|
||||
<th>GPS:</th>
|
||||
<td></td>
|
||||
<td>
|
||||
<b><span id="gps_lock"></span></b><br>
|
||||
<span id="gps_sats"></span> Sats, TTFF <span id="gps_ttff"></span>s, pDOP <span id="gps_pdop"></span><br>
|
||||
Time: <span id="gps_time"></span><br>
|
||||
<span id="gps_lat"></span> <span id="gps_lon"></span> <span id="gps_alt"></span>m
|
||||
</td>
|
||||
</tr>
|
||||
<tr height="5"></tr>
|
||||
<tr>
|
||||
<th>Sensors:</th>
|
||||
<td width="75">BME280<sub>I1</sub>:</td>
|
||||
|
|
|
@ -59,14 +59,14 @@ def imgproc():
|
|||
time.sleep(1)
|
||||
|
||||
w = time.time()
|
||||
def insert_image(sqlite, receiver, call, data_b91):
|
||||
def insert_image(db, receiver, call, data_b91):
|
||||
global imageProcessor,imageData,w
|
||||
|
||||
data = base91.decode(data_b91)
|
||||
if len(data) != 174:
|
||||
return # APRS message has invalid type or length (or both)
|
||||
|
||||
cur = sqlite.cursor()
|
||||
cur = db.cursor()
|
||||
|
||||
# Decode various meta data
|
||||
imageID = data[0]
|
||||
|
@ -91,7 +91,7 @@ def insert_image(sqlite, receiver, call, data_b91):
|
|||
|
||||
# Find image ID (or generate new one)
|
||||
_id = None
|
||||
cur.execute("SELECT id,packetID FROM image WHERE call = ? AND imageID = ? AND rxtime+10*60 >= ? ORDER BY rxtime DESC LIMIT 1", (call, imageID, timd))
|
||||
cur.execute("SELECT `id`,`packetID` FROM `image` WHERE `call` = %s AND `imageID` = %s AND `rxtime`+10*60 >= %s ORDER BY `rxtime` DESC LIMIT 1", (call, imageID, timd))
|
||||
fetch = cur.fetchall()
|
||||
if len(fetch):
|
||||
_id = fetch[0][0]
|
||||
|
@ -99,7 +99,7 @@ def insert_image(sqlite, receiver, call, data_b91):
|
|||
|
||||
if _id is None:
|
||||
# Generate ID
|
||||
cur.execute("SELECT id+1 FROM image ORDER BY id DESC LIMIT 1")
|
||||
cur.execute("SELECT `id`+1 FROM `image` ORDER BY `id` DESC LIMIT 1")
|
||||
fetch = cur.fetchall()
|
||||
if len(fetch):
|
||||
_id = fetch[0][0]
|
||||
|
@ -111,18 +111,18 @@ def insert_image(sqlite, receiver, call, data_b91):
|
|||
|
||||
# Insert into database
|
||||
cur.execute("""
|
||||
INSERT OR IGNORE INTO image (call,rxtime,imageID,packetID,data,id)
|
||||
VALUES (?,?,?,?,?,?)""",
|
||||
INSERT IGNORE INTO `image` (`call`,`rxtime`,`imageID`,`packetID`,`data`,`id`)
|
||||
VALUES (%s,%s,%s,%s,%s,%s)""",
|
||||
(call, timd, imageID, packetID, data, _id)
|
||||
)
|
||||
|
||||
if w+0.5 < time.time():
|
||||
sqlite.commit()
|
||||
db.commit()
|
||||
w = time.time()
|
||||
|
||||
with lock:
|
||||
allData = ''
|
||||
cur.execute("SELECT data FROM image WHERE id = ? ORDER BY packetID", (_id,))
|
||||
cur.execute("SELECT `data` FROM `image` WHERE `id` = %s ORDER BY `packetID`", (_id,))
|
||||
for data, in cur.fetchall():
|
||||
allData += '55' + data + (144*'0')
|
||||
imageData[_id] = (call, binascii.unhexlify(allData))
|
||||
|
|
|
@ -1,26 +1,34 @@
|
|||
from datetime import datetime,timedelta,timezone
|
||||
import sqlite3
|
||||
import base91
|
||||
import struct
|
||||
|
||||
def insert_position(sqlite, call, comm, typ):
|
||||
# Decode comment
|
||||
data = base91.decode(comm)
|
||||
(adc_vsol,adc_vbat,pac_vsol,pac_vbat,pac_pbat,pac_psol,light_intensity,
|
||||
gps_lock,gps_sats,gps_ttff,gps_pdop,gps_alt,gps_lat,
|
||||
gps_lon,sen_i1_press,sen_e1_press,sen_e2_press,sen_i1_temp,sen_e1_temp,
|
||||
sen_e2_temp,sen_i1_hum,sen_e1_hum,sen_e2_hum,dummy2,stm32_temp,
|
||||
si4464_temp,reset,_id,gps_time,sys_time,sys_error) = struct.unpack('HHHHhhHBBBBHiiIIIhhhBBBBhhHIIII', data[:72])
|
||||
def insert_position(db, call, comm, typ):
|
||||
try:
|
||||
# Decode comment
|
||||
data = base91.decode(comm)
|
||||
(adc_vsol,adc_vbat,pac_vsol,pac_vbat,pac_pbat,pac_psol,light_intensity,
|
||||
gps_lock,gps_sats,gps_ttff,gps_pdop,gps_alt,gps_lat,
|
||||
gps_lon,sen_i1_press,sen_e1_press,sen_e2_press,sen_i1_temp,sen_e1_temp,
|
||||
sen_e2_temp,sen_i1_hum,sen_e1_hum,sen_e2_hum,dummy2,stm32_temp,
|
||||
si4464_temp,reset,_id,gps_time,sys_time,sys_error) = struct.unpack('HHHHhhHBBBBHiiIIIhhhBBBBhhHIIII', data[:72])
|
||||
|
||||
# Insert
|
||||
rxtime = int(datetime.now(timezone.utc).timestamp())
|
||||
sqlite.cursor().execute(
|
||||
"""INSERT INTO position (call,rxtime,org,adc_vsol,adc_vbat,pac_vsol,pac_vbat,pac_pbat,pac_psol,light_intensity,gps_lock,gps_sats,gps_ttff,gps_pdop,gps_alt,gps_lat,gps_lon,sen_i1_press,sen_e1_press,sen_e2_press,sen_i1_temp,sen_e1_temp,sen_e2_temp,sen_i1_hum,sen_e1_hum,sen_e2_hum,sys_error,stm32_temp,si4464_temp,reset,id,sys_time,gps_time)
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)""",
|
||||
(call,rxtime,typ,adc_vsol,adc_vbat,pac_vsol,pac_vbat,pac_pbat,pac_psol,light_intensity,gps_lock,gps_sats,gps_ttff,gps_pdop,gps_alt,gps_lat,gps_lon,sen_i1_press,sen_e1_press,sen_e2_press,sen_i1_temp,sen_e1_temp,sen_e2_temp,sen_i1_hum,sen_e1_hum,sen_e2_hum,sys_error,stm32_temp,si4464_temp,reset,_id,sys_time,gps_time)
|
||||
)
|
||||
sqlite.commit()
|
||||
# Insert
|
||||
rxtime = int(datetime.now(timezone.utc).timestamp())
|
||||
db.cursor().execute(
|
||||
"""INSERT INTO `position` (`call`,`rxtime`,`org`,`adc_vsol`,`adc_vbat`,`pac_vsol`,`pac_vbat`,`pac_pbat`,`pac_psol`,`light_intensity`,`gps_lock`,
|
||||
`gps_sats`,`gps_ttff`,`gps_pdop`,`gps_alt`,`gps_lat`,`gps_lon`,`sen_i1_press`,`sen_e1_press`,`sen_e2_press`,`sen_i1_temp`,`sen_e1_temp`,
|
||||
`sen_e2_temp`,`sen_i1_hum`,`sen_e1_hum`,`sen_e2_hum`,`sys_error`,`stm32_temp`,`si4464_temp`,`reset`,`id`,`sys_time`,`gps_time`)
|
||||
VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)""",
|
||||
(call,rxtime,typ,adc_vsol,adc_vbat,pac_vsol,pac_vbat,pac_pbat,pac_psol,light_intensity,gps_lock,gps_sats,gps_ttff,
|
||||
gps_pdop,gps_alt,gps_lat,gps_lon,sen_i1_press,sen_e1_press,sen_e2_press,sen_i1_temp,sen_e1_temp,sen_e2_temp,sen_i1_hum,
|
||||
sen_e1_hum,sen_e2_hum,sys_error,stm32_temp,si4464_temp,reset,_id,sys_time,gps_time)
|
||||
)
|
||||
db.commit()
|
||||
|
||||
# Debug
|
||||
print('Received %s packet packet Call=%s Reset=%d ID=%d' % (typ, call, reset, _id))
|
||||
# Debug
|
||||
print('Received %s packet packet Call=%s Reset=%d ID=%d' % (typ, call, reset, _id))
|
||||
|
||||
except struct.error:
|
||||
|
||||
print('Received erroneous %s packet Call=%s' % (typ, call))
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue