From 8419ece2f89c4b18d45489b2d0e44930bec315c5 Mon Sep 17 00:00:00 2001 From: auxlife Date: Sat, 31 Dec 2016 14:08:33 -0800 Subject: [PATCH] Add files via upload --- config.inc.php | 16 ++++++++++++++++ db.inc.php | 7 ++++--- dbload.php | 10 ++++++++++ tidepool.inc.php | 14 +++++--------- 4 files changed, 35 insertions(+), 12 deletions(-) create mode 100644 config.inc.php diff --git a/config.inc.php b/config.inc.php new file mode 100644 index 0000000..41aedca --- /dev/null +++ b/config.inc.php @@ -0,0 +1,16 @@ + \ No newline at end of file diff --git a/db.inc.php b/db.inc.php index 2823701..ded6e2a 100644 --- a/db.inc.php +++ b/db.inc.php @@ -2,14 +2,15 @@ ini_set ('error_reporting', E_ALL); ini_set ('display_errors', '1'); error_reporting (E_ALL|E_STRICT); +include_once "config.inc.php"; $dbc = mysqli_init(); function ConnectDB() { $GLOBALS['dbc'] = mysqli_init(); - mysqli_ssl_set($GLOBALS['dbc'],'dbcrt/client-key.pem', 'dbcrt/client-cert.pem', 'dbcrt/ca-cert.pem', 'dbcrt/ca.pem', NULL) ; - mysqli_real_connect($GLOBALS['dbc'], /*HOST*/, /*USERNAME*/, /*PASSWORD*/, 'xdrip', 3306, NULL, MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT); + mysqli_ssl_set($GLOBALS['dbc'],'dbcrt/client-key.pem', 'dbcrt/client-cert.pem', 'dbcrt/ca-cert.pem', '/dbcrt/ca.pem', NULL) ; + mysqli_real_connect($GLOBALS['dbc'], $GLOBALS['DbHost'], $GLOBALS['DbUser'], $GLOBALS['DbPass'], $GLOBALS['DbName'], 3306, NULL, MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT); if (!$GLOBALS['dbc']) die('Could not connect to MySQL: ' . mysqli_connect_error() ); else @@ -20,7 +21,7 @@ function DisconnectDB() { return mysqli_close($GLOBALS['dbc']); } function InsertValue($DateString, $Type, $Value, $Payload) { - $query = "INSERT INTO `Data` (`DateString`, `Type`, `Value`, `Payload`, `Uploaded`) VALUES ('".$DateString."', '".$Type."', ".$Value.", '".$Payload."', NULL);"; + $query = "INSERT INTO `Data` (`Added`,`DateString`, `Type`, `Value`, `Payload`, `Uploaded`) VALUES (CURRENT_TIMESTAMP(),'".$DateString."', '".$Type."', ".$Value.", '".$Payload."', NULL);"; return mysqli_query($GLOBALS['dbc'],$query); } function ConfirmUpload($Payload) { diff --git a/dbload.php b/dbload.php index 9c43fb2..2ee2be3 100644 --- a/dbload.php +++ b/dbload.php @@ -72,4 +72,14 @@ function RandomString($Length) } DisconnectDB(); rename("v1/data.old", "v1/olddata/".RandomString(12).".".RandomString(4)); +/* +GetDeviceTime($entry["dateString"]) +*/ +//ConnectDB(); +//echo InsertValue($entry["dateString"], $entry["type"], $entry["mbg"] , "Payload"); +//echo ConfirmUpload("Payload"); +//DisconnectDB(); + +//'"payload":{"internalTime":"'.GetDeviceTime($entry["dateString"]).'","noiseMode":"Clean","trend":"'. $entry["direction"].'","value":'.ConvertToMmol($entry["sgv"]).'}' +//"payload":{"subType":"manual","time":"'.GetUTCTime($entry["dateString"]).'","timezoneOffset":'.GetUtcOffset().',"type":"smbg","units":"mmol/L","value":'.ConvertToMmol($entry["sgv"]).'} ?> \ No newline at end of file diff --git a/tidepool.inc.php b/tidepool.inc.php index dfad33d..4ce5785 100644 --- a/tidepool.inc.php +++ b/tidepool.inc.php @@ -4,14 +4,10 @@ die("Could not set infinite script timeout."); error_reporting(E_ALL); ini_set('display_errors', 'On'); -date_default_timezone_set('America/Los_Angeles'); -$baseurl = 'https://api.tidepool.org'; -$loginHash = /*BASE64 of EMAIL:PASSWORD*/; -$deviceId = /*DEXCOM SERIAL*/; $sessionStart = date(DATE_ATOM); $sessionToken = FALSE; $sessionData = array(); -$UTCoffset = -480; + function CheckFile($filename) { if(!file_exists($filename)) @@ -63,20 +59,20 @@ function DownloadAllData() { // not working return $response; } -function UploadBG($date, $type, $value) { +function UploadBG($date, $type, $value, $payload) { if($type == "sgv") { - $JSONstring = '{"uploadId":"'.GetUploadID().'","deviceId":"'.$GLOBALS['deviceId'].'","deviceTime":"'.GetDeviceTime($date).'","time":"'.GetUtcTime($date).'","timezoneOffset":'.$GLOBALS['UTCoffset'].',"type":"cbg","units":"mmol/L","value":'.ConvertToMmol($value).'}'; + $JSONstring = '{"uploadId":"'.GetUploadID().'","deviceId":"'.$GLOBALS['deviceId'].'","deviceTime":"'.GetDeviceTime($date).'","time":"'.GetUtcTime($date).'","timezoneOffset":'.$GLOBALS['UTCoffset'].',"type":"cbg","units":"mmol/L","value":'.ConvertToMmol($value).','.$payload.'}'; return UploadData($JSONstring); } if($type == "mbg") { - $JSONstring = '{"uploadId":"'.GetUploadID().'","deviceId":"'.$GLOBALS['deviceId'].'","deviceTime":"'.GetDeviceTime($date).'","time":"'.GetUtcTime($date).'","timezoneOffset":'.$GLOBALS['UTCoffset'].',"type":"smbg","subType":"manual","units":"mmol/L","value":'.ConvertToMmol($value).'}'; + $JSONstring = '{"uploadId":"'.GetUploadID().'","deviceId":"'.$GLOBALS['deviceId'].'","deviceTime":"'.GetDeviceTime($date).'","time":"'.GetUtcTime($date).'","timezoneOffset":'.$GLOBALS['UTCoffset'].',"type":"smbg","subType":"manual","units":"mmol/L","value":'.ConvertToMmol($value).','.$payload.'}'; return UploadData($JSONstring); } } function UploadData($JSONstring) { - $url = 'https://uploads.tidepool.org/data'; + $url = $GLOBALS['uploadapi'].'/data'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POST, 1);