Loonhaunt
Posts: 55
Joined: Sat Nov 16, 2013 5:13 am

Scratch Piface 8 channel Relay

Sun Dec 15, 2013 4:09 am

Hey ,

Back at Scratch with Piface. I set up a bit of a program that reads an input and starts a loop of turning on and off relays on a Sainsmart style relay board. It worked beautifully for a bunch of iterations then mysteriously quit. I looked over my circuit to make sure nothing had come undone and nothing had. I shut everything down rebooted started Scratch again, started a hosting session, ran Handler, and got the same result nothing, I was watching all of the outputs supposedly sending signals to the relays via the output monitors in Scratch, while the program was running but no lights on the board. I started the Piface Emulator and it opened and closed the relays perfectly and my breadboard and LEDS lit as they were intended to. I have had a similar thing happen with Scratch before, is there some inherent instablility at this point in development? I am going to re-assemble the code, ..."From Scratch" no pun intended, as I am suspicious that perhaps my output variables are not getting saved when I save the file while working on it or prior to shutting down.

Thoughts are welcome,

Dave

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

Re: Scratch Piface 8 channel Relay

Sun Dec 15, 2013 1:53 pm

Hello,
Hello,
there is a usage scenario for scratch where the build in server on port 42001 is not open.

In current scratch, the remote network connection is enabled by default.

(1) start scratch (enable remote connections) This enables the server on port 42001
(2) start a second scratch (enable remote connections). Port 42001 is already open in another process, so the server is not started.
(3) stop the first scratch instance (from (1).

The process (2) has remote network connections enabled, but no started remote desktop connection.

After reboot and carefully starting scratch only once, this should not happen.
You can use nmap to monitor the sockets on your machine.

Greetings
Gerhard

Loonhaunt
Posts: 55
Joined: Sat Nov 16, 2013 5:13 am

Re: Scratch Piface 8 channel Relay

Sun Dec 15, 2013 9:24 pm

Gerhard,
Thanks for the input, I will watch this as I work on scratch again.

Dave

simplesi
Posts: 2327
Joined: Fri Feb 24, 2012 6:19 pm
Location: Euxton, Lancashire, UK
Contact: Website

Re: Scratch Piface 8 channel Relay

Sun Dec 15, 2013 9:56 pm

In current scratch, the remote network connection is enabled by default.
I just checked this and it seems to be in some sort of in-between state

According to right-clicking on the last Sensor block - its says disable it (which implies it is enabled) but it does not connect to my ScratchGPIO running on port 42001.

If I disable it and re-enable it, then the RSC dialog comes up and then it does connect to ScratchGPIO
I'll contact Tim about this

Simon
Seeking help with Scratch and I/O stuff for Primary age children
http://cymplecy.wordpress.com/ @cymplecy on twitter

timrowledge
Posts: 1287
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch Piface 8 channel Relay

Mon Dec 16, 2013 10:41 pm

Sigh, yes I screwed up something before building the release image. Apologies; in my defence I didn't change any code but just accidentally did an 'enable remote connection' whilst testing something else out.

The simple answer is to disable the remote connection and re-enable, as SimpleSi mentioned. I'll find some way to make sure it gets properly cleaned up before ash release. In fact, I can't see why it would't be something to do at each system startup.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

Loonhaunt
Posts: 55
Joined: Sat Nov 16, 2013 5:13 am

Re: Scratch Piface 8 channel Relay

Mon Dec 16, 2013 11:05 pm

Pardon my wandering, but....

I am now a little confused as to what was going on with my original issue with the Host, no Host and Scratch not sending digital out even though I had virtual indication of it? I will read back through all of the posts, prior to my next bit of testing but just in case is there and encapsulated version of what is happening?

Dave

timrowledge
Posts: 1287
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch Piface 8 channel Relay

Tue Dec 17, 2013 12:19 am

Hmm. When you start hosting, the code does the proper close down and clean up of any old connections and then (re-)starts the server code. So strictly speaking you are not going to be seeing any effect of the remote connection being left sort-of active.

It's interesting that you say it worked for a while before stopping. That isn't really likely to be a Scratch specific issue with sockets; after all it merely uses the standard socket libraries. Right now I'm mystified. Any further testing you can think of to establish exactly what happens would be good.
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

Loonhaunt
Posts: 55
Joined: Sat Nov 16, 2013 5:13 am

Re: Scratch Piface 8 channel Relay

Tue Dec 17, 2013 2:47 am

I believe that the problem that I am having is caused by something that occurs during the file save process. I can save a perfectly working piece of Scratch code, and have it not function when I open it to run it again. I open the file, a Scratch session begins, I run Piface handler, I see that the inputs are connected via a terminal window , try to start the program and it does not run at all. I have right clicked on a sense point disabled it, then re-enabled and it still does not run. If I close that Scratch session, start a new one intiate Hosting, run Piface Handler, then build new code indentical to the one saved it will run. If I save that code. Close Scratch Open it again follow all of the procedure, that newly made but once saved code will not run?

What am I doing incorrectly?

Dave

timrowledge
Posts: 1287
Joined: Mon Oct 29, 2012 8:12 pm
Location: Vancouver Island
Contact: Website

Re: Scratch Piface 8 channel Relay

Tue Dec 17, 2013 4:17 am

Not at all sure you're doing anything wrong at all! It's going to be tricky debugging this since I don't have a Piface to test with... but patience and wild guesses may save the day ;-)

One test to try -
open Scratch
drag one of the sensor [button pressed] tiles into the script editor
get the menu to 'disable remote sensor connections' and do that
*then* load your project file.

My hypothesis is that we will have properly closed the sockets *before* loading your code. My hope is that this will show us that I at least sort of understand what is going on....
Making Smalltalk on ARM since 1986; making your Scratch better since 2012

Nige C
Posts: 46
Joined: Thu Jul 19, 2012 12:22 am
Location: Hadleigh, Suffolk

Re: Scratch Piface 8 channel Relay

Tue Dec 17, 2013 4:27 am

I feel the PiFace has been launched and up to now ignored. The latest instructions for PiFace does not install the latest interface without reading and installing the script manually. I did that an ended up with the latest PiFace Icon on the Raspberry Pi Xwindow desktop.
Last edited by Nige C on Tue Dec 17, 2013 5:01 am, edited 1 time in total.
Retired power engineer with a lot of real life experience. Life is an adventure again :)

Loonhaunt
Posts: 55
Joined: Sat Nov 16, 2013 5:13 am

Re: Scratch Piface 8 channel Relay

Fri Dec 27, 2013 1:47 pm

timrowledge wrote:Not at all sure you're doing anything wrong at all! It's going to be tricky debugging this since I don't have a Piface to test with... but patience and wild guesses may save the day ;-)

One test to try -
open Scratch
drag one of the sensor [button pressed] tiles into the script editor
get the menu to 'disable remote sensor connections' and do that
*then* load your project file.

My hypothesis is that we will have properly closed the sockets *before* loading your code. My hope is that this will show us that I at least sort of understand what is going on....
I have been working on other non-piface projects, so I have not had much to say about this thread recently. I did launch scratch and handler last night, using a some code that I assembled the last time I had both talking to each other and upon starting the program for the first time my relays opened and close via piface, performed their iterative function and shut off cleanly. I tried to show the program running to my daughter by starting it up again, and I got the sending through outputs acknowledgement with no relay function, again. I did not have a lot of time to work with it so I simply went to the sense blocks disabled and re-enabled them which accomplished nothing. Hopefully after the holiday here I will be able to focus some time on the issue. However since I have other projects that are quite productive I am not too inclined to mess with the Piface and Scratch combo.

Dave

alexjv89
Posts: 1
Joined: Tue Apr 15, 2014 10:12 am

Re: Scratch Piface 8 channel Relay

Tue Apr 15, 2014 10:15 am

Hey Loonhaunt,

So did you figure out how to solve the problem? Does anyone know how to make the output working from saved files?

I am having the exact same trouble.

Alex

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

Re: Scratch Piface 8 channel Relay

Wed Apr 16, 2014 5:14 am

Hello,

think there is still a bug in piface scratch handler. They ignore the record length information in the data coming from scratch. When records are scattered between various junks (which happens quite often), then sync is lost and it will look like communication is lost.

See https://github.com/piface/pifacedigital ... handler.py, version is 2.0.5

Code: Select all

                data = scratch_socket.recv(BUFFER_SIZE).decode('utf-8')
                data = data[4:] # get rid of the length info
I have in detail published a solution here in the forum, and have send this patch also to piface. Ask them to correct this.
So no scratch problem, it is a 'not perfect' implementation of the remote sensor protocol.
Regards, Gerhard

Loonhaunt
Posts: 55
Joined: Sat Nov 16, 2013 5:13 am

Re: Scratch Piface 8 channel Relay

Wed Apr 16, 2014 11:15 am

Nice, I will have to check that out.

Return to “Scratch”