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

Send data from companion to localhost server in laptop hotspot

ANSWERED

Hello fellow Fitbit developers,

 

I have developed an app that get the heart rate from a fitbit ionic device and sends it to the android companion. The companion is connected to a hotspot created by my laptop, which hosts a local Flask server. 

 

When trying to POST the data from the companion to the Flask server, I get this error message

```

TypeError: Failed to fetch

```

 

The weird thing is that I can perform POST from a terminal I have installed in my phone, but the companion cannot perform the request itself. This is my code for fetch:

Spoiler
fetch('http://192.168.137.1:5000/measurements', {
method:'post',
headers: {
'Content-Type': 'application/json'
},
body:JSON.stringify(evt.data)
}).then(function(result) {
if (!result.ok) {
console.log('error');
return;
}
console.log('send ok');
}).catch(function (err){
console.log(err);
})

Do you have any idea what is going on?

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

While you're supposed to be able to use http for localhost, I think that's currently broken (it wants https in all cases(!)).

 

I think this is a known issue; a fix has been promised.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
3 REPLIES 3

Hi @OrestisZekai,

 

I think your thread may find a better home, rather than where it was originally posted in the general Ionic customer support forum. We have two dev forums, one for the SDK and one for the Web API. From your code snippet, it looks like the Web API forum may be the place for it, so I'll move it there. If I'm incorrect, just let me know here and I can place it in the SDK forum..

 

Work out...eat... sleep...repeat!
Dave | California

Best Answer
0 Votes

While you're supposed to be able to use http for localhost, I think that's currently broken (it wants https in all cases(!)).

 

I think this is a known issue; a fix has been promised.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Hello @Gondwana,

 

looks like you are correct. I set up the same Flask server in a secure webserver over https and I can finally get messages through. 

 

But I really hoped I would be able to do it all in my hotspot. Thanks anyway

Best Answer
0 Votes