• Hi there.

    I've been working on a project that uses the ws module (as shown here) to connect to a node process running a WebSocket server.

    When running the server locally and connecting the Espruino to the same WiFi, the board is able to open a socket and communicate with the host given the ip address (ie 192.168.x.yy).

    However, when running the server on an EC2 on AWS the Espruino is unable to connect to the host (ie ec2-xx-yyy-zzz-v.compute-1.amazonaws.com­). The ws.on('close', () => { ... }); event is immediately fired after opening the socket. On the server side I see no indication of a connection attempt.

    The host is running on port 80 and I have opened that port. I can connect a node ws client to the host on the EC2, but the Espruino client refuses to connect.

    Any ideas on what might be preventing the connection? I found one Stack Overflow post that seems to be describing the same issue, but does not have a resolution and is quite old at this point.

    Any help you all could provide will be much appreciated.

    Thanks!

  • Hi! I noticed you closed this post - was that because you found an answer?

    I seem to recall that Amazon EC2 uses secure connections - it may be that while you can connect to port 80, it actually silently redirects to port 443 for HTTPS? Espruino wouldn't handle any redirections so that might be the issue?

    On the Pico and WiFi boards you can use HTTPS, but quite a lot of RAM is required for it.

  • Hi Gordon,

    Thanks for checking in. I closed the post as I was able to make the connection work.

    What I found was that I was trying to connect to http://ec2-xx-yyy-zzz-v.compute-1.amazon­aws.com from the Espruino board, and that did not work (although that is the host I used for the node ws client without an issue).

    By removing the http:// I was able to connect the Espruino to the hosted socket. I really thought I had tried that the other day to no avail, but I suppose something must have been different.

    @MaBe sent me a message letting me know that there is a 32 char limit for the internal hostname, so I'm a bit confused as my hostname is 40 characters. Nevertheless, it seems to be connecting and sending data ok, but will intermittently disconnect.

    A stranger issue that I am having is when connecting locally. When testing, I host the ws server on my local machine and connect the Espruino to the same WiFi. After finding the ip of my computer that is running the server, I use that on the Espruino to connect. However, I only seem to be able to connect 1/10 times.

    Most of the time it simply fails to connect, and then randomly without changing anything it will work. Any ideas what that might be about?

  • Which board are you using?

    The 32 char limit is news to me @MaBe - is it something specific to ESP8266?

    I'm afraid I have no idea about the connection issues - without any code it's pretty much impossible to diagnose, and I know I've tried ws on Espruino WiFi in the past connecting to a local server and it's been totally fine.

  • Yes, that was news for me too. Added a sdk non os 2v2

    3.5.30. wifi_station_set_hostname
    Function Set ESP8266 Station DHCP hostname.
    Prototype bool wifi_station_set_hostname(char* hostname)
    Parameter char* hostname: hostname, max length: 32 characters.
    Return true: Success false: Failure

    Edit: https://github.com/espruino/EspruinoBuil­dTools/blob/master/esp8266/2c-esp8266_no­n_os_sdk_api_reference_en_2v2.pdf

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Trouble connecting Espruino ws module to domain hosted on EC2

Posted by Avatar for RobertMcReed @RobertMcReed

Actions