Links2004 / arduinoWebSockets

arduinoWebSockets
GNU Lesser General Public License v2.1
1.89k stars 556 forks source link

Problem connecting to app node js in Heroku #455

Closed OmarGC closed 5 years ago

OmarGC commented 5 years ago

I'm using the WebSocketClientSocketIO.ino example for es8266. Everything works fine on my localhost, but I want to connect to my application: https://smartliquid-api-sis.herokuapp.com/ (Which implements Socket.IO server) (the main view does not render anything yet)

I saw the following post but it does not work for me: https://github.com/Links2004/arduinoWebSockets/issues/189

Basically my problem is to connect with server https. Since everything works well in http (PUBLIC IP). Before Heroku on my server (from home) implement a certificate with the help of the certbot, I followed the videos in the list: https://www.youtube.com/watch?v=d4QDyHLHZ9c&t=677s

I can connect from web applications, and even from my android app but not with esp8266

I changed to heroku because I thought I had an error in the configuration of my nginx since I followed this other post: https://github.com/Links2004/arduinoWebSockets/issues/364 I copied the nginx configuration from the Links2004 comment on 7 Sep 2018, but it did not work for me. I can connect with browser but not with esp8266

PLEASE HELP

Links2004 commented 5 years ago

please enable debug in the IDE and post the log output here. if its a cert / ca problem may #451 helps you.

OmarGC commented 5 years ago

I understand that to activate the log output, we use the command: Serial.setDebugOutput (true); which I put right after Serial.begin (115200); The output of the log is:

07: 36: 43.516 -> .... scandone
07: 36: 46.324 -> state: 0 -> 2 (b0)
07: 36: 46.324 -> .state: 2 -> 3 (0)
07: 36: 46.324 -> state: 3 -> 5 (10)
07: 36: 46.324 -> add 0
07: 36: 46.324 -> aid 4
07: 36: 46.324 -> cnt
07: 36: 46,392 ->
07: 36: 46.392 -> connected with RED6654, channel 6
07: 36: 46.462 -> ip: 192.168.1.40, mask: 255.255.255.0, gw: 192.168.1.254
07: 36: 46.462 -> ip: 192.168.1.40, mask: 255.255.255.0, gw: 192.168.1.254
07: 36: 46,816 ->.
07: 36: 46.816 -> Connected to: RED2467
07: 36: 46.816 -> IP Address: 192.168.1.40
07: 36: 46,816 -> [WSc] Disconnected!
07: 36: 51.816 -> [WSc] Disconnected!
07: 36: 56.327 -> pm open, type: 2 0
07: 36: 56,823 -> [WSc] Disconnected!
07: 37: 01.837 -> [WSc] Disconnected!
07: 37: 06.845 -> [WSc] Disconnected!
07: 37: 11,821 -> [WSc] Disconnected!

This connecting with my heroku project: using the example: WebSocketClientSocketIO.ino Trying to enter with: socketIO.begin ("smartliquid-api-sis.herokuapp.com", 80); Same probe with port 443 and send me the same error.

Now regarding the post I had already tried with the command: openssl s_client -connect smartliquid.org:443 </ dev / null 2> / dev / null | openssl x509 -fingerprint -noout -in / dev / stdin But I did not succeed, I'm in a centos 7 distribution, the OS output is:

unable to load certificate 139634858268560: error: 0906D06C: PEM routines: PEM_read_bio: no start line: pem_lib.c: 707: Expecting: TRUSTED CERTIFICATE

Previously following that idea I found the following command: sudo openssl x509 -noout -in /etc/letsencrypt/archive/smartliquid.org/cert1.pem Which if I generated an equal output with --- BEGIN CERTIFICATE --- and decided to put that key in my NodeMCU (esp8266) but I had an error. Since I'm using the example WebSocketClientSocketIO.ino and when I created the instance I created it with the command: SocketIOclient socketIO; Then return to: WebSocketClient.ino, if you have the method: webSocket.beginSslWithCA (domain, port, url, CA). It still does not connect to the home server. and activating the log sends me these lines:

08:16:38.174 -> 
08:16:38.174 -> -----Configuracion------
08:16:38.174 -> Conectando aRED2467
08:16:38.257 -> scandone
08:16:38.257 -> ap_loss
08:16:38.257 -> reconnect
08:16:38.257 -> scandone
08:16:38.726 -> .....scandone
08:16:42.039 -> state: 0 -> 2 (b0)
08:16:42.039 -> .state: 2 -> 3 (0)
08:16:42.079 -> state: 3 -> 5 (10)
08:16:42.079 -> add 0
08:16:42.079 -> aid 4
08:16:42.079 -> cnt 
08:16:42.149 -> 
08:16:42.149 -> connected with RED2467, channel 6
08:16:42.253 -> ip:192.168.1.40,mask:255.255.255.0,gw:192.168.1.254
08:16:42.253 -> ip:192.168.1.40,mask:255.255.255.0,gw:192.168.1.254
08:16:42.537 -> .
08:16:42.537 -> Conectado a: RED2467
08:16:42.537 -> Direccion IP: 192.168.1.40
08:16:42.537 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.537 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.537 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.570 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.570 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.570 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.570 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.570 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.570 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.570 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:42.570 -> Error: maximum number of CA certs added (10) - change of compile-time configuration required
08:16:42.606 -> ["test",{"cve":"Esp: On","nombre":"cisterna1","datos":40,"cveSistem":"qwertyuiuytrdfg"}]
08:16:42.606 -> [WSc] Disconnected!
08:16:43.079 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.079 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.079 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.079 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.079 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.113 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.113 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.113 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.113 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.113 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.113 -> Error: maximum number of CA certs added (10) - change of compile-time configuration required
08:16:43.113 -> [WSc] Disconnected!
08:16:43.618 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.618 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.618 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.618 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.618 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.653 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.653 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.653 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.653 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.653 -> Error: Invalid X509 ASN.1 file (X509 not ok)
08:16:43.653 -> Error: maximum number of CA certs added (10) - change of compile-time configuration required

In this sketch use to start connection use: webSocket.beginSslWithCA("smartliquid.org", 443, "/socket.io/?EIO=3", CA, "");

THANK YOU FOR ANSWERING, DISCUSS THE DISGRACES BUT I DO NOT KNOW WHAT HAPPENS AS I CAN NOT ACCESS FROM MY NODEMCU (esp8266) or on my home server: smartliquid.org nor ami heroku project: smartliquid-api-sis.herokuapp.com

It should be noted that probe the compatibility with socket with a chrome add-on: Hermes WebSocket Client.

Links2004 commented 5 years ago

Hi,

there a menu option in the IDE to enable SSL debug output. https://arduino-esp8266.readthedocs.io/en/latest/Troubleshooting/debugging.html if you configure the debug serial Interface the Websocket debug will be enabled too.

Serial.setDebugOutput will only enable the OS based debug output, by using the menu (compiler defines) you will get much more info.

OmarGC commented 5 years ago

Thanks for answering. This is the output now:

15:54:40.102 -> 
15:54:40.102 -> SDK:2.2.1(cfd48f3)/Core:2.4.2/lwIP:2.0.3(STABLE-2_0_3_RELEASE/glue:arduino-2.4.1-13-g163bb82)/BearSSL:6d1cefc
15:54:40.137 -> wifi evt: 2
15:54:40.137 -> 
15:54:40.137 -> -----Configuracion De Omar------
15:54:40.137 -> Conectando a INFINITUM2467
15:54:40.137 -> sta config unchangedscandone
15:54:40.239 -> scandone
15:54:40.239 -> state: 0 -> 2 (b0)
15:54:40.239 -> state: 2 -> 3 (0)
15:54:40.239 -> state: 3 -> 5 (10)
15:54:40.239 -> add 0
15:54:40.239 -> aid 8
15:54:40.239 -> cnt 
15:54:40.342 -> 
15:54:40.342 -> connected with INFINITUM2467, channel 6
15:54:40.342 -> ip:192.168.1.80,mask:255.255.255.0,gw:192.168.1.254
15:54:40.342 -> ip:192.168.1.80,mask:255.255.255.0,gw:192.168.1.254
15:54:40.342 -> wifi evt: 0
15:54:40.342 -> wifi evt: 3
15:54:40.613 -> .
15:54:40.613 -> Conectado a: INFINITUM2467
15:54:40.613 -> Direccion IP: 192.168.1.80
15:54:40.613 -> [WS-Client] connect ws...
15:54:40.647 -> [hostByName] request IP for: ws-arduino.herokuapp.com
15:54:40.647 -> [hostByName] Host: ws-arduino.herokuapp.com lookup error: -6!
15:54:40.647 -> [WS-Client] connection to ws-arduino.herokuapp.com:80 Failed
15:54:40.647 -> [WS-Client] client disconnected.
15:54:40.647 -> [WSc] Desconectado!
15:54:45.640 -> [WS-Client] connect ws...
15:54:45.640 -> [hostByName] request IP for: ws-arduino.herokuapp.com
15:54:45.640 -> [hostByName] Host: ws-arduino.herokuapp.com lookup error: -6!
15:54:45.640 -> [WS-Client] connection to ws-arduino.herokuapp.com:80 Failed
15:54:45.640 -> [WS-Client] client disconnected.
15:54:45.675 -> [WSc] Desconectado!
15:54:50.268 -> pm open,type:2 0
15:54:50.645 -> [WS-Client] connect ws...
15:54:50.645 -> [hostByName] request IP for: ws-arduino.herokuapp.com
15:54:50.645 -> [hostByName] Host: ws-arduino.herokuapp.com lookup error: -6!
15:54:50.645 -> [WS-Client] connection to ws-arduino.herokuapp.com:80 Failed
15:54:50.645 -> [WS-Client] client disconnected.
15:54:50.678 -> [WSc] Desconectado!
15:54:55.637 -> [WS-Client] connect ws...
15:54:55.637 -> [hostByName] request IP for: ws-arduino.herokuapp.com
15:54:55.671 -> [hostByName] Host: ws-arduino.herokuapp.com lookup error: -6!
15:54:55.671 -> [WS-Client] connection to ws-arduino.herokuapp.com:80 Failed
15:54:55.671 -> [WS-Client] client disconnected.
15:54:55.671 -> [WSc] Desconectado!
Links2004 commented 5 years ago

Hi,

15:54:45.640 -> [hostByName] request IP for: ws-arduino.herokuapp.com
15:54:45.640 -> [hostByName] Host: ws-arduino.herokuapp.com lookup error: -6!

this too line show that you have a DNS problem in your network configuration. the ESP is not able to lookup the domain. as result the connection is not possible.

OmarGC commented 5 years ago

Surprising! ok comment the configuration line for static ip and it worked correctly! Thank you! I will try with the configuration of my localhost. Thank you!