Page 1 of 1

How to connect to remote web server from web page

Posted: Fri Mar 02, 2018 8:10 am
by dhodges47
Using node, I can connect to a phidget web server running on a raspberry pi from my laptop using this address: phid://raspberry.pi/5661.

However, when I try to connect using javascript using that address, I get an error that says "failed to connect to server".
I also tried ws://raspberrypi.local/phidgets, and I get an error: "Socket error (server unavailable)"

The Phidget control panel application does find the server and accesses the controllers on it. It just seems to be in javascript running in a web page that it can't find it.

The api documentation for javascript doesn't indicate how to open a remote server. So I am stumped. Is this even possible?

Re: How to connect to remote web server from web page

Posted: Sat Mar 03, 2018 9:23 am
by mariusz7
You are saying "Using node" - do you mean NodeJS? It IS JavaScript.
You are saying "However... try to connect using javascript" - what do you mean? is it JavaScript on web page?
From my experience using Phidgets JavaScript implementation, it is still in alfa or beta. When you use an example from Phidget API documentation, you will not get error message on server failure because of improper implementation of promise by Phidgets JavaScript API. (The promise is not rejected)
Sorry, I am not helpful, maybe try to use IP address instead of raspberry.pi
Use nmap utility to find IPs on your subnet, example:

Code: Select all

nmap -sn 192.168.1.0/24

Re: How to connect to remote web server from web page

Posted: Mon Mar 05, 2018 4:45 pm
by Patrick
You need to add the port to the hostname. ie:

ws://raspberrypi.local:8989/phidgets

Default port would be 8080 or 8989 for websocket (in browser).


Improvements are on the way to the js library and API documentation later this week.

-Patrick

Re: How to connect to remote web server from web page

Posted: Wed Mar 07, 2018 7:05 am
by dhodges47
Yes, I mean javascript on the web page. NodeJS/Javascript running by itself does connect, but Javascript in the browser doesn't. Yes, I have tried the IP address.
mariusz7 wrote:You are saying "Using node" - do you mean NodeJS? It IS JavaScript.
You are saying "However... try to connect using javascript" - what do you mean? is it JavaScript on web page?
From my experience using Phidgets JavaScript implementation, it is still in alfa or beta. When you use an example from Phidget API documentation, you will not get error message on server failure because of improper implementation of promise by Phidgets JavaScript API. (The promise is not rejected)
Sorry, I am not helpful, maybe try to use IP address instead of raspberry.pi
Use nmap utility to find IPs on your subnet, example:

Code: Select all

nmap -sn 192.168.1.0/24

Re: How to connect to remote web server from web page

Posted: Wed Mar 07, 2018 7:08 am
by dhodges47
Thanks Patrick. I'll try this. And I'll look for the improvements to the js library and documentation.
Patrick wrote:You need to add the port to the hostname. ie:

ws://raspberrypi.local:8989/phidgets

Default port would be 8080 or 8989 for websocket (in browser).


Improvements are on the way to the js library and API documentation later this week.

-Patrick