Waiting for socket connection..

Started by cacack, February 02, 2016, 03:52:12 PM

cacack

I seem to be stuck.  I've got everything installed and it seems to be running however the web dashboard just shows the "Waiting for socket connection.." message.  In the output from gateway.js I see the initialization messages, and when I run another node configured with the demo sketch, I can see the messages received on the gateway.

This is a completely new installation (my first time) on a Raspberry PI 2 running a minimal Raspbian Netinstall.  I opted to use Nodesource's NodeJS 5.x packages.  I also skipped installing PHP since it appeared to only be used to validate the Nginx install.

I know nothing about NodeJS but I suspect this has something to do with the version I'm using and maybe with the version of the node packages (I'll post those versions next).  Any pointers as to where to look would be helpful.

Also probably worth noting that I'm actually installing everything by way of Ansible, which takes me from a clean Raspbian install to Moteino Gateway in 1 command.  For the curious, you can access the playbook here: https://github.com/cacack/ansible-moteino-gateway.

# lsb_release --all 
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 8.0 (jessie)
Release:        8.0
Codename:       jessie


# uname -a
Linux pi 3.18.0-trunk-rpi2 #1 SMP PREEMPT Debian 3.18.5-1~exp1+rpi19 (2015-08-08) armv7l GNU/Linux


# nginx -V       
nginx version: nginx/1.6.2
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt=-Wl,-z,relro --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_addition_module --with-http_dav_module --with-http_geoip_module --with-http_gzip_static_module --with-http_image_filter_module --with-http_spdy_module --with-http_sub_module --with-http_xslt_module --with-mail --with-mail_ssl_module --add-module=/build/nginx-Kaumns/nginx-1.6.2/debian/modules/nginx-auth-pam --add-module=/build/nginx-Kaumns/nginx-1.6.2/debian/modules/nginx-dav-ext-module --add-module=/build/nginx-Kaumns/nginx-1.6.2/debian/modules/nginx-echo --add-module=/build/nginx-Kaumns/nginx-1.6.2/debian/modules/nginx-upstream-fair --add-module=/build/nginx-Kaumns/nginx-1.6.2/debian/modules/ngx_http_substitutions_filter_module


# node --version
v5.5.0

cacack

Listing all of the package dependencies pushes the post past the 10,000 char limit...

$ npm list --depth=0
[email protected] /srv/moteino/gateway
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
+-- [email protected]
`-- [email protected]

bruster999

This probably isn't your issue but I was getting the same error right after installing Motion. The Motion app took over the default web browser port so the gateway couldn't grab a socket.
Bruster

Felix

cacack,
Not sure if you included all the steps I have at the Gateway page... but if you go from a vanilla raspbian through my walkthrough (installing everything manually with specific versions - this is important) you should get a clean webserver with websockets that will give you a page with no nodes but ready to accept data.
I will try to find some time to check out your ansible stuff, that could be useful.
Please share updates if you make any progress.

cacack

Quote from: bruster999 on February 02, 2016, 09:26:48 PM
This probably isn't your issue but I was getting the same error right after installing Motion. The Motion app took over the default web browser port so the gateway couldn't grab a socket.

Yes, I don't think so either.  I don't have anything else setup, just the basic Nginx, NodeJS and the gateway scripts.

Quote from: Felix on February 02, 2016, 11:41:12 PM
Not sure if you included all the steps I have at the Gateway page... but if you go from a vanilla raspbian through my walkthrough (installing everything manually with specific versions - this is important) you should get a clean webserver with websockets that will give you a page with no nodes but ready to accept data.

I modeled the Ansible playbook after your guide.  I will read through it again, as I could have missed something.  Won't be the first time  ;) .   The obvious (major) differences are I am using the Jessie release of Raspbian, the Jessie packaged Nginx 1.6.2, and the newer NodeJS 5.5.  I assume everyone else is following your guide exactly and using the Wheezy release with Nginx >= 1.8 and NodeJS 0.10.

Next will be digging into the gateway.js to understand how it works.

Felix

Raspbian vs Jessie - that could be it. Raspbian uses upstart, jessie I believe is systemd exclusively. I am relying on upstart to kick off the gateway.js app and keep it running.
If at all possible I would recommend using raspbian.

cacack

So I went back to the guide and setup the chat test node script.  I placed the chat.js in the same directory as the gateway.js so it should use the same node packages (/srv/moteino/gateway/).  I placed the chat.html in the same directory as the gateway html files (/srv/moteino/gateway/www/) and dropped in another nginx config to make it accessible.  When I access the web page I get this:



On the backend, the chat.js script only emits this everytime I refresh the web page:

AUTHORIZING CONNECTION FROM ::ffff:127.0.0.1:53034
AUTHORIZING CONNECTION FROM ::ffff:127.0.0.1:53039
AUTHORIZING CONNECTION FROM ::ffff:127.0.0.1:53043


I think this confirms it is something in my setup..

Felix

I'll say forget about the chat app, I should even remove that from the guide completely, just confuses people.
If the gateway app doesn't work there's other issues with the platform/setup.
If you are stuck with using jessie you will need another way of starting gateway.js, with systemd perhaps.

cacack

Quote from: Felix on February 03, 2016, 10:03:09 AM
Raspbian vs Jessie - that could be it. Raspbian uses upstart, jessie I believe is systemd exclusively. I am relying on upstart to kick off the gateway.js app and keep it running.
If at all possible I would recommend using raspbian.

I am using Raspbian, just the latest version.  Actually, I'm using their Netinstall version, which provides a minimal install (no X nor other unneeded things installed).  Jessie did switch to systemd but I have converted your upstart init script into a systemd service file:
[Unit]
Description=Moteino gateway.js home automation socket server
After=network.target

[Service]
Type=simple
User=moteino
ExecStart=/usr/bin/node /srv/moteino/gateway/gateway.js
Restart=on-abort
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=gateway

[Install]
WantedBy=multi-user.target


So systemd does keep the gateway.js script running.  I forgot to post the output of that eariler...  ::)
# systemctl status moteino-gateway
● moteino-gateway.service - Moteino gateway.js home automation socket server
   Loaded: loaded (/etc/systemd/system/moteino-gateway.service; enabled)
   Active: active (running) since Wed 2016-02-03 10:19:31 EST; 11s ago
 Main PID: 19168 (node)
   CGroup: /system.slice/moteino-gateway.service
           └─19168 /usr/bin/node /srv/moteino/gateway/gateway.js

Feb 03 10:19:31 pi systemd[1]: Started Moteino gateway.js home automation socket server.
Feb 03 10:19:37 pi gateway[19168]: [02-03-16_10:19:37.268] [LOG]   >:
Feb 03 10:19:37 pi gateway[19168]: [02-03-16_10:19:37.341] [LOG]   >: Listening at 915 Mhz...
Feb 03 10:19:37 pi gateway[19168]: [02-03-16_10:19:37.355] [LOG]   >: SPI Flash Init OK. Unique MAC = [D7:65:58:5:63:51:66:24:]
Feb 03 10:19:37 pi gateway[19168]: [02-03-16_10:19:37.357] [LOG]   >: RFM69_ATC Enabled (Auto Transmission Control)


And here is the processes...
# lsof -i tcp:8080
COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
node    19168  moteino   10u  IPv6 341901      0t0  TCP *:http-alt (LISTEN)
node    19168  moteino   14u  IPv6 345141      0t0  TCP localhost:http-alt->localhost:56061 (ESTABLISHED)
nginx   19202 www-data   17u  IPv4 344622      0t0  TCP localhost:56061->localhost:http-alt (ESTABLISHED)

# ps -fp 19168
UID        PID  PPID  C STIME TTY          TIME CMD
moteino  19168     1  1 10:19 ?        00:00:05 /usr/bin/node /srv/moteino/gateway/gateway.js


So this is why I'm thinking it is related to the version of node I'm using.  I was hoping the chat script would reveal something about my node setup, and allow me to avoid digging into the scripts..  ;D  But it sounds like node is really great for this kind of stuff so no time like now to start learning it.

jkarras

In your web browser attempt to connect to http://exampleserver.com:8080/socket.io and see what it returns. Based on your logs from systemd it looks like the gateway is starting correctly with 5.x

cacack

Sorry, life got in the way.  Accessing the Raspberry PI at http://<hostname>:8080/socket.io just results in a blank page.

Felix

Are you still trying to do the chat app?

cacack

@Felix, nope just trying what @jkarras suggested.  Unfortunately, I haven't had much time to devote to troubleshooting this.

jkarras

Sorry the URL to test should be http://<hostname>:8080/socket.io/ (notice the extra /). It should return something like.

{"code":0,"message":"Transport unknown"}

cacack

Quote from: jkarras on February 21, 2016, 11:36:01 PM
Sorry the URL to test should be http://<hostname>:8080/socket.io/ (notice the extra /). It should return something like.

{"code":0,"message":"Transport unknown"}


Yep that is the response I get.