Connecting Arduino SocketIoClient to NextJs api route

Viewed 36

I have a nextJs socket server in pages/api/socket hosted locally and my code is the same as what this article talks about.

My Arduino code is working in ESP8266 like this example from github

Basically, I emit a message event every 500 milliseconds from the Arduino loop and I want to console log that message when received by the nextJs api route but it does not worked for me.

I don't know the exact problem here, but when I tried this, a server using nodeJs and express and socket.io, it does work.

I am thinking that the problem is, in Arduino SocketIoClient, the websocket.begin("192.168.1.4", 3000) will connect to my http://localhost:3000 but my nextJs socket server lives in /api/socket so I added the url as the third parameter that looks like this, websocket.begin("192.168.1.4", 3000, "/api/socket"). But this does not work. NextJs cannot receive the connection from the Arduino.

Can anybody help or explain what is going on here?

0 Answers
Related