ghp
Posts: 1146
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Release: scratch2 controls GPIO with scratchClient

Sat Jun 03, 2017 4:52 pm

Hello,
the last month I worked on connecting scratch2, the web based scratch version from scratch.mit.edu and GPIO on raspberry and more.
To be precise, this is done by scratch extensions using http://scratchx.org/#scratchx. This is 'the same' as scratch2, but allows to use extensions. These extensions can provide an interface to scratchClient. And scratchClient can connect to GPIO as usual.

The extension blocks in scratchX are defined using the definitions from the config.xml file from scratchClient. This is working stable now.
Current implementation allows to send/receive broadcasts and to send/receive variables.
scratchX does not need to run on same computer as scratchClient. For example when using the pi2go adapter the scratchX can run on a laptop and scratchClient on the robot.

During this work, the internal web app was reworked and uses now tornado framework. Which has build in websocket support and is easier to use as cherrypy. As scratchX is online only, the connection to a local data provider needs to bypass the 'same server policy' and this was quite simple to achieve with tornado. Python3 is the suggested platform to run scratchClient now.

scratchClient is still working with scratch1.4, the program accepts connections from either scratchX or scratch1.4. Existing config files or adapters do not need to be changed. Monitoring and simulation of events is still possible by using the internal web server.

The current code was tested with the pi2go-configuration provided recently. Communication is now stable and allows reconnect. Execution in scratchX gets slow when browser is in background. Not very good if you automatically control a robot.

A release is available, see http://heppg.de/ikg/wordpress/?p=984. Especially shutdown with ctrl-c is working now. If there are still problems then kill the app from another window. In case of problems, close the browser (tab) and reload scratch2 application.

The provided adapters are same as in the previous scratch1.4 scratchClient.
The previous scratchClient 1.4 and the new scratchClient will be available in parallel till end of july, then both versions will be merged.
Next step is to validate the new scratchClient with the now available scratch2 in raspbian.

Regards,
Gerhard

ghp
Posts: 1146
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Release: scratch2 controls GPIO with scratchClient

Sat Jul 01, 2017 8:12 pm

Had some time to validate scratchClient connection to scratch2 on raspbian in the download from 2017-06-21-raspbian-jessie.img.
Works pretty good. The extra step needed with scratchx to bypass the need to download extensions from github is removed.
start scratchClient (installation is described in http://heppg.de/ikg/wordpress/?p=984)
Press shift and file, then use import experimental extension. In the dialog, enter ' http://localhost:8080/scratchx/js/extension.js'. You can use ctrl-v to paste a copied string.

scratchClient has an embedded web server which provides this documentation. open localhost:8080 in a browser to get the menu.

ghp
Posts: 1146
Joined: Wed Jun 12, 2013 12:41 pm
Location: Stuttgart Germany
Contact: Website

Re: Release: scratch2 controls GPIO with scratchClient

Mon Jul 03, 2017 4:04 am

When running experiments with scratch2 'local extensions', I found that the file name proposed by scratch2 on raspbian was project.sbx. Saving worked, but the file was not found directly (needed to use the search function) and content could not be loaded again.

There was a conversation on this on blog page https://www.raspberrypi.org/blog/scratc ... pberry-pi/
Here the statements from this page:

ghp says:
2nd Jul 2017 at 8:24 am

The scenario is:
– start standalone scratch2 on 2017-06-21-raspbian-jessie
– shift-click ‘file menu
– select ‘import experimental extension
– as I use scratchClient, I enter http://localhost:8080/scratchx/js/extension.js; scratchClient needs to run, of course. It provides an extension.js file
– scratch2 accepts the extension. This is great, as the limitation of scratchx to load only github based extension is removed.
– save project. The file name proposed is ‘project.sbx’

Simon Long says:
2nd Jul 2017 at 1:08 pm

OK, that’s not actually supported functionality in this release – it’s a hang-over from this editor being based on the one on scratchx.org. There will probably be a mechanism for adding local extensions in future releases, but the mechanism you have discovered isn’t it!

Don’t rely on it being there in future releases, as it may be removed. The bottom line is that we do not officially support loading additional extensions in this version.

Return to “Scratch”

Who is online

Users browsing this forum: No registered users and 2 guests