Perl


48 posts   Page 2 of 2   1, 2
by gadgetoid » Mon Jul 09, 2012 1:23 pm
For anyone interested, I have a project in the works to wrap up WiringPi for Perl, to join the Ruby and Python versions I'm maintaining.

I'm not doing anything clever, the enterprising individual could probably just grab my Python version, compile SWIG 2.0 from source ( unless they're using Rapsbian or Fedora which have it already iirc ) and run "swig -perl wiringpi.i".

I've got to research packaging it up for Perl, as I'm not really sure how or where to install the compiled library.
Posts: 75
Joined: Wed Mar 07, 2012 9:58 pm
by dch26 » Mon Jul 09, 2012 3:16 pm
and i have got my ".obj" (wavefront) 3d object model loader working for perl pi opengl.

cobra1.jpg
tada
cobra1.jpg (26.55 KiB) Viewed 4934 times


still need to tweak a few bits - but the basics are there - it was a straight rip from my desktop gl app.

if you are wondering about the spuriously placed car-parts - then i can tell you they were wrong in the original model i had (you see the same if you load in blender)

and this model is spinning in front of me, smoothly at 1920x1200

some stats for this model:
vertices : 6961
faces : 3264
normals : 2804 (not doing anything yet - lighting is next!)
texture coords : 694

cheers
dch
Posts: 23
Joined: Fri Jun 29, 2012 3:32 pm
Location: UK
by dch26 » Tue Jul 10, 2012 9:34 am
perl pi opengl

textures now loading from RAW or TGA (with or without alpha channel).
others could be loaded on request - but thats all i need for now.

lighting is working too :)

i will try to setup a nice lit model & post a screenshot a bit later

dch
Posts: 23
Joined: Fri Jun 29, 2012 3:32 pm
Location: UK
by dch26 » Tue Jul 10, 2012 4:45 pm
i guess this screenshot speaks for itself:

tex-fonts.jpg
tex-fonts.jpg (24.41 KiB) Viewed 4902 times


but, just in case it doesnt:

perl, raspberry pi, opengl es 1.x - text being printed by textured fonts.
font is perfectly proportional, spaced & baselined :)

18fps - not too bad, but....optimisation required i think!

with opengl es 1.x we will certainly hit a limit on the pi, where we become CPU bound.
we simply wont have the horsepower to manipulate the arrays as needed & we cant farm
it all off to the GPU

what mischief next?

dch
Posts: 23
Joined: Fri Jun 29, 2012 3:32 pm
Location: UK
by dch26 » Thu Jul 12, 2012 7:35 am
raspberry pi, perl, opengles 2.0 - yes 2.0!!!

vertex & fragment shaders to draw hello triangle

perl-opengles2-hello-triangle.jpg
perl-opengles2-hello-triangle.jpg (5.68 KiB) Viewed 4883 times


took a while to get going - but i was inspired after my opengles 1.x success.
my problem is, i dont (yet) speak shader language - so the triangle is my limit for now

hope you like

dch
Posts: 23
Joined: Fri Jun 29, 2012 3:32 pm
Location: UK
by Gibble » Thu Jul 12, 2012 8:39 am
Is there any code out there to play with, or is it just something you're doing yourself atm? Wouldn't mind a play, but not problem if not!
Posts: 56
Joined: Wed May 09, 2012 9:52 am
by dch26 » Thu Jul 12, 2012 12:39 pm
play files are available to those that are interested.
while its still in early stages i'm not going to widely publish it.

send me a private message with your ideas and tell me how you can help test

dch
Posts: 23
Joined: Fri Jun 29, 2012 3:32 pm
Location: UK
by richard_icrar » Sun Jul 22, 2012 5:20 am
Hi DCH

Would I need the same wrappers to access the EGL routines as OpenGL from C? Could you share the list of wrappers you wrote, as I believe I will need to make the same (or has (fingers crossed) some one else done this already?)

Thanks
Richard
Posts: 3
Joined: Fri Jul 20, 2012 4:33 am
by BillStephenson » Mon Jul 23, 2012 8:59 pm
gadgetoid wrote:For anyone interested, I have a project in the works to wrap up WiringPi for Perl, to join the Ruby and Python versions I'm maintaining.

I'm not doing anything clever, the enterprising individual could probably just grab my Python version, compile SWIG 2.0 from source ( unless they're using Rapsbian or Fedora which have it already iirc ) and run "swig -perl wiringpi.i".

I've got to research packaging it up for Perl, as I'm not really sure how or where to install the compiled library.


Hmmm, I, for one, am very interested in this, Looks like you've got it ready to play with too.

It may take me a bit before I have the chance, my RPi is scheduled to ship tomorrow, and I'll have my hands full with some other things I want to mess with first, but I will be getting to this library and the Perl module to interface with it, that's for sure. If nothing else, I'll install and do some simple tests, and I'll definitely play with the module to access the on-board serial port to see what I can do with that asap. If I can grab data from my GPS I'll be just tickled!

Thanks!!!
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by BillStephenson » Mon Jul 23, 2012 9:02 pm
dch26 wrote:raspberry pi, perl, opengles 2.0 - yes 2.0!!!
...

hope you like


That is cool!

Please keep up the great work and letting us know how things are going...

Bill
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by BillStephenson » Fri Jul 27, 2012 5:10 am
WooHoo!!! Got my RPi today and got it up and running with a mish-mash of stuff I've had lying around for no good reason, until now :D

I'll start working on some perl projects this upcoming week, and I'll let you all know how I do.

One thing that I was happy to see is that one of my perl apps ran great in the Midori web browser that comes with Raspian. I ran it from the internet and it was snappy as can be. I'll be working on getting it running on the RPi asap.

I have quite a few perl modules to install for that, so it will be a learning experience. I'll share whatever I can from it.
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by BillStephenson » Fri Jul 27, 2012 8:46 pm
I installed several modules today with no problem, but then found there was no CGI.pm in the perl that comes with the 2012-07-15-wheezy-raspbian.img

When I tried installing CGI.pm it fails with this message:

root@raspberrypi:/var/www# cd
root@raspberrypi:~# cpanm CGI
--> Working on CGI
Fetching http://www.cpan.org/authors/id/M/MA/MAR ... .59.tar.gz ... OK
Configuring CGI.pm-3.59 ... OK
==> Found dependencies: FCGI
--> Working on FCGI
Fetching http://www.cpan.org/authors/id/F/FL/FLO ... .74.tar.gz ... OK
Configuring FCGI-0.74 ... OK
Building and testing FCGI-0.74 ... FAIL
! Installing FCGI failed. See /root/.cpanm/build.log for details.
! Bailing out the installation for CGI.pm-3.59. Retry with --prompt or --force.


Tried doing "cpanm CGI --force" but still no go, same error message.

Any ideas on where to go from here?

Thanks,

Bill
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by BillStephenson » Fri Jul 27, 2012 9:43 pm
Well, was wrong about CGI.pm, it's there, and working when I run my script from the command line.

pi@raspberrypi /usr/lib/cgi-bin $ perl test2.cgi
Content-Type: text/html; charset=ISO-8859-1

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1><font color="#CC0000">Hello World</font></h1>
</body>
</html>pi@raspberrypi /usr/lib/cgi-bin


But when I run it from the browser I get this error in the apache error.log:

[Fri Jul 27 21:24:50 2012] [error] (2)No such file or directory: exec of '/usr/lib/cgi-bin/test2.cgi' failed
[Fri Jul 27 21:24:50 2012] [error] [client 192.168.2.101] Premature end of script headers: test2.cgi


But the file is there, and the permissions are set:

pi@raspberrypi / $ ls -l usr/lib/cgi-bin/
total 4
-rwxrwxrwx 1 pi pi 182 Apr 5 16:17 test2.cgi
pi@raspberrypi / $


So any ideas on what the problem is?
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by Htbaa » Sat Jul 28, 2012 10:13 am
Are you sure you've got the right compilers available? Do a apt-get install build-essential(s) to install the build tools that are also required by Perl for compiling modules that use C etc.
http://blog.htbaa.com
Posts: 2
Joined: Mon Jul 02, 2012 9:55 am
Location: Netherlands
by dch26 » Sat Jul 28, 2012 10:22 am
bill

have you forgotten your shebang as the first line of the perl script, to point to the perl executable?

dch
Posts: 23
Joined: Fri Jun 29, 2012 3:32 pm
Location: UK
by BillStephenson » Sat Jul 28, 2012 4:04 pm
Thanks for responding guys, I'm afraid I'm going to need all the help I can get with this :(

Here's where I stand now...

I did a clean install of raspbien and apache2 last night. Didn't change anything in the apache2.conf file this time (or any other apache config files).

I created a script with Leafpad and put it in the 'usr/lib/cgi-bin/' directory.

Here's the script:
<code>
#!/usr/bin/perl

#############################################################
# We use these fine modules...
use strict;
use warnings;
use CGI;
use CGI::Carp('fatalsToBrowser');
#############################################################
# Create a new CGI Object for the form input
my $Q = new CGI;

print $Q->header;

print $Q->start_html;

print 'Hello Moe';

print $Q->end_html;
</code>

Changed the permissions:
drwxrwxrwx 2 root root 4096 Jul 28 10:28 cgi-bin
-rwxrwxrwx 1 pi pi 407 Jul 28 2012 test.cgi

Ran it in a web browser and got this in the error.log:

[Sat Jul 28 10:30:31 2012] [error] (2)No such file or directory: exec of '/usr/lib/cgi-bin/test.cgi' failed
[Sat Jul 28 10:30:31 2012] [error] [client 192.168.2.101] Premature end of script headers: test.cgi

Perhaps it's how I'm installing apache?

Here's the commands I used:

# sudo bash
# apt-get update
# groupadd www-data
# usermod -a -G www-data www-data
# apt-get install apache2

I had expected the "www" and "cgi-bin" directories to be owned by "www", but that's not what happened:

drwxr-xr-x 2 root root 4096 Jul 27 20:58 www

Or maybe I have to do some configuration first, but I'm not finding a lot of info on that and what I do find is not very clear, or always specific to apache on Debian. From what I have found, apache on Debian isn't configured quite the same as other apache installations, so I'm struggling with that too.

I'm sure it's something simple, but I just haven't been able to nail it down. Once I do, I'll post the process a step at a time for others to review.
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by BillStephenson » Sun Jul 29, 2012 1:29 am
After reading and reconfiguring stuff all day I finally came across a clue...

my script starts with this line:

#!/usr/bin/perl

And when I run it with a web browser it fails with this error:

[Sun Jul 29 00:35:21 2012] [error] [client 192.168.2.101] (2)No such file or directory: exec of '/var/www/cgi-bin/test.cgi' failed
[Sun Jul 29 00:35:21 2012] [error] [client 192.168.2.101] Premature end of script headers: test.cgi

But, oddly, when I added this:

#!/usr/bin/perl -w

it runs with no error at all.

So, I thought it might be a line endings thing, but I've used BBEdit for years on my Mac and deployed my scripts on FreeBSD and Linux and never had that problem unless I was editing a script made with a Windows app. So I configured the file's line endings with as many options as my BBEdit gave, but without that "-w" there, it won't run as a cgi script.

Any ideas on what the heck is going on?
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by BillStephenson » Sun Jul 29, 2012 7:51 am
Okay, I still don't quite get the shebang line thing, but I'm pretty sure it's just a problem with the line endings on my scripts, so I still have to figure that out.

I have to add something to the end of the shebang line. It's not the "-w" switch, just a "-" by itself makes my scripts work. A blank space doesn't work though. I didn't change any line endings though, just added the "-w" to the shebang line. Weird...

I did get a few of my scripts running. Some are reading and writing files. The interface uses the prototype js libraries and a bit of ajax and it's actually all running pretty good in the Midori browser. It's a little slow running off the installed apache webserver, but not quite terribly so. I had hoped it'd be a little faster, but I was worried it wouldn't work at all, so I'm happy with how that's going.

The same web app actually runs pretty snappy in the Midori browser when it's accessing it off the internet from my VPS linux web server, or my Mac server on the LAN, so it looks like the RPi really should be a pretty good general purpose web client. I haven't tried to install Chrome on it yet, I might look into that soon.

Serving the web app from the Raspi to my Mac was pretty good too, all things considered. It's a little slow, but not painfully slow. I didn't try serving any big files with it yet, but that's not something I was looking to do anyway.

To sum up my first impressions I have to say that as a starting point for learning how to program using Perl, the Raspberry Pi is already an incredibly impressive platform. I'm sure that's obvious to most here, but it still exceeds any expectations I might have had.

Even for those with some experience it's an amazing tool to have. It's a developer's sandbox where you can stomp around and try things you'd never want to do with your workaday machine. It's one of those tools that you have to have now that you can. More than one is even better :D

Once I nail it down a bit more I'll post what I've done to get things working. It might be a bit Mac oriented, but I suspect most of it will be common enough.
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by BillStephenson » Mon Jul 30, 2012 8:48 pm
It's incredibly easy to set up a simple Perl webserver and use it to run perl cgi scripts on your Raspberry Pi. Here's what you need to get started:

First install CPAN Minus. Open the Root Terminal and enter these commands:

# sudo apt-get install curl
# sudo cpanm HTTP::Server::Simple::CGI

Now your server is installed. Next, get the example script from the HTTP::Server::Simple docs at http://www.cpan.org. HERE

I used the Midori browser to load that page and copy and pasted the example script into a Leafpad document and then saved the file into a directory named "http" that I created in my user directory.

I named the file "test.cgi" and saved it with these options: Character Coding->UTF-8->LF

So, the full path to my cgi script is:

/home/pi/http/test.cgi

Navigate to your new "http" directory in the Terminal using these commands:

# cd

# cd http

Use the Terminal to set the permissions on the script to "777"

# chmod 777 test.cgi

Now start the server by running the script:

# ./test.cgi

You should this output:

pi@raspberrypi ~/http $ ./test.cgi
Use 'kill 2431' to stop server.
pi@raspberrypi ~/http $ MyWebServer: You can connect to your server at http://localhost:8080/

Now test it in your Midori web browser by typing in the URL shown above:

http://localhost:8080/

You should see this on the page that loads:

Not Found

The example script has a sub-routine called "resp_hello". To view the output of that sub-routine you type this into the Midori web browser:

http://localhost:8080/hello

You should see this on the page that loads:

Hello !

Finally, the script looks to see if there is a variable called "name" appended to the url, and if there is it adds that to the "Hello ! greeting. So, try this url in your Midori web browser:

http://localhost:8080/hello?name=Your Name Here

You should see this on the page that loads:

Hello Your Name Here !

That's it! You're ready to start creating perl cgi scripts and serve them with your perl web server!
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by BillStephenson » Thu Aug 09, 2012 1:17 am
I've got the "Note Pad" app for the raspberry pi about finished up. It's pretty simple. It demonstrates the basics of using the "CGI", "HTML::Template" and "Text::Wrap" modules, a couple home made modules, reading and writing files, a simple example of using the prototype and scriptaculous JS library's "sortable list function" to "Drag and Drop" your notes in the order you want them to appear, and some CSS to style the output.

You can try the app out here:

http://raspberryperl.secureshopper.com/ ... /notes.cgi

Should come up here tomorrow (I just configured the domain name this afternoon):

http://raspberryperl.com/cgi-bin/NoteApp/notes.cgi

I'll get the code posted for running this app on the RPi as soon as I add some comments to the code and a set of instructions to install everything needed to get it up and running on raspbian. In the meantime, you can grab all the code here:

http://raspberryperl.secureshopper.com/NoteApp.zip

As with all things Perl, there is more than one way to do it. I make no claims as to this being the best way to write perl code, or the most efficient, or any other claims for that matter. I've tried to keep the code simple and readable in the example while also making it a usable product. My hope is that it is simple enough that beginners can make changes to it and add features as they see fit. Hopefully it achieves those simple goals.

If you have any comments or suggestions please post them here.

Kindest Regards,

Bill Stephenson
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by BillStephenson » Fri Aug 10, 2012 12:13 am
I removed that NoteApp.zip file because it contained a bunch of files the MacOS stuffs in there. You can find and download a new tarball with all the files in it here:

http://raspberryperl.com/NoteAppCode/

I also adjusted the paths in all the files to be used with the Apache web server on Raspbian.

If you have any questions let me know....

Bill
Posts: 130
Joined: Thu May 17, 2012 1:25 am
Location: SW Missouri Ozarks
by hugmeir » Wed Aug 21, 2013 11:00 am
dch26 wrote:raspberry pi, perl, opengles 2.0 - yes 2.0!!!

vertex & fragment shaders to draw hello triangle

perl-opengles2-hello-triangle.jpg


took a while to get going - but i was inspired after my opengles 1.x success.
my problem is, i dont (yet) speak shader language - so the triangle is my limit for now

hope you like

dch


Hey, I would be super interested in seeing your work on opengles + perl. Admittedly, not for the raspi (mine's headless), but for Android. In any case, is there a public repo somewhere, or some way I could take a peek at the code?

(Apologies for bumping an old thread)
Posts: 1
Joined: Wed Aug 21, 2013 10:50 am
by dch26 » Wed Aug 21, 2013 3:11 pm
@ hugmeir
you interested in opengles 1 or 2?
i didnt get that far with 2....just the bare framework...as i said i didnt have
time to learn the shader langauge.
i prefer 1 myself - but the pi (and presumably most android devices) are not
powerful enough to do everything you want on the CPU side.obviously 2
leverages the power of the GPU (which the pi has a good one of)

my opengles stuff was based on a SWIG wrapper i created - then some custom
C and some perl (obviously)

let me know
dch
Posts: 23
Joined: Fri Jun 29, 2012 3:32 pm
Location: UK