Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Data Collection/Streaming App

I am trying to create a watchface app for the Ionic that will continuously collect accelerometer data at a frequency of 50 Hz and heart rate data once a minute. I then need to continuously upload this data somewhere online that can be easily accessed (ideally I would stream the data directly to our 3rd party system, but that doesn’t seem to be possible at the moment).

 

I am just very lost and am getting confused with the system architecture. Do I need to send my data to the companion app and then upload it to the internet? If so, how do I do that? And where and how can I upload it? I'm pretty new to this.

 

Here’s what I have so far, and I‘d appreciate any feedback…

 

App:

// Import the messaging module
import * as messaging from "messaging";


// Import sensor modules
import { Accelerometer } from "accelerometer";
import { HeartRateSensor } from "heart-rate";
import document from "document";

var DataArray = []; //initialize accelerometer storage array
DataArray.length = 3000; //3000 entries ~ 1 minute of data

// Initialize sensors
console.log("App Started");

let accelData = document.getElementById("accel-data");
let hrmData = document.getElementById("hrm-data");

//let xData = document.getElementById("x-data");

let accel = new Accelerometer({ frequency: 50 }); //set 50 Hz sampling frequency
let hrm = new HeartRateSensor();

accel.start();
hrm.start();

var count = 0;
var HR = 0;
var HR_ts = 0;
var accel_x = 0;
var accel_y = 0;
var accel_z = 0;
var accel_ts = 0;



// Listen for the onopen event
messaging.peerSocket.onopen = function() {
  // Ready to send messages
  //sendMessage();
  refreshAccelData();
}


// Listen for the onerror event
messaging.peerSocket.onerror = function(err) {
  // Handle any errors
  console.log("Connection error: " + err.code + " - " + err.message);
}


setInterval(refreshAccelData, 0.05);
//setInterval(refreshAccelData, 50);
//setInterval(refreshData, 50);



function refreshAccelData() {
  count = count + 1;
  accel_x = accel.x ? accel.x.toFixed(1) : 0 ;
  accel_y = accel.y ? accel.y.toFixed(1) : 0 ;
  accel_z = accel.z ? accel.z.toFixed(1) : 0 ;
  accel_ts = accel.timestamp ;
  DataArray[count] = { accel_x , accel_y , accel_z , accel_ts , HR , HR_ts};
  if (count == 3000){ //once a minute refreshes the HR variable and its timestamp
    refreshHRData();
    count = 0;
    /*
    if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
    // Send the data to peer as a message
      messaging.peerSocket.send(DataArray);
      DataArray = [];
      DataArray.length = 3000;
    }
    */
  }
  
  
  if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
    // Send the data to peer as a message
    messaging.peerSocket.send(DataArray);
    DataArray = [];
    DataArray.length = 3000;
    }
  
}

function refreshHRData(){
  HR = hrm.heartRate ? hrm.heartRate : 0;
  HR_ts = accel.timestamp;
}

Companion:

// Import the messaging module
import * as messaging from "messaging";

// Listen for the onmessage event
messaging.peerSocket.onmessage = function(evt) {
  // Output the message to the console
  console.log(JSON.stringify(evt.data));
}
Best Answer
1 REPLY 1

any news?

Best Answer
0 Votes