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

The fetch() doesn't work!!!

ANSWERED

Hello,

 

I wanted to use the Fetch API to transfer the accelerameter data to an android phone by using this code

https://github.com/gondwanasoft/fitbit-accel-fetcher

However, It doesn't run on my computer and based on the error it says fetch() couldn't send request to server. I used a local host and this IP 127.0.0.1 does anyone know how can I fix that?

 

Best, 

Best Answer
0 Votes
1 BEST ANSWER

Accepted Solutions

Heaps more. It's described in the readme. Without a server, the URL won't know what to do with the data.

Peter McLennan
Gondwana Software

View best answer in original post

Best Answer
0 Votes
20 REPLIES 20

127.0.0.1 will be your phone, not your computer. What server are you running on your phone?

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I connected both laptop and phone to the personal wifi and just built the application on my watch and companion on phone and didn't run any server on my phone. Do I need to do anything else in other to be able to send data to the mentioned URL?

Best Answer
0 Votes

Heaps more. It's described in the readme. Without a server, the URL won't know what to do with the data.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thank you for the help. I'll check it out again. Can I directly send the data of accelerometer to a web service such as drop box? Is it just as easy as sending it to the phone? 

Best Answer
0 Votes

I think drop box (etc) will require a very specific protocol, including heaps of authentication. I think there is a web site that can catch and save simple files sent to it, but I don't know its URL.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

I checked the readme, and I don't know if I run the server correctly or nor, I used Fitbit studio and run the application on the phone and used the android studio and run the android-fitbit-fetcher on the same phone. while both are running on my phone when I send the transfer data button it gives me the error that I mentioned. 

Best Answer
0 Votes

Exactly what error message was displayed, and where was it displayed? What URL did you use for fetch?

Unfortunately there are about a billion things that can go wrong.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

The error is "server not found on 1" and the URL that I used is URL = http://127.0.0.1:3000

Best Answer
0 Votes

I don't think my code is capable of displaying that, so it may be coming directly from the API. The 'on 1' is strange; maybe check IP formatting.

 

It would still be helpful to know where you see this message.

 

There may be other clues in the console output.

 

I assume the Android app was running on your phone.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Amend that: I can see where the message is coming from...

Peter McLennan
Gondwana Software
Best Answer
0 Votes

The error massage is shown on watch, and the android app was running on the phone but the number of received file is always zero. 

Transfer queued. Here is also the copied log that I can see in the Fitbit studio. 
 
receiveFilesFromWatch()
Received file 1
Got file 1; contents: 240 bytes = 120 elements = 30 records; timestampPrev=-1 timestampMSB=0
sendToServer() fileName=1 asJSON=undefined
sendToServer() sent 1
sendToServer(): fileName=1 fetch error: TypeError: Failed to fetch. Ensure server is running.
receiveFilesFromCompanion(): received response-1662155022006
watch received response status code 2 for file 1
Best Answer
0 Votes

Ah. The key thing there is the TypeError. That's coming from the API and simply means that the fetch() didn't work. It can happen from incorrect IP, including incorrect security.

Unfortunately, Fitbit broke fetch() to http recently (see here). If they haven't fixed it yet, that's the error you'd get. I don't know if they've fixed it.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thank you for your help. It means that I need to use https to solve the issue? do I need to address the same URL but type https instead pf http?

Best Answer
0 Votes

That would only work if there's a non-self-signed certificate installed on the server (Android app). I'd have no idea how to do that. It's probably possible but difficult.

It used to be possible to host a server for free (with https included) on heroku, but I think they've got rid of the free tier. There may be other equivalent services. To use them, you'd need a server written in something like php or node.js.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

For what it's worth, I just fired up fitbit-accel-fetcher and android-fitbit-fetcher, and it worked fine. This indicates that Fitbit has fixed the issue that was preventing the use of local unsecured connections.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thank you for the update. I fired up both applications again but I received the same error on watch "Server not found on 1" and status 1 is server didn't respond to fetch() request. Do I need to update the Fitbit software to fix it? In order to clarify what I did, I kept the android-fitbit-fetcher open and the run the Fitbit-accel-fetcher and started to record data and then pushed the transfer button and then the error was displayed. On phone the "GET DATA" button is always disable since the number of received files is zero. 

 

Regards, 

Best Answer
0 Votes

I think the key message that you reported before was 'TypeError: Failed to fetch'. As I understand it, that means that the companion is not even able to send the fetch request, so nothing gets as far as the server.

My Fitbit mobile app is version 3.66 (36669011). Make sure the IP address that fetch is using is allowed, and that you've given the app internet permission.

Peter McLennan
Gondwana Software
Best Answer
0 Votes

Thank you again for your help. I am reading the code to better understand what happened. Could you please let me know what is the goal of the function simAccelTick(), you commented fake data for it. Since we read accelerometer data what is the need of this function!!!

Best Answer
0 Votes

From memory, simAccelTick should only be called if the app is running in the Fitbit simulator (investigate the variable isSim). When used on a real watch, simAccelTick won't be used; actual sensor data will be used instead. In a production build, sim-specific code should be removed.

Peter McLennan
Gondwana Software
Best Answer
0 Votes