Hello everyone,
I followed the documentation, but I can't get access to all the sensors. Can anyone confirm that?
Here's my code:
import { Accelerometer } from "accelerometer";
import { Barometer } from "barometer";
import { HeartRateSensor } from "heart-rate";
import { Gyroscope } from "gyroscope";
import { OrientationSensor } from "orientation";
console.log("App Started");
let accel = new Accelerometer();
let bar = new Barometer();
let hrm = new HeartRateSensor();
let gyro = new Gyroscope();
let orientation = new OrientationSensor({ frequency: 60 });
accel.start();
bar.start();
hrm.start();
gyro.start();
orientation.start();
function refreshData() {
console.log("accel:", accel.timestamp,
"bar:", bar.pressure,
"hrm:", hrm.heartRate,
"gyro:", gyro.timestamp,
"orientation", orientation.timestamp
);
}
refreshData();
setInterval(refreshData, 2000);
Answered! Go to the Best Answer.
Best AnswerI wrote this some time ago, so I had to change 'appbit' to 'me' in the import { appbit } from "appbit" to get it to work for me, but otherwise the orientation and gyro log for me.
My only other suggestion would be to restart your watch and see if that gets those sensors to start working.
Hi allyann,
yes I selected all permissios. But I only get values for the heartbeat and the barometric pressure.
The other sensors return NULL.
Best AnswerThe following code works, Just beware that if you increase the sampling rate (frequency), the logging can cause studio to hang.
import document from "document";
import { Gyroscope } from "gyroscope";
import { OrientationSensor } from "orientation";
import { HeartRateSensor } from "heart-rate";
import { appbit } from "appbit";
console.log("App Started");
// Create a new instance of the Gyroscope object
let gyro = new Gyroscope({ frequency: 1 });
let orientation = new OrientationSensor({ frequency: 1 });
let hrm = new HeartRateSensor({ frequency: 1 });
var gyroXElement = document.getElementById("gyro-x");
var gyroYElement = document.getElementById("gyro-y");
var gyroZElement = document.getElementById("gyro-z");
hrm.onreading = function() {
console.log(hrm.timestamp + ": " + hrm.heartRate);
}
gyro.onreading = function() {
var x = gyro.x.toFixed(3);
var y = gyro.y.toFixed(3);
var z = gyro.z.toFixed(3);
gyroXElement.text = x;
gyroYElement.text = y;
gyroZElement.text = z;
let gyroData = {
gyro: {
ts: gyro.timestamp,
x: x ? x : 0,
y: y ? y : 0,
z: z ? z : 0
},
};
console.log(JSON.stringify(gyroData));
}
orientation.onreading = function() {
let data = {
orientation: {
ts: orientation.timestamp,
q0: orientation.quaternion[0],
q1: orientation.quaternion[1],
q2: orientation.quaternion[2],
q4: orientation.quaternion[3],
},
};
console.log(JSON.stringify(data));
}
me.onunload = function() {
gyro.stop();
orientation.stop();
hrm.stop();
}
// Begin monitoring the sensor
orientation.start();
gyro.start();
hrm.start();
Best AnswerUnfortunately, your code doesn't work either.
Only HRM is printed. Orientation and Gyroscope doesn`t appear.
Here is the console log
[22:03:06]App Started app/index.js:20,1[22:03:06]361512852: 56 app/index.js:20,1[22:03:06]361512908: 56 app/index.js:20,1[22:03:07]361513926: 56
... [HOST][22:03:15]App Closed
Best AnswerI wrote this some time ago, so I had to change 'appbit' to 'me' in the import { appbit } from "appbit" to get it to work for me, but otherwise the orientation and gyro log for me.
My only other suggestion would be to restart your watch and see if that gets those sensors to start working.
After some resets my Ionic suddenly started to get values for some reason.
Thanks for your input.
Best Answer