Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
6
600SeriesAndroidUploader
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
cgm
uploader
600SeriesAndroidUploader
Commits
0e332d3d
Commit
0e332d3d
authored
8 years ago
by
Volker Richert
Browse files
Options
Downloads
Patches
Plain Diff
split collection upload of device status into single posts
parent
36887c56
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java
+29
-16
29 additions, 16 deletions
...roid/upload/nightscout/NightscoutUploadIntentService.java
with
29 additions
and
16 deletions
app/src/main/java/info/nightscout/android/upload/nightscout/NightscoutUploadIntentService.java
+
29
−
16
View file @
0e332d3d
...
...
@@ -30,6 +30,7 @@ import java.util.regex.Pattern;
import
info.nightscout.android.R
;
import
info.nightscout.android.medtronic.MainActivity
;
import
info.nightscout.android.medtronic.service.MedtronicCnlIntentService
;
import
info.nightscout.android.model.medtronicNg.PumpStatusEvent
;
import
info.nightscout.android.upload.nightscout.serializer.EntriesSerializer
;
import
io.realm.Realm
;
...
...
@@ -74,18 +75,22 @@ public class NightscoutUploadIntentService extends IntentService {
.
notEqualTo
(
"sgv"
,
0
)
.
findAll
();
SharedPreferences
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
mContext
);
if
(
records
.
size
()
>
0
)
{
SharedPreferences
prefs
=
PreferenceManager
.
getDefaultSharedPreferences
(
mContext
);
Boolean
enableRESTUpload
=
prefs
.
getBoolean
(
"EnableRESTUpload"
,
false
);
try
{
if
(
enableRESTUpload
)
{
long
start
=
System
.
currentTimeMillis
();
Log
.
i
(
TAG
,
String
.
format
(
"Starting upload of %s record using a REST API"
,
records
.
size
()));
doRESTUpload
(
prefs
,
records
);
Log
.
i
(
TAG
,
String
.
format
(
"Finished upload of %s record using a REST API in %s ms"
,
records
.
size
(),
System
.
currentTimeMillis
()
-
start
));
Boolean
enableRESTUpload
=
prefs
.
getBoolean
(
"EnableRESTUpload"
,
false
);
try
{
if
(
enableRESTUpload
)
{
long
start
=
System
.
currentTimeMillis
();
Log
.
i
(
TAG
,
String
.
format
(
"Starting upload of %s record using a REST API"
,
records
.
size
()));
doRESTUpload
(
prefs
,
records
);
Log
.
i
(
TAG
,
String
.
format
(
"Finished upload of %s record using a REST API in %s ms"
,
records
.
size
(),
System
.
currentTimeMillis
()
-
start
));
}
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"ERROR uploading data!!!!!"
,
e
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"
ERROR uploading data!!!!!"
,
e
);
}
else
{
Log
.
i
(
TAG
,
"
No records has to be uploaded"
);
}
NightscoutUploadReceiver
.
completeWakefulIntent
(
intent
);
...
...
@@ -159,14 +164,16 @@ public class NightscoutUploadIntentService extends IntentService {
JSONArray
entriesBody
=
new
JSONArray
();
for
(
PumpStatusEvent
record
:
records
)
{
addDeviceStatus
(
devicestatusBody
,
record
);
addSgvEntry
(
entriesBody
,
record
);
addMbgEntry
(
entriesBody
,
record
);
}
uploadToNightscout
(
new
URL
(
baseURL
+
"/entries"
),
secret
,
entriesBody
);
uploadToNightscout
(
new
URL
(
baseURL
+
"/devicestatus"
),
secret
,
devicestatusBody
);
for
(
int
i
=
0
;
i
<
devicestatusBody
.
length
();
i
++)
{
uploadToNightscout
(
new
URL
(
baseURL
+
"/devicestatus"
),
secret
,
devicestatusBody
.
getJSONObject
(
i
));
}
// Yay! We uploaded. Tell Realm
// FIXME - check the upload succeeded!
...
...
@@ -183,7 +190,15 @@ public class NightscoutUploadIntentService extends IntentService {
}
}
private
boolean
uploadToNightscout
(
URL
endpoint
,
String
secret
,
JSONObject
httpBody
)
throws
Exception
{
return
uploadToNightscout
(
endpoint
,
secret
,
httpBody
.
toString
());
}
private
boolean
uploadToNightscout
(
URL
endpoint
,
String
secret
,
JSONArray
httpBody
)
throws
Exception
{
return
uploadToNightscout
(
endpoint
,
secret
,
httpBody
.
toString
());
}
private
boolean
uploadToNightscout
(
URL
endpoint
,
String
secret
,
String
httpBody
)
throws
Exception
{
Log
.
i
(
TAG
,
"postURL: "
+
endpoint
.
toString
());
HttpPost
post
=
new
HttpPost
(
endpoint
.
toString
());
...
...
@@ -209,12 +224,10 @@ public class NightscoutUploadIntentService extends IntentService {
DefaultHttpClient
httpclient
=
new
DefaultHttpClient
(
params
);
String
jsonString
=
httpBody
.
toString
();
Log
.
i
(
TAG
,
"Upload JSON: "
+
jsonString
);
Log
.
i
(
TAG
,
"Upload JSON: "
+
httpBody
);
try
{
StringEntity
se
=
new
StringEntity
(
jsonString
);
StringEntity
se
=
new
StringEntity
(
httpBody
);
post
.
setEntity
(
se
);
post
.
setHeader
(
"Accept"
,
"application/json"
);
post
.
setHeader
(
"Content-type"
,
"application/json"
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment