Skip to content

Ascii text is garbled when Arduino message is displayed in ScripCraft #3

@sisomm

Description

@sisomm

So I have managed to send commands from ScriptCraft to an Arduino, and the Arduino responds over the serial port.

I use the mosquitto_pub command listening on the serial port
tail -f /dev/tty.usbserial-A702MUZO | /usr/local/Cellar/mosquitto/1.2.3/bin/mosquitto_pub -t /arduino/1/status -l
And it shows up nicely in the queue with topic /arduino/1/status:
Pin: 13 State: LOW
Pin: 13 State: HIGH
Pin: 13 State: LOW
Pin: 13 State: HIGH

Now, when I subscribe to this in ScriptCraft, Using your the code :

client.subscribe('/arduino/1/status');
.
.
.

client.onMessageArrived(function(topic, message){
// handle incoming messages here.
var bytes = message.payload;
player.sendMessage(bytes);
});

  • the text above is totally garbled. How do I convert it to readable text?

Pathetic excuse: I have tried to google it. I know that it is a binary payload, and It should be converted somehow - both from ASCII to UniCode and from byte array to String. This is stretching me a bit, since I don´t know JavaScript and I am quite rusty as a programmer (ten years have gone since I did it professionally)

AND I assume that such a conversion will come in handy for many others, hence could be part of your library

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions