05-14-2020 12:53
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-14-2020 12:53
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Hello,
I am wondering if anyone can help me troubleshoot a simple app configuration.
I am trying to create a companion app to be the go-between between my fitbit (Versa2) and other apps I have created for my phone (Android). Currently, I am just designing for myself but if something works well I may put it out there.
Currently, I am just trying to get the Fetch API to work.
Here is the scenario.
I have this app that I have created that runs a Nano server on Localhost at http://localhost:8765.
currently, it just publishes a text string "This is my phone..." to the the server.
I would like my companion app to fetch that string and then eventually publish it to my watchface.
I know in the future, I should use json objects and more security, but for now, I want to troubleshoot the link between the two as simple as possible.
Here is my current companion app code.
console.log("Companion code started");
fetch('http://localhost:8765/txt.txt')
.then(response => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.catch(error => {
console.error('There has been a problem with your fetch operation:', error);
});
Currently, it builds and receives the communication from the watch and companion app to the console, but the fetch fails with the following error (regardless of whether the server is running). I can access the text file and see the string with my phone's browser. Yet, when I run the application, I get this error.
There has been a problem with your fetch operation: TypeError: Failed to fetch
Can anyone point me in the right direction to figure out how to get this working?
I am new to javascript, but am beginning to learn it.
Answered! Go to the Best Answer.

Accepted Solutions
05-14-2020 13:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


05-14-2020 13:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Wild guess: instead of 'localhost', try '127.0.0.1'.
Gondwana Software

05-14-2020 13:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post


05-14-2020 13:56
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Wild guess: instead of 'localhost', try '127.0.0.1'.
Gondwana Software

05-14-2020 14:03 - edited 05-14-2020 17:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post

05-14-2020 14:03 - edited 05-14-2020 17:27
- Mark as New
- Bookmark
- Subscribe
- Permalink
- Report this post
Thank you. I will. So my code looks correct on the companion app side of things?
I also found an old thread where someone (I think it was you) mentioned an app (Kws) that creates a web server. That would allow me to take one more thing out of the equation.
So, with KWS, and your suggested change, I think it worked. Thank you.

