01-30-2020 07:10
01-30-2020 07:10
I have created one app for Fitbit ionic and Versa app in version 3.1and it was working properly. That app is already live. and now suddenly that stopped working and when I am checking in the studio it is giving this error "error Unhandled exception: TypeError: Expected a constructor".
Why my live app is not working with new SDK?
01-30-2020 09:44
01-30-2020 09:44
Can't really tell from that snippet. Do you have any other variables named Accelerometer in your code? Can you paste the contents of the file here?
02-03-2020 09:36 - edited 02-03-2020 11:28
02-03-2020 09:36 - edited 02-03-2020 11:28
Accelerometer isn't working on the simulator, I tried a blank project with just these 3 lines:
import { Accelerometer } from "accelerometer";
const acc = new Accelerometer({ frequency: 1 });
acc.start();
and still getting the same error...
Edit:
I noticed that the 'Accelerometer' imported is undefined when running in the simulator, on the contrary on the watch everything works.
02-03-2020 11:35
02-03-2020 11:35
The simulator doesn't have an accelerometer, nor does it try to simulate an accelerometer.
You can forge some accelerometer data using the heart-rate and/or battery sliders.
02-03-2020 11:48
02-03-2020 11:48
That's what I thought but this old fitbit-os-simulator changelog page says otherwise...
Anyway thank you. I'll stop trying
02-03-2020 11:54
02-03-2020 11:54
Good point! It could be argued that the API is present but the relevant object can't be instantiated. 🙂
An analogy: Versa Lite has the Barometer API — but no barometer so you can't instantiate it.
02-05-2020 07:39 - edited 02-05-2020 07:46
02-05-2020 07:39 - edited 02-05-2020 07:46
here is the full file code... @JonFitbit
import clock from "clock";
import document from "document";
import * as util from "../common/utils";
// import { me } from "appbit";
//turn off display autooff
import { display } from "display";
display.autoOff = false;
display.on = true;
/******************************/
/* socket connection code: start */
//files for socket call
import { BartUI } from "./ui.js";
import * as messaging from "messaging";
//code for socket call
let ui = new BartUI();
//code for socket call
ui.updateUI();
const errormessagebox= document.getElementById("errormessagebox");
messaging.peerSocket.onopen = function() {
// console.log("watch: socket open");
errormessagebox.style.visibility = "hidden";
}
messaging.peerSocket.onclose = function() {
// console.log("watch: socket close");
errormessagebox.style.visibility = "visible";
}
// // Listen for the onerror event
messaging.peerSocket.onerror = function(err) {
// Handle any errors
// console.log("watch: socket error");
errormessagebox.style.visibility = "visible";
}
// // Listen for the onmessage event
messaging.peerSocket.onmessage = function(msg) {
console.log("watch: socket message received: "+JSON.stringify(msg.data));
if(msg.data == "MISSING_FITBIT_AUTH"){
errormessagebox.text = "Authentication Required";
errormessagebox.style.visibility = "visible";
}else if(msg.data == "COMPLETED_FITBIT_AUTH"){
errormessagebox.text = "";
errormessagebox.style.visibility = "hidden";
}else if (msg.data == "MISSING_LINKING"){
errormessagebox.text = "Better Alerts Not Linked";
errormessagebox.style.visibility = "visible";
}else if (msg.data == "COMPLETED_LINKING"){
errormessagebox.text = "";
errormessagebox.style.visibility = "hidden";
}else if(msg.data == "EMERGENCY_CONTACTED"){
/* show some text on watch screen if bottom button pressed */
let clockface = document.getElementById("clockface");
let emergencyface = document.getElementById("emergencyface");
// console.log("==== here before timeout ====");
setTimeout(function(){
// console.log("==== here inside timeout ====");
clockface.style.visibility = (clockface.style.visibility == "hidden") ? "visible" : "hidden";
emergencyface.style.visibility = (emergencyface.style.visibility == "hidden") ? "visible" : "hidden";
vibration.stop("nudge-max");
}, 4000);
vibration.start("nudge-max");
// console.log("==== here after timeout ====");
clockface.style.visibility = (clockface.style.visibility == "hidden") ? "visible" : "hidden";
emergencyface.style.visibility = (emergencyface.style.visibility == "hidden") ? "visible" : "hidden";
}
// console.log("watch: socket message received");
}
if (messaging.peerSocket.readyState === messaging.peerSocket.CLOSED) {
// messagebox.text = `Fitbit App Not Connected`;
console.log("Fitbit App is not connected");
}
/* socket connection code: end */
/******************************/
/******************************/
/* Accelerometer code: start */
import { Accelerometer } from "accelerometer";
// Create a new accelerometer, sampling at 1hz (once per second)
var accel = new Accelerometer({ frequency: 1 });
let accel_ratio = 30;
let accel_ratio_minus = -30;
/* check for body presence */
import { BodyPresenceSensor } from "body-presence";
let body = new BodyPresenceSensor();
body.onreading = () => {
if (!body.present) {
// console.log("not present");
//Stop monitoring the sensor
accel.stop();
} else {
// console.log("present");
//Begin monitoring the sensor
accel.start();
}
};
body.start();
accel.onreading = function() {
// console.log("reading accelerometer");
// Peek the current sensor values
// console.log("ts: "+ accel.timestamp + " x: "+ accel.x + " y: "+ accel.y + " z: "+ accel.z);
if((accel.x > accel_ratio || accel.x < accel_ratio_minus) || (accel.y > accel_ratio || accel.y < accel_ratio_minus) || (accel.z > accel_ratio || accel.z < accel_ratio_minus)) {
// console.log("fallback detected");
messaging.peerSocket.send("fallback");
}
// Stop monitoring the sensor
//accel.stop();
}
/* accel code: end */
/******************************/
import { vibration } from "haptics";
/* Physical button press code: start */
document.onkeypress = function(e) {
console.log("Key pressed: " + e.key);
if(e.key == "up" || e.key == "down"){
messaging.peerSocket.send(e.key);
//display message on bottom button press
if(e.key == "down") {
// /* show some text on watch screen if bottom button pressed */
// let clockface = document.getElementById("clockface");
// let emergencyface = document.getElementById("emergencyface");
// console.log("==== here before timeout ====");
// setTimeout(function(){
// console.log("==== here inside timeout ====");
// clockface.style.visibility = (clockface.style.visibility == "hidden") ? "visible" : "hidden";
// emergencyface.style.visibility = (emergencyface.style.visibility == "hidden") ? "visible" : "hidden";
// vibration.stop("nudge-max");
// }, 4000);
// vibration.start("nudge-max");
// console.log("==== here after timeout ====");
// clockface.style.visibility = (clockface.style.visibility == "hidden") ? "visible" : "hidden";
// emergencyface.style.visibility = (emergencyface.style.visibility == "hidden") ? "visible" : "hidden";
}
}
}
/******************************/
/* clock code: start */
// Get a handle on the <text> element
let myLabel = document.getElementById("myLabel");
// Update the clock every minute
clock.granularity = "minutes";
// Update the clock every tick event
clock.ontick = () => updateClock();
// Update the <text> element with the current time
function updateClock() {
// console.log("here in clock update");
let today = new Date();
let hours = today.getHours();
let mins = util.zeroPad(today.getMinutes());
let ampm = 'am';
if(hours > 12){
hours = hours - 12;
ampm = 'pm';
}
myLabel.text = `${hours}:${mins}`;
}
/* clock code: end */
/******************************/
/******************************/
//show date
var month = new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEPT","OCT","NOV","DEC");
var dayArr = new Array("Sun","Mon","Tue","Wed","Thu","Fri","Sat");
let today = new Date();
const myMonth = document.getElementById("myMonth");
const myDay = document.getElementById("myDay");
let monthnum = today.getMonth();
let daynum = today.getDate();
let day = today.getDay();
let year = today.getFullYear();
let monthname = month[monthnum];
let dayname = dayArr[day];
myMonth.text = `${dayname} ${monthname} ${daynum}, ${year}`;
// document.getElementById("emergencyface").style.display = "none";
document.getElementById("emergencyface").style.visibility = "hidden";