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

inconsistency between simulator and watch

ANSWERED

When using the simulator I have no issue using fetch and grabbing some data from an API, then passing it to the from the companion app to the fitbit with the messenging service. When i deploy it to the actual fitbit I'm getting a null. Am i missing a cert or something?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

I'm pretty sure fetch is only supporting https. The simulator doesn't have that restriction though.

View best answer in original post

Best Answer
0 Votes
6 REPLIES 6

Did you double check that you set the permissions properly in the package.json? Can you post a code snippet?

Best Answer
0 Votes
export function usgsCall(site){
 const host = `http://waterservices.usgs.gov/nwis/iv/?format=json&sites=${site}&period=P1D`;
 return fetch(host, {
    method : "GET"}) 
    .then(function(response){
      return response.json();
    })
    .then(function(data) {
      let obj = data.value.timeSeries;
      console.log(data.value.timeSeries);
      for (var key in obj){
        if (obj.hasOwnProperty(key))
        {
          if(obj[key].variable.unit.unitCode === "ft3/s"){
            var cfs = obj[key].values[0].value[0].value;
            var four = cfs - obj[key].values[0].value[12].value;
            var two = cfs - obj[key].values[0].value[8].value;
            var half = cfs - obj[key].values[0].value[2].value;
          }
          if(obj[key].variable.unit.unitCode === "ft"){
            var feet = obj[key].values[0].value[0].value;
          }
        }
      }
      return {cfs: cfs, feet: feet, four: four, two: two, half: half};
    })
    .catch(function(error) {
      console.log(error, 'error');
    });
}

The error will be throw but wont actual print anything.

Best Answer
0 Votes

Its the fetch itself where i'm running into an issue i believe.

Best Answer
0 Votes

This is the error I'm pulling.

SyntaxError: Unexpected end of JSON input
Best Answer
0 Votes

I'm pretty sure fetch is only supporting https. The simulator doesn't have that restriction though.

Best Answer
0 Votes

I can call an HTTP web server from a local network when running on the versa but I can't do an HTTP request to a public IP address, I'm also getting a null.

 

Making HTTP requests should be allowed.

Nonetheless, Where can we find more info about what's allowed and what not?

Best Answer
0 Votes