Http REST API not working with 0.25.2?

I have been enjoying very stable operation with the blynk app and my client hardware for quite a while. I now wish to do some integration using the REST API. I can read my project json data. I can get and set pins. The problem is these actions have no affect on the client hardware or on the blynk app. Do I need to upgrade the local server? Last time I upgraded it took quite a while to get back to a stable environment so I’m reluctant to do so without a known reason.

@guy. Post your sketch. Please make sure you paste it as shown “```cpp <paste> ```” for all of us to see readable, formatted code.

What do you mean by “can get and set pins?” Presume it is using HTTP. If you do so, the state will be propogated to both the device and the app. Is the token correct? You can verify that by calling for the project details using http://blynk-cloud.com/token/project.

Edit: just realised you are using a local server. Replace blynk-cloud.com with your local ip. What you are attempting is fairly staightforward. Can you check the server logs for what is happening when the HTTP api call is used to set a pin value?

Yes. We do not provide support for old versions.

Upgraded local server to v0.32.2
Upgraded app (Android) to v2.19.0

Tried to login: 'Connecting …"

/logs.blynk.log:

    21:51:29.367 INFO - Initializing gmail smtp mail transport. Username : example@gmail.com. SMTP host : smtp.gmail.com:587
    21:51:29.589 INFO - Didn't find Let's Encrypt certificates.
    21:51:29.590 INFO - Automatic certificate generation is turned ON.
    21:51:29.708 DEBUG- -Dio.netty.buffer.bytebuf.checkAccessible: true
    21:51:29.708 DEBUG- Loaded default ResourceLeakDetector: io.netty.util.ResourceLeakDetector@1d8ae8b
    21:51:29.925 DEBUG- hard.socket.idle.timeout = 15
    21:51:29.948 DEBUG- Created allowed user list : guy.mcswain@gmail.com
    21:51:29.972 DEBUG- app.socket.idle.timeout = 600
    21:51:30.343 DEBUG- Created allowed user list : guy.mcswain@gmail.com
    21:51:30.971 DEBUG- hard.socket.idle.timeout = 15
    21:51:31.067 DEBUG- -Dio.netty.processId: 15042 (auto-detected)
    21:51:31.088 DEBUG- -Djava.net.preferIPv4Stack: false
    21:51:31.088 DEBUG- -Djava.net.preferIPv6Addresses: false
    21:51:31.105 DEBUG- Loopback interface: lo (lo, 0:0:0:0:0:0:0:1%lo)
    21:51:31.109 DEBUG- /proc/sys/net/core/somaxconn: 128
    21:51:31.118 DEBUG- -Dio.netty.machineId: b8:27:eb:ff:fe:c2:52:f7 (auto-detected)
    21:51:31.353 INFO - Hardware plain tcp/ip server listening at 8442 port.
    21:51:31.363 INFO - Hardware SSL server listening at 8441 port.
    21:51:31.367 INFO - Application server listening at 8443 port.
    21:51:31.371 INFO - HTTP API and WebSockets server listening at 8080 port.
    21:51:31.376 INFO - HTTPS API, WebSockets and Admin page server listening at 9443 port.
    21:51:31.380 INFO - Mqtt hardware server listening at 8440 port.
    21:52:13.637 DEBUG- -Dio.netty.recycler.maxCapacityPerThread: 4096
    21:52:13.638 DEBUG- -Dio.netty.recycler.maxSharedCapacityFactor: 2
    21:52:13.638 DEBUG- -Dio.netty.recycler.linkCapacity: 16
    21:52:13.639 DEBUG- -Dio.netty.recycler.ratio: 8
    21:52:18.041 DEBUG- [id: 0x28251632, L:/10.0.0.15:8443 - R:/10.0.0.89:45765] HANDSHAKEN: TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
    21:52:19.024 ERROR- Wrong income message format.
    21:52:19.035 WARN - User not logged. /10.0.0.89:45765. Closing.
    21:52:19.086 DEBUG- Discarded inbound message PooledUnsafeDirectByteBuf(ridx: 0, widx: 84, cap: 84) that reached at the tail of the pipeline. Please check your pipeline configuration.

What do I need to do to overcome ‘ERROR- Wrong income message format.’?

Now that you have upgraded your Local Server and Android App… you need to change ports :stuck_out_tongue_winking_eye: Possibly even adjust your routers port forwarding…

Possibly also read this concerning the latest Library as well.

Basicly, keep up on all the Announcement topics… important changes happen as the development continues…

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…?