1

I have an Arduino Nano, and a local Java WebSocket server (ws://localhost:8888) run by a .jar file on my computer.

I'm wondering if it's possible to send data (text, numbers etc.) from the Arduino Nano to the WebSocket server via USB cable (USB-A to USB Mini, one that normally powers the Nano).

If so, what do I need to do it?

A quick Google for WebSocket Arduino libraries reveals:

Websockets and Arduino Websocket Fast, but looking at the examples, the former uses Ethernet.h and the latter uses Wifi.h, and I'm unsure if my board is compatible with that without other modules.

asked Jul 16, 2021 at 0:37
4
  • I don't know the possibilities you have in WebSocket, but the ordinary way to communicate with an Arduino (when it does not have a Wifi or Ethernet HAT) is via Serial. You can use basically any serial communication library to send strings from/to the Arduino. Commented Jul 16, 2021 at 5:59
  • I figured as much, I'm trying the SerialPort library and facing an issue, see here: github.com/serialport/node-serialport/issues/2297 Commented Jul 16, 2021 at 6:22
  • 1
    You fail to describe what error you get and what doesn't work. Commented Jul 16, 2021 at 6:26
  • It's in the title of the issue, and mentioned again in the issue Commented Jul 17, 2021 at 0:50

3 Answers 3

3

As @Majenko already said the ATmega328 uses a serial connection to communicate. Another chip on the board translates the serial data to USB-Format and the other way around. This enables your computer to interact with the main chip on the Nano (ATmega328). To solve your problem you might try using something like this simple serial-to-websocket node-server that listenes to data coming in from a serial port and sends it out over WebSocket.

answered Aug 9, 2021 at 6:33
0
1

I ended up using Python to bridge Serial to WebSocket. I wanted flexibility in sending from WebSocket back to Serial too, so I didn't try a prepackaged solution like https://github.com/RandomStudio/serial-to-websocket

answered Aug 11, 2021 at 22:40
1
  • it is what RaulG recommended some days ago. it would be nice to accept his answer and not to write a new one Commented Aug 12, 2021 at 6:38
0

No, you can't. The Arduino has a serial connection, not a network connection. If the Java program is of your own devising you would need to rewrite it to use serial instead of (or as well as) WebSockets. Either that or write a separate piece of software for your computer to go between the Arduino's serial connection and the WebSockets interface.

answered Jul 16, 2021 at 8:42

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.