| 1 | 1 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,33 @@ |
| 1 |
+STRAVA_API |
|
| 2 |
+ |
|
| 3 |
+{
|
|
| 4 |
+ "file": /path/to/file.txt, // {File} The uploaded file.
|
|
| 5 |
+ "name": name_example, // {String} The desired name of the resulting activity.
|
|
| 6 |
+ "description": description_example, // {String} The desired description of the resulting activity.
|
|
| 7 |
+ "trainer": trainer_example, // {String} Whether the resulting activity should be marked as having been performed on a trainer.
|
|
| 8 |
+ "commute": commute_example, // {String} Whether the resulting activity should be tagged as a commute.
|
|
| 9 |
+ "dataType": dataType_example, // {String} The format of the uploaded file.
|
|
| 10 |
+ "externalId": externalId_example // {String} The desired external identifier of the resulting activity.
|
|
| 11 |
+} |
|
| 12 |
+ |
|
| 13 |
+ |
|
| 14 |
+https://resmedglobal.atlassian.net/secure/CreateIssue.jspa?issuetype=2&pid=ISMS2 |
|
| 15 |
+https://resmedglobal.atlassian.net/secure/CreateIssue.jspa?issuetype=3&pid=ISMS2 |
|
| 16 |
+ |
|
| 17 |
+OAuth2.0 strava / pebble |
|
| 18 |
+ |
|
| 19 |
+1 - get activity:write authorization (once and for all) |
|
| 20 |
+ GET https://www.strava.com/oauth/authorize?client_id=94880&response_type=code&redirect_uri=http://strava.jonget.fr&approval_prompt=force&state=bike_companion&scope=activity:write |
|
| 21 |
+ monitor state, code and scope (as upload can be unchecked)! |
|
| 22 |
+ code is short lived and one time usage |
|
| 23 |
+2 - get tokens in exchange of code |
|
| 24 |
+ POST https://www.strava.com/oauth/token?client_id=94880&client_secret=08dc170f0fe38f39dd327bea82a28db4400e6f00&code=e0aeb60ea9f508d25974bb56ccb551be56b91470&grant_type=authorization_code |
|
| 25 |
+ refresh & access tokens + expiry of access token (6hours) retrieved |
|
| 26 |
+ |
|
| 27 |
+3 - test if access token expired |
|
| 28 |
+ |
|
| 29 |
+4a- if not, API call |
|
| 30 |
+ GET https://www.strava.com/api/v3/athlete with "Authorization" header ="Bearer XXXXX" XXXXX=access token |
|
| 31 |
+ |
|
| 32 |
+4b- if yes refresh access token with refresh token get in 2 |
|
| 33 |
+ POST https://www.strava.com/oauth/token?client_id=94880&client_secret=08dc170f0fe38f39dd327bea82a28db4400e6f00&refresh_token=XXXXXXX&grant_type=refresh_token |
| ... | ... |
@@ -65,16 +65,17 @@ static void send_message(char * msg){
|
| 65 | 65 |
|
| 66 | 66 |
|
| 67 | 67 |
static void prv_select_click_handler(ClickRecognizerRef recognizer, void *context) {
|
| 68 |
- text_layer_set_text(s_other_text_layer, "Select - sending get geoloc"); |
|
| 68 |
+ text_layer_set_text(s_speed_text_layer, ""); |
|
| 69 |
+ text_layer_set_text(s_other_text_layer, "sending get geoloc"); |
|
| 69 | 70 |
send_message("get");
|
| 70 | 71 |
} |
| 71 | 72 |
|
| 72 | 73 |
static void prv_up_click_handler(ClickRecognizerRef recognizer, void *context) {
|
| 73 |
- text_layer_set_text(s_other_text_layer, "Up"); |
|
| 74 |
+ //text_layer_set_text(s_other_text_layer, "Up"); |
|
| 74 | 75 |
} |
| 75 | 76 |
|
| 76 | 77 |
static void prv_down_click_handler(ClickRecognizerRef recognizer, void *context) {
|
| 77 |
- text_layer_set_text(s_other_text_layer, "Down"); |
|
| 78 |
+ //text_layer_set_text(s_other_text_layer, "Down"); |
|
| 78 | 79 |
} |
| 79 | 80 |
|
| 80 | 81 |
static void prv_click_config_provider(void *context) {
|
| ... | ... |
@@ -93,7 +94,6 @@ static void prv_window_load(Window *window) {
|
| 93 | 94 |
text_layer_set_text_color(s_speed_text_layer, GColorWhite); |
| 94 | 95 |
text_layer_set_font(s_speed_text_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD)); |
| 95 | 96 |
text_layer_set_text_alignment(s_speed_text_layer, GTextAlignmentCenter); |
| 96 |
- text_layer_set_text(s_speed_text_layer, "Press a button"); |
|
| 97 | 97 |
layer_add_child(window_layer, text_layer_get_layer(s_speed_text_layer)); |
| 98 | 98 |
|
| 99 | 99 |
|
| ... | ... |
@@ -101,9 +101,8 @@ static void prv_window_load(Window *window) {
|
| 101 | 101 |
|
| 102 | 102 |
text_layer_set_background_color(s_other_text_layer, GColorClear); |
| 103 | 103 |
text_layer_set_text_color(s_other_text_layer, GColorBlack); |
| 104 |
- text_layer_set_font(s_other_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14)); |
|
| 104 |
+ text_layer_set_font(s_other_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD)); |
|
| 105 | 105 |
text_layer_set_text_alignment(s_other_text_layer, GTextAlignmentCenter); |
| 106 |
- text_layer_set_text(s_other_text_layer, "Press a button"); |
|
| 107 | 106 |
layer_add_child(window_layer, text_layer_get_layer(s_other_text_layer)); |
| 108 | 107 |
} |
| 109 | 108 |
|
| ... | ... |
@@ -114,6 +113,7 @@ static void prv_window_unload(Window *window) {
|
| 114 | 113 |
void comm_is_ready() {
|
| 115 | 114 |
|
| 116 | 115 |
// set the text |
| 116 |
+ text_layer_set_text(s_speed_text_layer, "Press a button to start"); |
|
| 117 | 117 |
text_layer_set_text(s_other_text_layer, "Welcome to Bike Companion ! JSready"); |
| 118 | 118 |
|
| 119 | 119 |
} |
| ... | ... |
@@ -273,7 +273,7 @@ static void inbox_received_callback(DictionaryIterator *iter, void *context) {
|
| 273 | 273 |
|
| 274 | 274 |
APP_LOG(APP_LOG_LEVEL_DEBUG, "to display : %s ",s_msg); |
| 275 | 275 |
|
| 276 |
- text_layer_set_text(s_speed_text_layer, strcat(s_speed," km/h")); |
|
| 276 |
+ text_layer_set_text(s_speed_text_layer, s_speed); |
|
| 277 | 277 |
text_layer_set_text(s_other_text_layer, s_msg); |
| 278 | 278 |
}else{
|
| 279 | 279 |
//APP_LOG(APP_LOG_LEVEL_DEBUG, "not status message... "); |
| ... | ... |
@@ -8,7 +8,6 @@ var message; |
| 8 | 8 |
var gpx_to_strava = false; |
| 9 | 9 |
var csv_to_web = true; |
| 10 | 10 |
|
| 11 |
-var firstlocationInterval; |
|
| 12 | 11 |
var locationInterval; |
| 13 | 12 |
|
| 14 | 13 |
var firstlocationOptions = {
|
| ... | ... |
@@ -129,7 +128,7 @@ function GPXHeadersBuilder(timestamp, name, type) {
|
| 129 | 128 |
function GPXtrkptBuilder(lat, lon, ele, timestamp) {
|
| 130 | 129 |
var GPX = localStorage.getItem("GPX");
|
| 131 | 130 |
var trkpt = '<trkpt lat="' + lat + '" lon="' + lon + '"><ele>' + ele + '</ele><time>' + timestamp + '</time></trkpt>'; |
| 132 |
- var ret = localStorage.setItem("GPX", GPX + trkpt);
|
|
| 131 |
+ localStorage.setItem("GPX", GPX + trkpt);
|
|
| 133 | 132 |
return true; |
| 134 | 133 |
} |
| 135 | 134 |
|
| ... | ... |
@@ -139,13 +138,14 @@ function GPXfooterBuilder() {
|
| 139 | 138 |
var GPX = localStorage.getItem("GPX");
|
| 140 | 139 |
var footer = '</trkseg></trk></gpx>'; |
| 141 | 140 |
var ret = localStorage.setItem("GPX", GPX + footer);
|
| 142 |
- console.log("GPX closed : " + GPX + footer);
|
|
| 141 |
+ //console.log("GPX closed : " + GPX + footer);
|
|
| 143 | 142 |
return ret; |
| 144 | 143 |
} |
| 145 | 144 |
|
| 146 | 145 |
// Send GPX to Strava profile |
| 147 | 146 |
// TODO : get authentication creds from settings |
| 148 | 147 |
function SendToStrava() {
|
| 148 |
+ console.log('--- GPX upload to strava');
|
|
| 149 | 149 |
var GPX = localStorage.getItem("GPX");
|
| 150 | 150 |
|
| 151 | 151 |
|
| ... | ... |
@@ -203,20 +203,21 @@ function CSV(pos) {
|
| 203 | 203 |
// Send CSV to web server (need configuration on serverside) |
| 204 | 204 |
// TODO : secure it ? |
| 205 | 205 |
function PostToWeb() {
|
| 206 |
+ console.log('--- CSV upload to web');
|
|
| 206 | 207 |
var CSV = localStorage.getItem("CSV");
|
| 207 | 208 |
|
| 208 |
- var url = "https://jonget.fr/strava/upload.php?name=pebblecsv&type=gpx/xml"; |
|
| 209 |
+ var url = "https://jonget.fr/strava/upload.php?name=pebblecsv&type=application/gpx+xml"; |
|
| 209 | 210 |
var xhr = new XMLHttpRequest(); |
| 210 | 211 |
xhr.timeout = 10000; // time in milliseconds |
| 211 | 212 |
|
| 212 | 213 |
xhr.open("POST", url, false);
|
| 213 | 214 |
|
| 214 |
- console.log('------ CSV / xhr opened')
|
|
| 215 |
+ //console.log('------ CSV / xhr opened')
|
|
| 215 | 216 |
xhr.onload = function () {
|
| 216 |
- console.log('------xhr onload')
|
|
| 217 |
+ //console.log('------xhr onload')
|
|
| 217 | 218 |
if (xhr.readyState === 4) {
|
| 218 |
- console.log('------xhr request returned with ' + xhr.status);
|
|
| 219 |
- console.log(this.responseText); |
|
| 219 |
+ //console.log('------xhr request returned with ' + xhr.status);
|
|
| 220 |
+ //console.log(this.responseText); |
|
| 220 | 221 |
if (xhr.status == 200) {
|
| 221 | 222 |
//console.log('--> HTTP 200');
|
| 222 | 223 |
return true; |
| ... | ... |
@@ -235,7 +236,6 @@ function PostToWeb() {
|
| 235 | 236 |
// Send location to web server for instant location (no tracking) |
| 236 | 237 |
// TODO : secure it ? |
| 237 | 238 |
function instantLocationUpdate(pos) {
|
| 238 |
- |
|
| 239 | 239 |
console.log('--- Instant location update');
|
| 240 | 240 |
// console.log(" location is " + new_pos.coords.latitude + ',' + new_pos.coords.longitude + ' , acc. ' + new_pos.coords.accuracy);
|
| 241 | 241 |
|
| ... | ... |
@@ -245,12 +245,12 @@ function instantLocationUpdate(pos) {
|
| 245 | 245 |
|
| 246 | 246 |
xhr.open("POST", url);
|
| 247 | 247 |
|
| 248 |
- console.log('------ instant / xhr opened')
|
|
| 248 |
+ //console.log('------ instant / xhr opened')
|
|
| 249 | 249 |
xhr.onload = function () {
|
| 250 |
- console.log('------xhr onload')
|
|
| 250 |
+ //console.log('------xhr onload')
|
|
| 251 | 251 |
if (xhr.readyState === 4) {
|
| 252 |
- console.log('------xhr request returned with ' + xhr.status);
|
|
| 253 |
- console.log(this.responseText); |
|
| 252 |
+ //console.log('------xhr request returned with ' + xhr.status);
|
|
| 253 |
+ //console.log(this.responseText); |
|
| 254 | 254 |
if (xhr.status == 200) {
|
| 255 | 255 |
//console.log('--> HTTP 200');
|
| 256 | 256 |
return true; |
| ... | ... |
@@ -343,12 +343,12 @@ function locationSuccess(new_pos) {
|
| 343 | 343 |
if (gpx_to_strava) {
|
| 344 | 344 |
//add a new datapoint to GPX file |
| 345 | 345 |
GPXtrkptBuilder(latitudeString, longitudeString, altitudeString, timestampISO); |
| 346 |
- console.log('GPX: ' + localStorage.getItem("GPX"));
|
|
| 346 |
+ //console.log('GPX: ' + localStorage.getItem("GPX"));
|
|
| 347 | 347 |
} |
| 348 | 348 |
if (csv_to_web) {
|
| 349 | 349 |
// Start the csv file |
| 350 | 350 |
CSV(new_pos); |
| 351 |
- console.log('CSV: ' + localStorage.getItem("CSV"));
|
|
| 351 |
+ //console.log('CSV: ' + localStorage.getItem("CSV"));
|
|
| 352 | 352 |
} |
| 353 | 353 |
|
| 354 | 354 |
|
| ... | ... |
@@ -370,13 +370,9 @@ function locationSuccess(new_pos) {
|
| 370 | 370 |
}); |
| 371 | 371 |
} |
| 372 | 372 |
|
| 373 |
- // restart the watch |
|
| 374 |
- //geoloc_id = navigator.geolocation.watchPosition(locationSuccess, locationError, locationOptions); |
|
| 375 | 373 |
} |
| 376 | 374 |
|
| 377 | 375 |
function locationError(err) {
|
| 378 |
- //clear watch of new position to avoid overlap |
|
| 379 |
- //navigator.geolocation.clearWatch(geoloc_id); |
|
| 380 | 376 |
|
| 381 | 377 |
console.warn('location error (' + err.code + '): ' + err.message);
|
| 382 | 378 |
if (csv_to_web) {
|
| ... | ... |
@@ -387,8 +383,6 @@ function locationError(err) {
|
| 387 | 383 |
localStorage.setItem("CSV", CSV + datapoint);
|
| 388 | 384 |
} |
| 389 | 385 |
|
| 390 |
- // restart the watch |
|
| 391 |
- //geoloc_id = navigator.geolocation.watchPosition(locationSuccess, locationError, locationOptions); |
|
| 392 | 386 |
} |
| 393 | 387 |
|
| 394 | 388 |
|
| ... | ... |
@@ -399,7 +393,7 @@ function get_coordinate() {
|
| 399 | 393 |
|
| 400 | 394 |
locationInterval = setInterval(function () {
|
| 401 | 395 |
navigator.geolocation.getCurrentPosition(locationSuccess, locationError, locationOptions); |
| 402 |
- }, 5000); |
|
| 396 |
+ }, 1000); |
|
| 403 | 397 |
|
| 404 | 398 |
instantLocationInterval = setInterval(function () {
|
| 405 | 399 |
navigator.geolocation.getCurrentPosition(instantLocationUpdate, locationError, locationOptions); |
| ... | ... |
@@ -430,7 +424,7 @@ Pebble.addEventListener('ready', function (e) {
|
| 430 | 424 |
Pebble.addEventListener('appmessage', function (e) {
|
| 431 | 425 |
// Get the dictionary from the message |
| 432 | 426 |
var dict = e.payload; |
| 433 |
- console.log(dict[0].toString()); |
|
| 427 |
+ //console.log(dict[0].toString()); |
|
| 434 | 428 |
switch (dict[0]) {
|
| 435 | 429 |
case 'get': |
| 436 | 430 |
get_coordinate(); |
| ... | ... |
@@ -443,7 +437,6 @@ Pebble.addEventListener('appmessage', function (e) {
|
| 443 | 437 |
SendToStrava(); |
| 444 | 438 |
} |
| 445 | 439 |
if (csv_to_web) {
|
| 446 |
- //CSV(new_pos); |
|
| 447 | 440 |
// send CSV to web server through API |
| 448 | 441 |
PostToWeb(); |
| 449 | 442 |
} |