Discuss Scratch

RCBilsland
Scratcher
2 posts

Scratch 3.0, Scratch Link and the need for a Serial Interface

Sorry about this bit of cross channel posting but I thought the information would be of interest here as well as the extensions forum, maybe shedding some light on how Scratch Link works and the benefit of adding a serial interface to it.


I enjoy a good puzzle and thought I would take apart how Scratch 3.0 was talking to local hardware and what part Scratch Link played in this puzzle. What I found is a clever way to work around security restrictions within the browser and also layers of code that have been developed meaning that others will be able create their own extensions using them without too much of a problem.

The communication path goes from the extension library (e.g. the micro:bit extension) through to generic communication libraries (currently either Bluetooth or Bluetooth low energy). From here a web-socket connection is opened to device-manager.scratch.mit.edu, port 20110. Normally a browser won't allow communications outside of the domain the site is loaded from and the address used is just a sub-domain of scratch.mit.edu so all OK. But still how does this get back to the local hardware and this is the clever bit, if you lookup the IP address of device-manager.scratch.mit.edu it returns 127.0.0.1. For anyone who doesn't recognise this it's also called localhost or in layman's terms the machine the request is being made from. This is how the communication gets to the local hardware. What Scratch Link does is creates a web-socket server on your machine for connections to be made with that exposes the required communication stacks and so onto the local hardware.

So for anyone who wants to write an extension to connect to either a Bluetooth or Bluetooth low energy device then I believe everything is there that is needed to do so. What I would like (if you're still reading this) is for Scratch Link to expose the local serial ports through another generic communication library so that everyone can use it. Not all devices can be connect to over Bluetooth and being able to make serial connections would open up a whole new world of peripherals that could be connected to Scratch (I have a head full of ideas).

Before anyone asks I have no connection with any of the Scratch 3.0 or Scratch Link development, everything I have found is just by looking through the source code on GitHub and exploring the Scratch Link installation package. I hope others find this post useful and maybe someone would be good enough to include serial communications into Scratch Link.

Bob.
SimpleScratch
Scratcher
500+ posts

Scratch 3.0, Scratch Link and the need for a Serial Interface

and also layers of code that have been developed meaning that others will be able create their own extensions using them without too much of a problem.
The information is interesting but I'm not seeing any use for it

We can't write our own extensions so its a mute point what Scratch Link does
ScratchAndJoJoSiwa
Scratcher
7 posts

Scratch 3.0, Scratch Link and the need for a Serial Interface

when green flag clicked
set [port 20110 v] to [already in use]
ask [when will be in not?] and wait
if <(answer) = [intel inside]> then//waits the func to be intel inside
play sound [boom boom v] until done
broadcast [allow v]

end
and then will be used:
when I receive [allow v]
set [port 20110 v] to [0]//will be no longer already in use
switch backdrop to [win v]
play sound [yay v] until done//cheer

Last edited by ScratchAndJoJoSiwa (Aug. 18, 2020 20:12:44)

DGNada1985
New to Scratch
1 post

Scratch 3.0, Scratch Link and the need for a Serial Interface

Hello evry one,

I want to ask if I can build a TCP client or server using scratch

Your support will be apprecieted.

Regards
Nada
notmax67
Scratcher
1 post

Scratch 3.0, Scratch Link and the need for a Serial Interface

move () steps[quote=DGNada1985]Hello evry one,

I want to ask if I can build a TCP client or server using scratch

Your support will be apprecieted.

Regards
Nada[/quote]
maybe
H__4
Scratcher
3 posts

Scratch 3.0, Scratch Link and the need for a Serial Interface

What does this mean?
Is it all just blah blah blah?
Who cares?

H__4

Powered by DjangoBB