01-30-2022 15:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-30-2022 15:08
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
- Who Voted for this post?
So I created a clockface with weather data from OpenWeather but every time I open an app or open Fitbit today the info is gone and I have to sync my watch again. Is there a way that I could keep the "out of date" weather data until I can get new data? (even when closing the clockface) (I'm using a Fitbit Versa 2)

- Labels:
-
JavaScript
01-30-2022 17:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


01-30-2022 17:02
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Yes: save the data to the file system on the watch. See fs API doco.
Gondwana Software

01-30-2022 18:57
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

01-30-2022 18:57
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
MY REPLY GOT DELETED???!!!
@Gondwana As I was saying I have no idea what to do and the FS API is complicated, so I was wondering if you could explain me how to do it.
My code is very simple:
In app I have this:
// Import the messaging module
import * as messaging from "messaging";
import document from "document";
// Request weather data from the companion
function fetchWeather() {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
// Send a command to the companion
messaging.peerSocket.send({
command: 'weather'
});
}
}
// Display the weather data received from the companion
function processWeatherData(data) {
console.log("The temperature is: " + data.temperature);
console.log("The location is : " + data.location);
console.log("The forecast is: " + data.meteo);
// Get handle on text fields
let tempText = document.getElementById("tempText");
let locationText = document.getElementById("locationText");
let forecastText = document.getElementById("forecastText");
// Inside the processWeatherData block
tempText.text = Math.round(data.temperature) + "°C";
locationText.text = (data.location);
forecastText.text = (data.meteo);
}
// Listen for the onopen event
messaging.peerSocket.onopen = function() {
// Fetch weather when the connection opens
fetchWeather();
}
// Listen for messages from the companion
messaging.peerSocket.onmessage = function(evt) {
if (evt.data) {
processWeatherData(evt.data);
}
}
// Listen for the onerror event
messaging.peerSocket.onerror = function(err) {
// Handle any errors
console.log("Connection error: " + err.code + " - " + err.message);
}
setInterval(fetchWeather, 60 * 1000 * 60);
And this in the companion:
// Import the messaging module
import * as messaging from "messaging";
import { geolocation } from "geolocation";
var API_KEY = "API KEY";
// Fetch the weather from OpenWeather
function queryOpenWeather() {
geolocation.getCurrentPosition(locationSuccess, locationError);
function locationSuccess(position) {
var lat = position.coords.latitude;
var long = position.coords.longitude;
console.log("latitude: " + lat);
console.log("langitude: " + long);
var linkApi = "https://api.openweathermap.org/data/2.5/weather?lat=" + lat + "&lon=" + long + "&units=metric" + "&APPID=" + API_KEY;
fetch(linkApi)
.then(function (response) {
response.json()
.then(function(data) {
// We just want some data
var weather = {
temperature: data["main"]["temp"], humidity: data["main"]["humidity"], location: data["name"], meteo: data["weather"][0]["main"]
}
// Send the weather data to the device
returnWeatherData(weather);
});
})
.catch(function (err) {
console.log("Error fetching weather: " + err);
});
};
function locationError(error) {
console.log("Error: " + error.code,
"Message: " + error.message);
}
}
// Send the weather data to the device
function returnWeatherData(data) {
if (messaging.peerSocket.readyState === messaging.peerSocket.OPEN) {
// Send a command to the device
messaging.peerSocket.send(data);
} else {
console.log("Error: Connection is not open");
}
}
// Listen for messages from the device
messaging.peerSocket.onmessage = function(evt) {
if (evt.data && evt.data.command == "weather") {
// The device requested weather data
queryOpenWeather();
}
}
// Listen for the onerror event
messaging.peerSocket.onerror = function(err) {
// Handle any errors
console.log("Connection error: " + err.code + " - " + err.message);
}
Do you have any idea what to do?

01-31-2022 11:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post



01-31-2022 11:52
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Moved post to SDK forums
Senior Technical Solutions Consultant
Fitbit Partner Engineering & Web API Support | Google

