Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
auxlife authored Dec 31, 2016
1 parent 9b37ab7 commit 8419ece
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
16 changes: 16 additions & 0 deletions config.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php
$DbHost = /*DATABASE HOST*/;
$DbUser = /*DATABASE USER*/;
$DbPass = /*DATABASE PASSWORD*/;
$DbName = /*DATABASE NAME*/;

$uploadapi = 'https://uploads.tidepool.org';
$baseurl = 'https://api.tidepool.org';
$loginHash = /*BASE64 of EMAIL:PASSWORD*/;
$deviceId = /*DEXCOM SERIAL*/;

// Set the Local timezone used by xdrip
date_default_timezone_set('America/Los_Angeles');
//Time difference between UTC and Local Timezone
$UTCoffset = -480;
?>
7 changes: 4 additions & 3 deletions db.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions dbload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]).'}
?>
14 changes: 5 additions & 9 deletions tidepool.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8419ece

Please sign in to comment.