Http REST API not working with 0.25.2?

I’m using vshymanskyy/blynk-library-js v0.47 which is the latest.

The link you gave above is long and difficult to comprehend but the gist seems to be about default ports. In my log that I provided you will see the assigned ports. These are configured from my ‘server.properties’ file. I’m still not sure what I need to change.

Fyi, I’m only using my local LAN (WiFi) to access blynk hardware and server from my smart phone, so no router port forwarding should be required.

Thanks for any help you can provide.

It is a bit of a read… but most of the real detail is in the first posts. You might get finished long before I have time to explain it as I am busy on my end… but I have a minute or two, so here…

First thing… change you port in your JS Client script to 8080

If you are also running your LS on the same RPi, then you may need to run this command on it (I think it is just a run and forget thing)…

NOTE: if you have local server and uploaded new firmware, you need to add addtional port forwarding:

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

Script changed to access blynk LS at port 8080. Blynk log:

23:00:24.834 DEBUG- Hardware not logged. /127.0.0.1:33612. Closing.
23:00:34.846 DEBUG- Hardware not logged. /127.0.0.1:33616. Closing.
23:00:44.857 DEBUG- Hardware not logged. /127.0.0.1:33620. Closing.

Client log:

pi@blynkie:~ $ sudo journalctl --unit lights --no-pager | tail -30
Mar 05 23:01:04 blynkie node[31139]: 2018.03.05 11:01 pm - error: Lights received blynk error! ECONNRESET
Mar 05 23:01:04 blynkie node[31139]: Error ECONNRESET
Mar 05 23:01:14 blynkie node[31139]: Connecting to: localhost 8080
Mar 05 23:01:14 blynkie node[31139]: SSL authorization…
Mar 05 23:01:14 blynkie node[31139]: 2018.03.05 11:01 pm - error: Lights received blynk error! ECONNRESET
Mar 05 23:01:14 blynkie node[31139]: Error ECONNRESET

I presume I’m getting ECONNRESET because my server.properties have:

INFO - Hardware SSL server listening at 8441 port.

Also, does server port 8080 now handle SSL/TLS handshake?

Let’s go back to the original error. Do the port settings have anything to do with this?

I appreciate you need to ask questions, but I have already pointed put the general issue (you need to upgrade to keep working with Blynk, and when you upgrade you need to keep abreast of required changes).

So anyhow… since I do not remember all the details, I need to look up each answer I give you :slight_smile: … so you might as well read and search for them yourself :wink:

e.g. Searching this forum for your error found this…

Ah, this link helps. We’re making progress so please bear with me.

Before posting the error, I had changed the Application server listening at 8443 port to port 9443 but got a conflict with HTTPS API, WebSockets and Admin page server listening at 9443 port.

So what port should I assign the https api and admin page server?

Btw, I thought the server.properties were supposed to override these defaults. Is that no longer the case?

App should connect to 9443 port.
Hardware should connect to 8080 port.

If you have any server.properties - please remove. So it doesn’t overlap with default.

That’s it.

I have commented out all lines affecting ports in server.properties:

hardware mqtt port
hardware.mqtt.port=8440

hardware ssl port
hardware.ssl.port=8441

hardware plain tcp/ip port
hardware.default.port=8442

#http and web sockets port
#http.port=8080

#https and web sockets port
#https.port=9443

#application ssl port
app.ssl.port=8443

Restarted the blynk local server:

pi@blynkie:~ $ cat /logs/blynk.log | tail -30
07:47:06.162 DEBUG- -Dio.netty.allocator.type: pooled
07:47:06.162 DEBUG- -Dio.netty.threadLocalDirectBufferSize: 0
07:47:06.163 DEBUG- -Dio.netty.maxThreadLocalCharBufferSize: 16384
07:47:06.406 INFO - Initializing gmail smtp mail transport. Username : example@gmail.com. SMTP host : smtp.gmail.com:587
07:47:06.626 INFO - Didn’t find Let’s Encrypt certificates.
07:47:06.626 INFO - Automatic certificate generation is turned ON.
07:47:06.743 DEBUG- -Dio.netty.buffer.bytebuf.checkAccessible: true
07:47:06.744 DEBUG- Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@1d8ae8b
07:47:06.961 DEBUG- hard.socket.idle.timeout = 15
07:47:06.983 DEBUG- Created allowed user list : guy.mcswain@gmail.com
07:47:07.008 DEBUG- app.socket.idle.timeout = 600
07:47:07.384 DEBUG- Created allowed user list : guy.mcswain@gmail.com
07:47:08.032 DEBUG- hard.socket.idle.timeout = 15
07:47:08.128 DEBUG- -Dio.netty.processId: 5230 (auto-detected)
07:47:08.149 DEBUG- -Djava.net.preferIPv4Stack: false
07:47:08.149 DEBUG- -Djava.net.preferIPv6Addresses: false
07:47:08.166 DEBUG- Loopback interface: lo (lo, 0:0:0:0:0:0:0:1%lo)
07:47:08.171 DEBUG- /proc/sys/net/core/somaxconn: 128
07:47:08.188 DEBUG- -Dio.netty.machineId: b8:27:eb:ff:fe:c2:52:f7 (auto-detected)
07:47:08.425 INFO - Hardware plain tcp/ip server listening at 8442 port.
07:47:08.433 INFO - Hardware SSL server listening at 8441 port.
07:47:08.437 INFO - Application server listening at 8443 port.
07:47:08.441 INFO - HTTP API and WebSockets server listening at 8080 port.
07:47:08.444 INFO - HTTPS API, WebSockets and Admin page server listening at 9443 port.
07:47:08.448 INFO - Mqtt hardware server listening at 8440 port.
07:47:18.328 DEBUG- -Dio.netty.recycler.maxCapacityPerThread: 4096
07:47:18.329 DEBUG- -Dio.netty.recycler.maxSharedCapacityFactor: 2
07:47:18.330 DEBUG- -Dio.netty.recycler.linkCapacity: 16
07:47:18.331 DEBUG- -Dio.netty.recycler.ratio: 8
07:47:18.459 DEBUG- Hardware not logged. /127.0.0.1:35068. Closing.

Hardware can’t connect even though I’ve changed the port to 8080 on the client.
Also, logs show that application server is still listening at port 8443.
No joy!

It can. But you don’t login it with auth token according to the error message.

From client log it appears it is in SSL negotiation when an exception is thrown:

pi@blynkie:~ $ sudo journalctl --unit lights --no-pager | tail -30
Mar 06 08:22:50 blynkie node[620]: SSL authorization…
Mar 06 08:22:50 blynkie node[620]: 2018.03.06 8:22 am - error: Lights received blynk error! ECONNRESET
Mar 06 08:22:50 blynkie node[620]: Error ECONNRESET
Mar 06 08:23:00 blynkie node[620]: Connecting to: localhost 8080
Mar 06 08:23:00 blynkie node[620]: SSL authorization…

According to blynk-node.js the next log entry should be either ‘SSL not authorized’ or ‘Connected’. I don’t believe the blynk auth token has yet been passed. Do I have this right?

Did you generate this Auth while App was logged into this particular server? If not, then that is your issue.

@Gunner, my client connects when I use port 8441 so it’s not the blynk auth. It is turning the lights on/off automatically as designed without the app connected. Now I just need to get the blynk app to connect without having to manually rebuild the dashboard.

I am confused…

Blynk consists of a trio of components, the App, Server & Device (sketch). The API communicates directly to the server, but assumes it is using the proper auth from the App

Your App needs to log into whatever server the device is connecting to… Once logged in, the App requests the Auth, the Server generates and emails the Auth and you insert it into the device’s Sketch… but if you change any one of those three components to another one from another trio then not all will work.

So… what did you have and what did you change…?

I upgraded the local server and the app to keep these in sync but I left my client unchanged. I copied over the mymail@gmail.com.Blynk.user to the new server folder. That’s it. (Except for my diversion with the recommended change for port 8080. Now reverted to 8441.)

Did you upgrade (AKA stop server download new file, change startup method to recognise new file name and restart server?) If so, why do you need to copy anything from “Old” server to 'New" server? There should bo no folder changes or anything like that, just simple stop, new file, restart.

Or did you create a “New” server on the same platform and transfer stuff over… if so that might just cause enough confusion to explain some the the issues.

I’m wrong! Re checked the log … showing invalid token in DB. Sorry for misleading you.

My client is just running autonomously.

However, I don’t get the ECONNRESET exception when using port 8441.

Well, I am probably more lost then you are :stuck_out_tongue: Sorry, but I will need to leave this for someone with more API experience :slight_smile:

Resolved. I’ve been away for the last 10 days and see that the local server revision has bumped from 0.32.2 to 0.33.2. I upgraded to the latest and I can now connect both the app and the hw client. (Also had to upgrade app to 2.19.2)

I’m back to where I started with a working configuration. I have not yet tried the REST API but if I have issues I will open a new thread. Please mark this thread as ‘resolved.’