scratchfoundation / scratch-link

Device interoperability layer for Windows and MacOS
BSD 3-Clause "New" or "Revised" License
103 stars 82 forks source link

Linux version of scratch-link? #84

Open martinohanlon opened 6 years ago

martinohanlon commented 6 years ago

This issue is meant to be a way of opening a discussion relating to the creation a linux version of scratch-link.

From my perspective:

In the near future, we (Raspberry Pi foundation) will need to make some decisions about how to make a future Scratch 3 Raspberry Pi extensions "talk" to the hardware and the presence (or not) of a linux version of scratch-link is a factor.

Current thinking (no more than that, subject to change, etc) is that comms would be via TCP to the pigpiod daemon running on the Pi.

Are there any plans for a scratch-link version for linux? Is it a consideration?

thisandagain commented 5 years ago

Hey @martinohanlon, just to follow-up on this thread from our email discussion:

em-be commented 5 years ago

Hi,

After some quick examination it seems that scrach-link is a flat web server @device-manager.scratch.mit.edu:20110 with websocket capability which handles json requests as described in Network Protocol. json requests for bt/ble are quite simple:

I propose to create scratch-link version for linux as SysV service starting at init which reroutes device-manager.scratch.mit.edu to localhost. It can be implemented in python using flask with websockets or any other simple http-service. For other than bt/ble services eg. tcp pigpiod daemon @ raspberry, scratch-link should just redirect the queries as necessary. Comments?

audetto commented 5 years ago

I don't know how the Windows and MacOS versions are implemented, but I think this is very similar to the http-serial-BT bridge developed by MakeBlock for the MBot (like an Arduino)

It is a node.js app which is used by their version of Scratch to send data via the serial port to the device which is running a particular sketch with a compatible protocol.

I've created a github project here if anybody is curious https://github.com/audetto/mblock-mlink.

The good thing about this approach is that the same node.js version works for all platforms and you don't need to maintain a separate source for each of them.

How to create the serial port, is OS-specific, but afterwards the same code works for Win, Mac, USB, BT...

audetto commented 5 years ago

https://github.com/audetto/asi-link

I've written a super simple implementation in nodejs of a link for serial ports (USB or BT Classic), which should work on all platforms. Not tested with any real device as I do not have a device to test it with. I am still writing the scratch-vm extension for an mBot, then I will do the full test.

I might be completely off, but it looks super simple, with a few caveats

audetto commented 5 years ago

My bad, it was a side effect of a poor design (global variables...) Each extension is a new ws:// connection so there is no need to ad this to the protocol. Anyway, now it is time to write the Extension in scratch-vm and we will see how this works.

cwillisf commented 5 years ago

@audetto I've just created #137 as a place to discuss WSS rationale and related topics. You're not the first person to ask about it so I figured it was time for a thorough explanation to be posted somewhere.

If you'd like to further discuss other topics related to the protocol or serial ports or anything that isn't specifically related to building a Linux version of Scratch Link, I would recommend creating a separate issue for that discussion. Thanks!

marek-memsql commented 5 years ago

+1 for the linux port... It would be great because my kids could use a rpi for programming boost...

audetto commented 5 years ago

Mind you, scratch link linux for a serial device is pretty much done (either USB or Bluetooth Classic)

Lego Boost needs BLE UART which is not written.

There is a node.js module for this

https://github.com/noble/noble

I will have to try it.

jaafreitas commented 5 years ago

Two years ago I wrote a multi-platform micro:bit extension for ScratchX using noble. https://github.com/jaafreitas/scratch-microbit-extension

I'm still waiting for the official Scratch Link for Linx, Raspberry PI and Chromebook version.

jorgenskogmo commented 5 years ago

+1 for Linux (esp. RPI)

apple502j commented 5 years ago

@thisandagain A Japanese programmer wrote Python implementation of Scratch Link here: https://github.com/kawasaki/bluepy-scratch-link/blob/master/scratch_link.py Worth checking.

thisandagain commented 4 years ago

@apple502j Thanks for the heads-up! I hadn't seen this yet!

jsyzthz commented 4 years ago

Can we use a cross-platform language to re-write this tools? like Java, Python ...

qwertykid commented 4 years ago

do you have copy i can install???

pepo-k commented 3 years ago

Hi is there any progress in porting of scratch link to linux? Can anybody make help here to show hot to get the lego boost working over ubuntu/scrattux?

Peter

jsyzthz commented 3 years ago

i try the go lang and java ,but it's difficult to implement. but i found a idea - Web Bluetooth. who use it? like MakeCode

Pythone commented 3 years ago

This issue is meant to be a way of opening a discussion relating to the creation a linux version of scratch-link.

From my perspective:

In the near future, we (Raspberry Pi foundation) will need to make some decisions about how to make a future Scratch 3 Raspberry Pi extensions "talk" to the hardware and the presence (or not) of a linux version of scratch-link is a factor.

Current thinking (no more than that, subject to change, etc) is that comms would be via TCP to the pigpiod daemon running on the Pi.

Are there any plans for a scratch-link version for linux? Is it a consideration?

I tried using pyscrlink and it worked well. (repo: https://github.com/kawasaki/pyscrlink)

Pythone commented 3 years ago

@thisandagain A Japanese programmer wrote Python implementation of Scratch Link here: https://github.com/kawasaki/bluepy-scratch-link/blob/master/scratch_link.py Worth checking.

It turns out that this was renamed to pyscrlink

wawrzek commented 2 years ago

Is there any updated on Linux support?

zdila commented 2 years ago

I have written scratch-link in Node.js for Linux and Intelino smart train: https://github.com/zdila/intelino-smart-train-scratch-link-linux

Code is quick and dirty (written in cca one day including studying of D-BUS and it's Bluetooth API) and it is hardcoded to search only Intelino devices. Feel free to use it for the inspiration.

markakis-sch commented 2 years ago

+1 for official Linux support.

I'm using Scratch 3.0 and kawasaki/pyscrlink on Linux (Ubuntu). I confirm that is stable and works fine with Lego WeDo 2.0 and EV3.

I also tried zdila/scratch-link-ble-linux. I was able to connect a WeDO 2.0 but could only use the "set light color to" command. I will continue to try it, because it is new and under development.