MrYsLab / s3-extend

Control an Arduino Uno, Circuit Playground Express, Raspberry Pi Pico, ESP-8266, ESP-32, Picoboard, Robohat MM1, or Rasberry Pi From Scratch 3
GNU Affero General Public License v3.0
27 stars 13 forks source link

OneGpio Raspberry Pi Extension and s3r are fragile #31

Closed KigenHasebe closed 2 years ago

KigenHasebe commented 2 years ago

Thanks for S3ONeGPIO.

The fragility is annoying when we program scripts for Scratch 3. I hope there might be some fool proofs in or s3r.

On such aulty OneGpio Raspberry Pi blocks, s3r on RasPi necessarily aborts. Then s3r and S3OneGPIO and Scratch script of the problem must be restarted manually.

I have encounter two cases. There might be potentially faulty blocks more.

A. block 'Tone Pin [PIN] [FREQ] Hz [DURATION] ms'

If FREQ is zero, s3r aborts. The intention of zero FREQ was a silence which is synchronous with before and after tones.

The cause of abort is a simple zero division. As a workaround I barely found that FREQ 1 works for me.

/usr/local/lib/python3.7/site-packages/s3_extend/gateways/rpi_gateway.py pin at the frequency and duration requested. frequency = int(payload['freq']) frequency = int((1000 / frequency) * 1000)

B. block 'Write PWM Pin [PIN] [VALUE]%'

If VALUE is negative or larger than 100, s3r aborts. These are primitive coding bugs of Scratch script. Nevertheless, that is annoying,

By the way, I devised a hack to restart s3r automatically. Aborted s3r revives several times surely. Though I am not sure why this hack works for me. I put the following code into /etc/rc.local.

( while (true) do if ps -ae | grep -w s3r > /dev/null ; then sleep 10 if [ x$DONE = "x" ] ; then DONE=Y else break fi else /usr/local/bin/s3r fi done ) &

MrYsLab commented 2 years ago

@KigenHasebe Thanks for the issue. Fixed with release 1.17