Recent

Author Topic: locale from gps  (Read 10818 times)

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: locale from gps
« Reply #15 on: November 06, 2015, 07:06:33 pm »
Hi wp
Yes, I did, having come from many years of C! I can't get used to pascal being non case sensitive!

I have now hit another problem! I tried to set the system date using SetDate, but find that although the function exists in linux, it doesn't do anything!!! How can I set the system date from within my program, using the date from my gps fix? If I try to run the Date command as anexternal process, I won't have root privileges to execute it!

How linux makes the simplest things bloomin' impossible!!

Brian

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: locale from gps
« Reply #16 on: November 06, 2015, 07:30:04 pm »
Do you have the permission to set the date?

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: locale from gps
« Reply #17 on: November 06, 2015, 10:03:57 pm »
I don't know, but apparently setDate still won't work.

The only way I can see to possibly do it is to use something like the RunCommand to issue a date command, but I don't know about permissions or whether I could use sudo in the command.
As user pi, I normally either use sudo or sudo bash, when I need root privileges, but that's at a command prompt, not in LXDE.

I am quite new to linux and so get easily confused!

Thanks

Brian

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: locale from gps
« Reply #18 on: November 07, 2015, 12:44:00 am »
I investigated a bit and wrote this procedure which you can use to add (or subtract) the specified hours to (from) the system time - it works in Linux Mint:
Code: Pascal  [Select][+][-]
  1. procedure SetLocalTime(HoursOffset: Double);
  2. var
  3.   dt: TDateTime;
  4.   output: String;
  5. begin
  6.   dt := now() + HoursOffset/24;
  7.   RunCommand('date', [FormatDateTime('mmddhhnnyyyy', dt)], output);
  8. end;
  9.  

Since you need root priviledges to change the system clock I think it easiest to run your entire program as root (sudo yourprogram).

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: locale from gps
« Reply #19 on: November 07, 2015, 09:40:06 am »
Hi wp, Thanks very much for that. One question though, how do I run the program from within LXDE as sudo? At the moment, I simply double click the icon in File Manager, but once finished, I will make it start automatically when LXDE starts.

Thanks very much for your efforts.
Brian

christian1987

  • New Member
  • *
  • Posts: 30
Re: locale from gps
« Reply #20 on: November 07, 2015, 10:08:32 am »
You can edit /etc/sudoers so that a password is not required to use:
sudo echo Hello World

After that, make a wrapper, which just call
sudo yourApp

Good luck!

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: locale from gps
« Reply #21 on: November 07, 2015, 05:48:43 pm »
Hi, Thanks for your suggestions. I have looked at the sudoers file and I am lost! Could you be more explicit please and what is a wrapper?

Thanks

Brian

wp

  • Hero Member
  • *****
  • Posts: 11923
Re: locale from gps
« Reply #22 on: November 07, 2015, 11:23:03 pm »
Some time ago there has been a contribution in this forum how to elevate user privileges in Linux (http://forum.lazarus.freepascal.org/index.php/topic,14479.msg81824.html#msg81824). Based on this post, please test the following code which advances the system clock by 1 hour and works fine in Linux Mint 17.1. With this modification you can run your program as ordinary user, no sudo required, no messing around with /etc/sudoers. The program will pop up a box requesting the root password:

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   output: String;
  4. begin
  5.   RunCommand('pkexec', ['date', FormatDateTime('mmddhhnnyyyy', now+1/24)], output);
  6.   Memo1.Lines.Add(output);
  7. end;

BLL

  • Sr. Member
  • ****
  • Posts: 276
Re: locale from gps
« Reply #23 on: November 08, 2015, 10:20:36 am »
Hi, Thanks for that - I will try it, but I would prefer not to have to enter a password every tie I start the program..

Brian

 

TinyPortal © 2005-2018