[SOLVED] Problem connecting to local server from javascript

Hi,

I made my first blynk project and made a javascript on my Raspberry Pi to control it.
It all works fine, Now I tried to run a local blynk server, I followed the installation instructions from this site. I can connect with the app, but from my script on the raspberry I get an error.

First, in the javascript I changed:
var blynk = new Blynk.Blynk(AUTH);
into:
var blynk = new Blynk.Blynk(AUTH, options= {addr:"192.168.10.10"});

with the address of my local blynk server (server runs with default settings)

If I run my javascript, the output is as follows:

Connecting to SSL: 192.168.10.10 8441 events.js:87 throw Error('Uncaught, unspecified "error" event.'); ^ Error: Uncaught, unspecified "error" event. at Error (native) at emit (events.js:87:13) at Blynk.error (/usr/local/lib/node_modules/blynk-library/blynk.js:571:8) at null.<anonymous> (/usr/local/lib/node_modules/blynk-library/blynk.js:534:48) at emit (events.js:107:17) at TLSSocket.<anonymous> (/usr/local/lib/node_modules/blynk-library/blynk-node.js:180:14) at TLSSocket.emit (events.js:129:20) at net.js:451:14 at process._tickCallback (node.js:355:11)

What am I doing wrong ?

The script runs on Raspberry Pi with Raspbian OS and JAva 8 installed.

All help is much appreciated.

I ran into the same problem today. Everything worked, until I tried setting up a local server on my Raspberry Pi. Connecting to the server from the app works.

NodeJS Stacktrace:

OnOff mode Connecting to SSL: 192.168.1.110 8441 events.js:87 throw Error('Uncaught, unspecified "error" event.'); ^ Error: Uncaught, unspecified "error" event. at Error (native) at emit (events.js:87:13) at Blynk.error (/usr/local/lib/node_modules/blynk-library/blynk.js:569:8) at null.<anonymous> (/usr/local/lib/node_modules/blynk-library/blynk.js:532:48) at emit (events.js:107:17) at TLSSocket.<anonymous> (/usr/local/lib/node_modules/blynk-library/blynk-node.js:180:14) at TLSSocket.emit (events.js:129:20) at TLSSocket.<anonymous> (_tls_wrap.js:942:18) at TLSSocket.emit (events.js:104:17) at TLSSocket._finishInit (_tls_wrap.js:460:8)

Server runs on Raspberry Pi / Raspbian Wheezy / Java 8, Server version 0.12.4
Client runs on Rapsberry Pi / Raspbian Wheezy / Node version 0.12.6-1, blynk library version 0.0.28 (set up like described under http://docs.blynk.cc/#hardware-set-ups-raspberry-pi)

What does blynk.log says of your local server?

Nothing. It shows that i logged in from the app, but no track of any javascript connection attempt.

Thats all the logs after performing the following steps

  • rebooted blynk server
  • connected from app to confirm that the server is ready
  • started the node script and ran into the same error as above

20:07:55.315 INFO - Using data dir ‘Blynk’
20:07:57.753 INFO - Initializing mail transport. Username : xxxx. SMTP host : xxxx:587
20:07:59.035 INFO - Plain tcp/ip hardware server port 8442.
20:07:59.043 INFO - Enabling SSL for hardware.
20:07:59.051 WARN - ATTENTION. Certificate /home/pi and key /home/pi paths not valid. Using embedded certs. This is not secure. Please replace it with your own certs.
20:08:02.041 INFO - SSL hardware port 8441.
20:08:02.066 INFO - Enabling SSL for application.
20:08:02.071 WARN - ATTENTION. Server certificate paths cert : ‘/home/pi’, key : ‘/home/pi’ - not valid. Using embedded server certs and one way ssl. This is not secure. Please replace it with your $
20:08:04.321 INFO - Application server port 8443.
20:08:04.445 INFO - Enabling HTTP API.
20:08:04.447 INFO - HTTP API port 8080.
20:08:04.466 INFO - Enabling HTTPS API.
20:08:04.468 WARN - ATTENTION. Certificate /home/pi and key /home/pi paths not valid. Using embedded certs. This is not secure. Please replace it with your own certs.
20:08:07.418 INFO - HTTPS API port 9443.
20:08:07.478 INFO - Enabling HTTPS for admin UI.
20:08:07.479 WARN - ATTENTION. Certificate /home/pi and key /home/pi paths not valid. Using embedded certs. This is not secure. Please replace it with your own certs.
20:08:08.771 INFO - HTTPS admin UI port 7443.
20:08:08.775 INFO - Enabling Web Sockets.
20:08:08.777 INFO - Web Sockets port 8082.
20:08:08.781 INFO - Enabling Web SSL Sockets.
20:08:08.782 WARN - ATTENTION. Certificate /home/pi and key /home/pi paths not valid. Using embedded certs. This is not secure. Please replace it with your own certs.
20:08:12.138 INFO - Web SSL Sockets port 8081.
20:08:48.175 INFO - xxxx app joined.

I use the following line of code to attempt the connection:

var blynk = new Blynk.Blynk(process.argv[2], options= {addr:"192.168.1.110"});

process.argv[2] contains the auth code.

Do you use LED widgets in your code? Please show it.

It’s mainly demo code plus two virtual pins triggered with buttons.

#!/usr/bin/env node

var Blynk = require("/usr/local/lib/node_modules/blynk-library");

if (!process.argv[2]) {
  console.log("Please specify auth token.");
  process.exit(1);
}

var blynk = new Blynk.Blynk(process.argv[2], options= {addr:"192.168.1.110"});
var v0 = new blynk.VirtualPin(0);
var v1 = new blynk.VirtualPin(1);

blynk.on('connect', function() {
  console.log("Blynk ready.");
});

v0.on('write', function(param) {
  console.log('V0 ',param[0]);
});

v1.on('write', function(param) {
  console.log('V1 ',param[0]);
});

When I first tried it with the blync cloud, I had the pins start an external script whenever they got a signal - that worked fine. I removed that code now and went back to printfs in order to be able to test the “plain” blynk functionality and make sure that no external dependency is wreaking havoc, but the problem is still there.

Well, if you have no errors in blynk.log - most probably problem is in your firewall, ip tables, blocked ports on rasp pi.

I had the same problem, when I replaced my javascript with a C program, the example code in the library, then it all worked fine. So I don’t think the problem is with the server, firewall or something like that.

No firewall configured on either of the Pis. Basically two plain raspbian setups with basic network configuration and some scripts that do some GPIO stuff.

I’ll try a simple C example now to see if that helps.

pi@raspberrypi ~/rclinux $ sudo ./blynk --token=xxxx --server=192.168.1.110
[1] Blynk v0.3.3-beta
[5001] Connecting to 192.168.1.110:8442
[5498] Ready (ping: 15ms).

Same PIs, no configuration changed etc. I’m voting for “no firewall issue” :wink:

Hi all,
you can use TCP connection example for now (examples/nodejs/client-tcp-local.js).
I will look into SSL connection issue.

Just wanted to confirm that the TCP connection example works. This will work for now, thanks for the answer!

1 Like

Hi,
Sorry to comeback on this subject, but I’ve got the same issue than cy5y and I’m beginer in programing …
So, how do you “use TCP connection example” please ?
Thank you for your help.

Please update your library from npm and tell me if it works. Thanks!

Great ! it works very well since I’ve updated the library :

sudo npm install -g blynk-library

Thanks :wink: