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.

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.
    – PMF
    Jul 16 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
    – kevinlinxc
    Jul 16 at 6:22
  • 1
    You fail to describe what error you get and what doesn't work.
    – PMF
    Jul 16 at 6:26
  • It's in the title of the issue, and mentioned again in the issue
    – kevinlinxc
    Jul 17 at 0:50
2

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.

0
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.

0

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

1
  • it is what RaulG recommended some days ago. it would be nice to accept his answer and not to write a new one
    – Juraj
    Aug 12 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.