[fpc-pascal] Access GPIO pins on RPi2 without root?

2015-10-07 Thread Bo Berglund
How can one control the GPIO outputs on a Raspberry Pi2 without
needing the program to run as root? I am using Raspbian Wheezy and I
need to add two relays controls to my program.
The pages I have found with google are for the original Pi so the
connector referenced is the wrong size and it is also always mentioned
that the program must be run as root.
My program must be started every minute by cron so I don't know how
this will happen...
(Not so used to Linux)

Do I need to install some driver in Raspbian to allow access to the
GPIO ports from FPC?


-- 
Bo Berglund
Developer in Sweden

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Access GPIO pins on RPi2 without root?

2015-10-07 Thread leledumbo
>How can one control the GPIO outputs on a Raspberry Pi2 without needing the
program to run as root?

sudo chown root 
sudo chmod 4755 

The 4 is setuid bit, which will allow normal users to run the program but
the program itself has root privilege.



--
View this message in context: 
http://free-pascal-general.1045716.n5.nabble.com/Access-GPIO-pins-on-RPi2-without-root-tp5722809p5722810.html
Sent from the Free Pascal - General mailing list archive at Nabble.com.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Access GPIO pins on RPi2 without root?

2015-10-07 Thread Lukasz Sokol
On 07/10/15 08:02, Bo Berglund wrote:
> How can one control the GPIO outputs on a Raspberry Pi2 without
> needing the program to run as root? I am using Raspbian Wheezy and I
> need to add two relays controls to my program.
> The pages I have found with google are for the original Pi so the
> connector referenced is the wrong size and it is also always mentioned
> that the program must be run as root.
> My program must be started every minute by cron so I don't know how
> this will happen...
> (Not so used to Linux)
> 
> Do I need to install some driver in Raspbian to allow access to the
> GPIO ports from FPC?
> 
> 

Apart from running SUID Root, which is generally discouraged (there is lots of 
answers on why setuid root is bad)

I'd probably search for some udev rules to make up - to chown the gpio
devices in /dev to root:gpio, (for example) and your unprivileged user to
be a member of group gpio;

( possibly https://www.raspberrypi.org/forums/viewtopic.php?f=29=9667, but
also worth checking out other 
https://www.google.com/search?q=raspberry+pi+udev+gpio+user=utf-8=utf-8 
results.)

el es

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Access GPIO pins on RPi2 without root?

2015-10-07 Thread Jonas Maebe


Bo Berglund wrote on Wed, 07 Oct 2015:


How can one control the GPIO outputs on a Raspberry Pi2 without
needing the program to run as root? I am using Raspbian Wheezy and I
need to add two relays controls to my program.


This really has nothing to do with either FPC or Pascal programming in  
general. Please ask such questions on the fpc-other list in the future.


Thanks,


Jonas
FPC mailing lists admin

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] PostgreSQL notifications broken

2015-10-07 Thread Mark Morgan Lloyd

Mark Morgan Lloyd wrote:

Michael Van Canneyt wrote:

On Mon, 28 Sep 2015, Mark Morgan Lloyd wrote:


PostgreSQL has a useful feature where application programs can send 
notifications to each other, this tends to be much "cheaper" than 
periodically polling a table for changes.


I've had this working on various CPUs and OSes in a number of 
programs since at least 2.2.4, but it appears to have been broken 
at some point between 2.6.0 and 2.6.4 with problems persisting 
through to 3.0.0-rc1 and trunk.



PGConn is what you're looking for.

TPQTrans is referenced in :

  TPQCursor = Class(TSQLCursor)
  protected
Statement: string;
StmtName : string;
tr   : TPQTrans;


Thanks, I'll take another look but one of the handles I'm tracking is 
that PGConn field.


It turns out that the "best" handle to use- at least in the case of 
connections to PostgreSQL- is still the one associated with the 
connection object. The issue is not so much that the handles have been 
shuffled round, but that some of the database stuff was changed to 
reduce the number of spurious transactions that were issued.


Adding a couple of explicit CommitRetaining calls seems to improve 
things a lot:


  res := PQexec(postgresHandle(), PChar('LISTEN ' + 
sanitizeName(EditTableName.Text, true)));

  PQclear(res)
  SQLTransaction1.CommitRetaining

and

  DatabaseTableForm.SQLTransaction1.CommitRetaining;
  pqConsumeResult := PQconsumeInput(postgresHandle());
  notification := PQnotifies(postgresHandle());

where postgresHandle() gets the call from the connection object by 
default. To be extended to other programs and to also using Firebird as 
the backend.


Discussing this sort of thing elsewhere, at least PostgreSQL, 
Firebird/Interbase and Oracle provide comparable notification/event 
features with varying degrees of functionality. If encapsulating this 
sort of thing in libraries or components, it would be highly 
desirable to be able to rely on the availability of a persistent handle.


The above should be sufficient ?

But the mechanisms are different for each DB, so a unified mechanism 
is not something we are considering, to my knowledge.


But there does appear to be some common level of functionality where a 
database can either initiate or relay a notification. The amount of 
extra payload varies, e.g. Postgres (but not Firebird) includes the 
backend PID while I'm told that Oracle can filter notifications through 
a query.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Access GPIO pins on RPi2 without root?

2015-10-07 Thread Michael Van Canneyt



On Wed, 7 Oct 2015, Mark Morgan Lloyd wrote:


Jonas Maebe wrote:

Bo Berglund wrote on Wed, 07 Oct 2015:


I think that it really does because there must be some interface
between the FPC system and the underlying operating system managing
the hardware.


On Linux/Unix, every interface to hardware gets exposed as a file 
(generally under /dev). Sometimes you have libraries that provide a higher 
level interface, but in the end it will always access that file. If you 
need root permissions to perform actions on this file with language X, you 
will also need them with language Y and also if you use library Z to access 
it. The file operations are basic POSIX operations (open, read, write, 
ioctl, close), which are available with an "fp" prefix via the baseunix and 
unix units, and which are the same in C or other languages.


If you have a library that you want to use, then you can of course ask here 
whether anyone has translated the headers for it (which will probably be in 
C) to Pascal or so.


I've just been taking a look and I don't immediately see a kernel module that 
provides an interface to GPIO via /dev. I think there's things for I2C etc.


GPIO is managed via a mmap-ped file, which means the usual access mechanisms 
apply.

Michael.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Access GPIO pins on RPi2 without root?

2015-10-07 Thread Mark Morgan Lloyd

Jonas Maebe wrote:

Bo Berglund wrote on Wed, 07 Oct 2015:


I think that it really does because there must be some interface
between the FPC system and the underlying operating system managing
the hardware.


On Linux/Unix, every interface to hardware gets exposed as a file 
(generally under /dev). Sometimes you have libraries that provide a 
higher level interface, but in the end it will always access that file. 
If you need root permissions to perform actions on this file with 
language X, you will also need them with language Y and also if you use 
library Z to access it. The file operations are basic POSIX operations 
(open, read, write, ioctl, close), which are available with an "fp" 
prefix via the baseunix and unix units, and which are the same in C or 
other languages.


If you have a library that you want to use, then you can of course ask 
here whether anyone has translated the headers for it (which will 
probably be in C) to Pascal or so.


I've just been taking a look and I don't immediately see a kernel module 
that provides an interface to GPIO via /dev. I think there's things for 
I2C etc.


Via 
http://wiki.freepascal.org/Lazarus_on_Raspberry_Pi#1._Native_hardware_access 
I see mention of /sys/class/gpio etc. although I've not looked to see 
what's implemented as standard. Using this interface requires membership 
of the gpio group, which in principle answers Bo's question.


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


[fpc-pascal] How to duplicate PHP's gzcompress() function in FPC?

2015-10-07 Thread Graeme Geldenhuys
Hi,

I need to compress a file the same way as PHP's gzcompress() function:

   http://php.net/manual/en/function.gzcompress.php

>From that URL it uses ZLIB, and that is apparently different to GZIP and
DEFLATE, because PHP also has a gzencode() and gzdeflate() functions
respectively.

It seems the key point, from want I understand in the URL text, is that
ZLIB compresses the data and has no Header Information, where GZIP does
similar, but has Header Information.

I'm still unclear as to the the differences between ZLIB and DEFLATE - I
always assumed them to be the same thing.

Anyway, so what is the equivalent to gzcompress in FPC? I see in the FCL
there is a zlib.pp unit, but in the code comments in takes about
wrapping the compressed data with gzip. So I'm not sure if this is then
equivalent to PHP's gzcompress().

Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to duplicate PHP's gzcompress() function in FPC?

2015-10-07 Thread Graeme Geldenhuys
On 2015-10-07 16:51, Dmitry Boyarintsev wrote:
> The difference is mentioned in deflateInit2() functions, where a user can
> specify windowBits. If the value is negative, to Gzip header would be
> generated.
> 
> I presume the gzcompress is passing negative value to the function, while
> gzencode passes a positive value to the function.


I'm actually experimenting that that (or similar) right now I
already use TCompressionStream included with FPC, and I see its
constructor has an option ASkipHeaders which defaults to False. I'm now
setting that parameter to True and will soon see if that works for my
code or not.


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to duplicate PHP's gzcompress() function in FPC?

2015-10-07 Thread silvioprog
On Wed, Oct 7, 2015 at 12:26 PM, Graeme Geldenhuys <
mailingli...@geldenhuys.co.uk> wrote:

> Hi,
>
> I need to compress a file the same way as PHP's gzcompress() function:
>
>http://php.net/manual/en/function.gzcompress.php-pascal
> 
>
[...]

About compress a string with GZ, this one[1] show how to compress streams,
that can be used to compress strings too, via something like TStringStream.
=)

I believe that this example is compatible with 2.6.4+.

[1] http://www.gocher.me/GZIP

-- 
Silvio Clécio
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] How to duplicate PHP's gzcompress() function in FPC?

2015-10-07 Thread Graeme Geldenhuys
On 2015-10-07 16:56, Graeme Geldenhuys wrote:
> constructor has an option ASkipHeaders which defaults to False. I'm now
> setting that parameter to True and will soon see if that works for my
> code or not.

That didn't work for my experiment. :-/


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to duplicate PHP's gzcompress() function in FPC?

2015-10-07 Thread Dmitry Boyarintsev
Not sure about, if there's an equivalent function, but the difference with
Gzip and Deflate is the following.
Gzip contains an information about the original file + deflate (compressed)
stream of data.
Default is just stream of data.
For example ZIP files are using Deflate, but not using Gzip headers
(providing their owns).

The difference is mentioned in deflateInit2() functions, where a user can
specify windowBits. If the value is negative, to Gzip header would be
generated.

I presume the gzcompress is passing negative value to the function, while
gzencode passes a positive value to the function.

thanks,
Dmitry

On Wed, Oct 7, 2015 at 11:26 AM, Graeme Geldenhuys <
mailingli...@geldenhuys.co.uk> wrote:

> Hi,
>
> I need to compress a file the same way as PHP's gzcompress() function:
>
>http://php.net/manual/en/function.gzcompress.php
>
> From that URL it uses ZLIB, and that is apparently different to GZIP and
> DEFLATE, because PHP also has a gzencode() and gzdeflate() functions
> respectively.
>
> It seems the key point, from want I understand in the URL text, is that
> ZLIB compresses the data and has no Header Information, where GZIP does
> similar, but has Header Information.
>
> I'm still unclear as to the the differences between ZLIB and DEFLATE - I
> always assumed them to be the same thing.
>
> Anyway, so what is the equivalent to gzcompress in FPC? I see in the FCL
> there is a zlib.pp unit, but in the code comments in takes about
> wrapping the compressed data with gzip. So I'm not sure if this is then
> equivalent to PHP's gzcompress().
>
> Regards,
>   - Graeme -
>
> --
> fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
> http://fpgui.sourceforge.net/
>
> My public PGP key:  http://tinyurl.com/graeme-pgp
> ___
> fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
> http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
>
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] How to duplicate PHP's gzcompress() function in FPC?

2015-10-07 Thread Graeme Geldenhuys
On 2015-10-07 17:22, Graeme Geldenhuys wrote:
>> > constructor has an option ASkipHeaders which defaults to False. I'm now
>> > setting that parameter to True and will soon see if that works for my
>> > code or not.
> That didn't work for my experiment. :-/


Correction, I made a silly mistake in my code. I've managed to get it to
work with TCompressionStream and with ASkipHeaders = False (the default).

Thanks for everybody's feedback on this.


Regards,
  - Graeme -

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] How to duplicate PHP's gzcompress() function in FPC?

2015-10-07 Thread silvioprog
On Wed, Oct 7, 2015 at 1:42 PM, Graeme Geldenhuys <
mailingli...@geldenhuys.co.uk> wrote:
[...]

> Correction, I made a silly mistake in my code. I've managed to get it to
> work with TCompressionStream and with ASkipHeaders = False (the default).


The link that I sent has a nice explanation (and tests) about GZIP header:

"GZip:
2 bytes $1f $8b  (IDentification)
1 byte $08 Compression Method = deflate
1 byte $00 FLaGs bit 0   FTEXT - indicates file is ASCII text (can be
safely ignored) bit 1   FHCRC - there is a CRC16 for the header immediately
following the header bit 2   FEXTRA - extra fields are present bit 3
FNAME - the zero-terminated filename is present. encoding; ISO-8859-1. bit
4   FCOMMENT - a zero-terminated file comment is present. encoding:
ISO-8859-1 bit 5-7   reserved
4 bytes $ Modification TIME = no time stamp is available"
More ... 

-- 
Silvio Clécio
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal