Problems connecting (RPi) client to local server

Take a look at the required changes in the docs at http://docs.blynk.cc/#blynk-server-update-instruction-app-and-sketch-changes

The docs are unclear. How does that work with this? http://docs.blynk.cc/#hardware-set-ups-raspberry-pi

It’s a 2 step process, build the server then use the server.

I think you have done the first part, now do the second with the link I provided.

To someone new to the project and reading through the docs, there are lots of missing holes. What would be more helpful than RTFM, is an example of how the doc applies to what I’m trying to do. It’s not very clear beyond installing the software what to do next. What you linked to does not explain how to connect the RPi to the server with blynk-client?

This was the specific question you asked.

I gave you the precise details you need to do this.

90% of users are connecting to Blynk’s cloud server and therefore the documentation reflects this.
Have you used Blynk’s server?

No, I’d rather use a local server. I’m literally ~2 hours into trying to test out blynk. Installed the local server onto one RPi, trying to setup the second RPi as the client.

And no, from a newcomer perspective you didn’t answer the question. How does the link you gave me tell me how to connect to RPi. The link you shared has a section that talks about RPi and says:

Change your rasp PI javascript from
  var blynk = new Blynk.Blynk(AUTH, options = {connector : new Blynk.TcpClient()});
to
  var blynk = new Blynk.Blynk(AUTH, options= {addr:"xxx.xxx.xxx.xxx"});

How does that solve this step:

4. Run Blynk test script (put your auth token):
 blynk-client 715f8cafe95f4a91bae319d0376caa8c

With this results:

root@garagepi:~# blynk-client {my_token}
OnOff mode
Connecting to: blynk-cloud.com 8441
SSL authorization...
Connected
Could not login: INVALID_TOKEN
events.js:165
      throw err;
      ^

Error: Uncaught, unspecified "error" event. (INVALID_TOKEN)
    at Blynk.emit (events.js:163:17)
    at Blynk.onReceive (/usr/lib/node_modules/blynk-library/blynk.js:418:20)
    at .<anonymous> (/usr/lib/node_modules/blynk-library/blynk.js:548:50)
    at emitOne (events.js:96:13)
    at emit (events.js:188:7)
    at TLSSocket.<anonymous> (/usr/lib/node_modules/blynk-library/blynk-node.js:193:16)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at TLSSocket.Readable.push (_stream_readable.js:134:10)

Again what would be more helpful is an example of getting up and running.

That’s your prerogative but a cloud server would have had you up and running in 2 minutes rather than 2+ hours.

Any reason you are using 2 devices when 1 device can be client and server?

Have you bothered to change the “server” in the app?

your sketch is still trying to connect to the cloud so the problem is in your arduino sketch, not the local server.

@Costas provided a direct link to solve the issue.

Hint, change your Blynk.setup() server address.

@costas yes, in the app I’m logged into my own server. I have verified this by looking at the server logs and I can see my account was created and each time I log in. I can also go to my server admin page, and I can see that I’m the only user and there are sections like hardware, stats & config.

I’m using two RPi’s because I can. Figured if I’m going to build a network of RPi’s in my house to control things, I’d have one dedicated as a server. May upgrade to a small linux server later if I need better performance, but for now I have plenty of RPi’s lying around.

@Jamin what sketch? And I’m not using any arduino’s, only RPi’s. Where is Blynk.setup()? I’m just following directions here, step 4.
http://docs.blynk.cc/#hardware-set-ups-raspberry-pi

The link I gave you states:

Change your rasp PI javascript from
  var blynk = new Blynk.Blynk(AUTH, options = {connector : new Blynk.TcpClient()});
to
  var blynk = new Blynk.Blynk(AUTH, options= {addr:"xxx.xxx.xxx.xxx"});

I have zero experience with rPi’s but there must be somwhere that you have to put a binary sketch written in C++ right?

In Arduino the line you change is Blynk.begin() where you add a custom server address (or else it connects to the cloud).

So the issue is your sketch.

Edit: Costas’s post above mine also explains this (but in rPi syntax).

@Jamin Pi is normally javascript but Blynk do also have a C++ option.

The C++ (NOT javascript) format for a Pi client to access a local server is:

sudo ./blynk --server=xxx.xxx.xxx.xxx --token=xxxxxxxx --port=xxxx

I know it doesn’t look very C++ like but that’s because on the Pi the C++ code is compiled and it’s written to accept various parameters.

:innocent:

There is no blynk command. Tried that with the blank-client and got the same error. There are only two executables on the system with the name blynk

root@garagepi:/usr/bin# ls -lasF | grep blynk
    0 lrwxrwxrwx  1 root root          53 Mar  2 15:31 blynk-client -> ../lib/node_modules/blynk-library/bin/blynk-client.js*
    0 lrwxrwxrwx  1 root root          51 Mar  2 15:31 blynk-ctrl -> ../lib/node_modules/blynk-library/bin/blynk-ctrl.js*

Here’s the result from running blank-client:

root@garagepi:~# blynk-client --server=192.168.1.161 --token={my_token} --port=8441
OnOff mode
Connecting to: blynk-cloud.com 8441
SSL authorization...
Connected
Could not login: INVALID_TOKEN
events.js:165
      throw err;
      ^

Error: Uncaught, unspecified "error" event. (INVALID_TOKEN)
    at Blynk.emit (events.js:163:17)
    at Blynk.onReceive (/usr/lib/node_modules/blynk-library/blynk.js:418:20)
    at .<anonymous> (/usr/lib/node_modules/blynk-library/blynk.js:548:50)
    at emitOne (events.js:96:13)
    at emit (events.js:188:7)
    at TLSSocket.<anonymous> (/usr/lib/node_modules/blynk-library/blynk-node.js:193:16)
    at emitOne (events.js:96:13)
    at TLSSocket.emit (events.js:188:7)
    at readableAddChunk (_stream_readable.js:176:18)
    at TLSSocket.Readable.push (_stream_readable.js:134:10)

@mattboston I CLEARLY marked that syntax is for C++ not for javascript.

In the link YOU posted it clearly states:

5 You can write our own script based on examples

and:

Additional materials:
Instructables: Blynk on Javascript for Raspberry Pi, Intel Edison and others
Instructables: Use DHT11/DHT12 sensors with Raspberry Pi and Blynk

This is where you are now. So once you have created your javascript read my post that starts “The link I gave you states:”

So skip step 4 and go to 5!!! Not a single thing in any of the above conversations did anyone mention skipping step 4!!! I’m CLEARLY following the docs (as written) and trying to follow the steps by running blynk-client. If step 4 shouldn’t be done for a local server, it would have been nice to have that noted in the docs or you could have added that to all the other stuff you threw at me.

You are not actually following the docs.

As I said earlier 90% are not doing what you are doing and your link is to use the Pi as a client to the cloud server. Nowhere does it mention local servers in your link and that’s why I took the time to direct you to the correct section of the docs.

Of the 10% of Blynkers that are using a local server, some are on Pi’s and some on the many other servers that are available.
Of those running local server almost all of them used the cloud server first and I would say it should be 100%. Why try to run before you can even walk!

So for 99% to 100% of Blynkers then step 4 is absolutely VITAL and written exactly where it should be in that section of the docs…

P.S. support from me has now ended.

@mattboston

First… I understand and sympathize with you; The documentation and examples with referencing the RPi are currently limited (but getting better) and assume a much larger knowledge base with Java, Linux and probably even Python… or whatever the RPi natively works with.

However, @Costas has gone above and beyond in helping me in the past, just as he has with you here… but he DOES NOT WORK FOR BLYNK! He is a voluntary user, just helping other users like you and me, so badgering him about the documentation not being good enough is not fair to him.

There are TWO ways of running Blynk (Client) on RPI: The partially documented NODEJS (Java) and the less referenced wiringPi (C++ style)… and thus two completely differing methods of doing everything from linking to a specific server and writing scripts to control pins. There are more examples and such spread out on >github< , but personaly I find them random and confusing.

Since it appears you are using the NODEJS method, I have less experience with that (e.g. I gave up and went the wiringPi route :stuck_out_tongue_winking_eye: )… However, unlike with the C++ method, I seem to recall you determine the server location, not via the command line, but by editing a file (or your actual script) to make the server address changes as @Costas pointed out.

Give me a little while to dig up the details… they are in the forum here somewhere… and I will pass the directions on to you (if someone else doesn’t do so first).

@mattboston

For some reason links posted in these forums stopped defaulting in a green colour, and are now only highlighted green when moused over… so any links I post now are usually bracketed between > <.

OK, in the >github< link I referenced above, you can compare these two scripts - >client-tcp.js< & >client-tcp-local.js< to see an example (I think?) on how to edit your own script from the default cloud server to your Local server.

Basicly, what was shown here…

I hope that this will make it a bit clearer for you :slight_smile:

@mattboston Here is my post on this Node.js, Local Server and SSL issue… This should answer your questions as well.