Devon and Cornwall GNU/Linux Users Group

  • About DCGLUG
    • FAQ
    • Join
    • Meetings
    • Mailing List Archive
  • About : GNU / Linux
    • Federated social media
    • Video on Free software
    • Video on DRM
    • Video on Creative Commons
    • Hacker / Hacking definition
  • Tutorials
    • BASH Tutorials
    • e-learning
    • My Sql
    • LaTeX and Overleaf
    • Send Plain text e-mail
    • Tutorial : GnuPG – Encryption & Signing
  • CHAT (IRC) / Matrix
    • IRC – Client Setup
      • Weechat Setup guide
      • Hexchat Setup
      • IRSSI Configuration
      • xchat – setup
      • ERC Setup
      • Chat – Matrix
    • DCGLUG on Mastodon

Mesh Networking in Scratch – The way to interface practically anything to scratch.

Posted on 2014-08-30 by Paul Sutton

Introduction

The Scratch development platform is a great way for younger coders to get into computer programming with it’s simple “lego brick” style of drag and drop code construction. However interfacing hardware to it can be a little bit tricky (although not totally impossible).

One feature of Scratch that can be very useful is the mesh network feature which provides a mechanism for broadcasting messages and sharing variables (as “sensor-updates”) via standard network sockets.

This feature means that practically any modern computer language (python,c,c++,java,php to name but a few) could be used to interface to a scratch session via the mesh. For example these languages can be used to directly interface other hardware such as game controllers (wii remotes, console game pads etc.), to scratch via the mesh network.

There are two little wrinkles in this plan however. Firstly because the program is acting as a proxy between the hardware and scratch via a network connection the response can be sluggish. Press button here and wait half a second plus before scratch responds. This isn’t the nanosecond responses that console games expect in “real world” game titles, but this is scratch games, not the next multinational block buster game.

The second wrinkle is that you have to turn on the Mesh networking. Not the hardest thing to do in the world, but one should be aware of what mesh networking is doing in the background. For one thing its allowing anything that understands the Mesh networking protocol (which I will be explaining later in this article)  to access variables in your scratch session without a single nod or wink to authentication or security (because frankly mesh networking on scratch has none). If you think of a scratch variable holding one of your private emails then switching on mesh networking would allow another computer on the same local network to access that email. Worse still if you open up port 42001 on your firewall then potentially anyone on the Internet could access your scratch session. The good news here is that by default it is highly unlikely that your firewall will have opened up port 42001 to any machine on your local network (let alone one used by a primary school child).  However it is possible to do this through your firewall management software and there maybe a point where you would want to consider a school-to-school project link. If that opportunity does ever arise, open up your firewall to port 42001, do the exercise, close down access to port 42001, job done.

Having said all that, the reality is that you will not (should not) be doing anything that sensitive with scratch. By making you aware of the minor risks and dangers in opening up mesh networking (when compared to the benefits that it brings to young coders discovering new ways to do things like inter process communication), I am hoping that you will be able to appreciate the issues involved and head them off in the more controlled environment of the classroom. The most likely scenario is when some bright kid realised that they can snoop on another kids classroom project by connecting to his/her mesh. If that happens credit them for having a deeper understanding of how mesh network works with Scratch… but also take some time to explain to them the ethical issues of doing such things “unannounced” with a hope that they will grow up to be network security consultants not master cyber criminals…..

Most importantly be aware of how it works  yourself. If you know how to detect it (and hopefully this article will explain it well enough for you to understand) then it probably will never happen. And even an “up front” lesson on ethical computing would not go amiss. Give them the old spiderman pep talk “with great power comes great responsibility ….”

Turning Mesh On

I could write a really boring sub section on this but frankly M.I.T’s own instructions for doing this pretty much cover it, after all they did develop Scratch so they should have an idea or two about how it works! See: http://wiki.scratch.mit.edu/wiki/Mesh

The only other thing I would add to this from my own personal experience is that while turning mesh networking on for Scratch on Linux based systems like the Raspberry Pi you will need to run it as root (sudo scratch) from the console. If you don’t do this it will probably freeze up as the “save” stage and you will have to follow the instructions all over again.

Once you have updated the image with mesh enabled you will be able to switch it on/off from within any scratch session started as a “normal” user via the usual desktop shortcut link.

My Python ScratchListener Class

I have adopted and adapted other peoples work in constructing my own “ScratchListener” class. The code is meant as a test piece framework for someone to add new features to or interface new devices to scratch

Source code   
from array import array
import threading
import struct
import socket
import time
import sys
 
class Scratch():
 
def __init__(self):
PORT = 42001
HOST = 'localhost'
 
if not HOST:
sys.exit()
 
print("connecting...")
self.scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.scratchSock.connect((HOST, PORT))
print("connected")
 
def send(self,cmd):
print(cmd)
head = len(cmd).to_bytes(4,byteorder="big")
self.scratchSock.send(head + cmd.encode("utf-8"))
 
def broadcast(self,message):
self.send("broadcast %s" % message)
 
def update(self,variable,value):
self.send("sensor-update \"%s\" %s" % (variable,value))
 
def recv(self):
return(self.scratchSock.recv(1024).decode("utf-8",'replace'))
 
class ScratchListener(threading.Thread):
 
def __init__(self):
 
threading.Thread.__init__(self)
 
PORT = 42001
HOST = 'localhost'
 
if not HOST:
sys.exit()
 
print("connecting...")
self.scratchSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.scratchSock.connect((HOST, PORT))
print("connected")
 
def run(self):
 
while(True):
 
data = self.scratchSock.recv(1024)
length = struct.unpack(">l",data[0:4])[0]
pdata = data[4:].decode("utf-8")
 
if(length != len(pdata)):
print("Data Length Missmatch on received data")
return
 
print("Data Received %d %s" % (length,pdata))
self.process(pdata)
 
def process(self,pdata):
 
if("sensor-update" in pdata):
print("Sensor Stuff")
parts = pdata.split(" ")
variable = (parts[1])[1:-1]
val = (parts[2])
exec("%s_temp = %s" % (variable,val))
print(external1_temp)
 
def send(self,cmd):
print(cmd)
head = len(cmd).to_bytes(4,byteorder="big")
self.scratchSock.send(head + cmd.encode("utf-8"))
 
def broadcast(self,message):
self.send("broadcast %s" % message)
 
def update(self,variable,value):
self.send("sensor-update \"%s\" %s" % (variable,value))
 
def recv(self):
return(self.scratchSock.recv(1024).decode("utf-8",'replace'))
 
# Main....
 
if(__name__ == "__main__"):
scratch = ScratchListener()
scratch.start()
external1 = 0
 
while(True):
#scratch.send("broadcast broadcast")
#scratch.send("sensor-update \"external1\" %d " % external1)
#scratch.send("sensor-update \"external2\" %d " % external1)
#scratch.send("set variable \"external1\" to %d" % external1)
#scratch.send("broadcast hello")
#scratch.broadcast("broadcast")
 
#print(scratch.recv()[4:])
 
scratch.update("external1","%d" % external1)
#scratch.broadcast("broadcast")
 
time.sleep(5)
 
external1 = external1 + 1

http://www.nikeairmaxfreedom.com nike air max 2015

Posted in Uncategorized | Leave a comment |

Gimp – Picture resize

Posted on 2014-08-27 by Paul Sutton

I have pulled in the tutorial from my website to the DCGLUG website,  this can be found at

http://www.dcglug.org.uk/gimp-picture-resize-tutorial/
http://www.nikeairmaxfreerun.com nike air max 90

Posted in Uncategorized | Leave a comment |

Job Vacancy : Digital Experience Manager

Posted on 2014-08-26 by Paul Sutton

LOCAL JOB VACANCY

Employer: SOUTH WEST GRID FOR LEARNING TRUST
Link to details : http://www.devonjobs.gov.uk/management-south-west-grid-for-learning-trust-digital-experience-manager/44066.job

 

  • Closing date:19 September 2014
  • Based at:Exeter

 
http://www.nikeairmaxfreedom.com nike air max

Posted in jobs | Leave a comment |

Sound converter tutorial

Posted on 2014-08-26 by Paul Sutton

I have added a simple sound converter tutorial to the website resources section

http://www.dcglug.org.uk/sound-converter/
http://www.nikeairmaxfreedom.com air max 95

Posted in Uncategorized | Leave a comment |

Global Hackathon

Posted on 2014-08-17 by Paul Sutton

 hack4goodlogo

Global hackathon 12-14 Sep 2014

0.6: hack against catastrophic climate change.

http://hack4good.io/  #hack4good

Flyer global H4G06 - LONDON2
http://www.nikeairmaxfreedom.com nike air max sneakers

Posted in Uncategorized | Leave a comment |

Fab Lab Taster Courses

Posted on 2014-08-15 by Paul Sutton

DEVON FAB LAB TASTER COURSES

** An Introduction to 3D Printing
------------------------------------------------------------
Saturday 16^th Aug - 11am , 1pm, 3pm.


**
An Introduction to Laser Engraving
------------------------------------------------------------
Saturday 23^rd Aug - 11am , 1pm, 3pm.


**
Printing Customised Cases and Covers
------------------------------------------------------------
Saturday 30^th Aug - 11am , 1pm, 3pm.


**
An Introduction to CNC Routing
------------------------------------------------------------
Saturday 6^th September - 11am , 1pm, 3pm.


**
An Introduction to Computerised Embroidery
------------------------------------------------------------
Saturday13^th September - 11am , 1pm, 3pm.


**
Bookings via our Eventbrite page:
http://fablabdevon.us8.list-manage.com/track/click?u=b8a10c99f56bd80ad9ba5aaa5&id=9846107b4b&e=2c61775a67

http://www.nikeairmaxfreerun.com nike air max 95

Posted in Courses, FabLab, hacking, Hardware | Leave a comment |

Web design course in Paignton

Posted on 2014-08-15 by Paul Sutton

Centrepeace in paignton are offering a 2 day web design course,   covering HTML / CSS and Java Script,  please see their website for more information

http://centrepeace.org.uk/1/post/2014/07/learn-web-design-centrepeace.html

Download pdf poster below.

learn_web_design__centrepeace

codeclublogo

If you are under 11 then something similar could be offered as part of code club ,  Please get in touch with centre peace directly and mention code club.

 
http://www.nikeairmaxfreerun.com nike air max 95

Posted in Uncategorized | Leave a comment |

Torios Project update

Posted on 2014-08-11 by Paul Sutton

Reproduced from my personal website http://www.zleap.net

For those of you who are following my blog / twitter feed you will know that I am involved as Documentation lead of the Torios project.  Over the past weekend I made a big stride in this.

  • Added the screenshot for the Jwm window manager settings manager
  • Added a section on testing and included some instructions on how to test a virtual box vdi hard disk image
  • Added information on how to create a flash disk.

There is still some work to do on this but I am getting there and hopefully this information can be synchronised with the online wiki manual.

We are still in internal testing phase at the moment but we should hopefully be able to release a pubic pre-alpha very shortly after which we will be seeking more feedback from user testing, so if you are interested please sign up.

If you can help in other ways please get in touch with the project leaders, details can be found on the website.  Ideally you will have a launchpad account which you will need to enable to you sign up to the main discussion list as well as edit and contribute to bugs, blueprints etc.  If you need help please ask.

If you are unsure what launchpad is please go to the website here. Or visit the Torios launchpad project portal.

 

Notes on early testing in virtual box seem to suggest that having 256 mb of RAM provides a nice quick system.  As this is a replacement for Windows XP which is now end of life.

Latest news can be found here.

IRC (chat) meeting schedule can be found here,  don’t worry if you don’t have an irc client I have added a web based interface to the channel
http://www.nikeairmaxfreerun.com nike air max 2015

Posted in Uncategorized | Leave a comment |

INXI : System information and More

Posted on 2014-08-05 by Paul Sutton

One of the nice things about hangong out on IRC and or with Linux user groups is you get to find out about all sorts of hidden gems.

INXI is one such gem. : https://code.google.com/p/inxi/

It is a full featured system information tool or as the website describes it “A newer, better system information script for irc, administration, and system troubleshooters.”

i believe this is installed by default on Mint and a few others for xubuntu you need to install it

sudo apt-get install inxi should do it

As with all or a vast majority of Linux commands there is a man page

man inxi

so what can it do

Well , to get some basic system information up you can use the -Sx argument

Source code   
$ sudo inxi -Sx
System:    Host: ER1401 Kernel: 3.13.0-30-generic i686 (32 bit, gcc: 4.8.2)
           Desktop: Xfce 4.11.6 (Gtk 2.24.23) Distro: Ubuntu 14.04 trusty

One of the more non system features is one that can give you info on local weather

Source code   
inxi -xxxWTorquay,Uk
Weather:   Conditions: 70 F (21 C) - Partly Cloudy Wind: From the South at 16 MPH Humidity: 78%
           Pressure: 29.98 in (1015 mb) Location: Torquay (UK) Altitude: 0 ft 
           Time: August 5, 4:52 PM BST Observation Time: August 5, 4:20 PM BST

Which is useful you can also invoke this from IRC clients with

/exec -c inxi -xxxWTorquay,Uk

for example which then executes within IRC, (not all channels appreciate this)

One of the ideas of this program is to provide people with system information so they can help you

of course you can send out put to a file with

/exec -c inxi -xxxWTorquay,Uk > output.txt
http://www.nikeairmaxfreedom.com nike air max 2014

Posted in Uncategorized | Leave a comment |

Exeter Raspberry Pi jam

Posted on 2014-08-04 by Paul Sutton

2nd August 2014, saw yet another pi jam take place in Exeter Library / Fab lab,  the 2 hour session seemed to be really busy. In the main fab lab there was a introduction to raspberry pi workshop where users were given an intro to the pi and had a chance to experiment with some electronic interfacing SAM_0240 The Library / fablab have some new raspberry pi model B+ for users SAM_0241 Bag of components from CPC ready for the work shop SAM_0244 This is a project from Mark evans, the display shows the Pis IP address SAM_0252 SAM_0253 Some of the creations by some of the younger visitors using scratch SAM_0254 And yes minecraft on the pi,  i think we managed to hack this enough to get the tnt blocks to explode with code rather than using redstone torches which are not available in MC Pi edition. SAM_0242 And bob made an appearance one of Tom Broughs many projects.  This is arduino based but that is not really important, anyone inspired to make their own Bob ask Tom for info :).

SAM_0248

 

Handy – Scratch controlled robot arm  (not the mini webcam)- issue with camera settings hence it is dark,

SAM_0203

Freddie (photo from a previous jam ) has now improved further.

 

So in all an excellent jam,  more of the same on Saturday 9th August in paignton,  we hope to see lots of people there :), and maybe we can look in to doing mini workshops at a future date.

 
http://www.nikeairmaxfreerun.com nike air max 95

Posted in Arduino, coding, programming, Raspberry pi | Leave a comment |
« Previous Page
Next Page »

Recent Posts

  • Tinkerers Meeting – July 2025
  • Tinkerers Meeting – June 2025
  • Meetings June 2025
  • End of Windows 10
  • LibreOffice 24.8.7 is available for download

RSS Debian Security

  • DSA-5961-1 slurm-wlm - security update
  • DSA-5960-1 djvulibre - security update
  • DSA-5959-1 thunderbird - security update

RSS Debian News

  • Updated Debian 12: 12.11 released
  • Updated Debian 12: 12.10 released
  • The Debian Project mourns the loss of Steve Langasek (vorlon)

CyberChimps WordPress Themes

© 2021 Devon and Cornwall GNU/Linux Users Group