duminică, 16 noiembrie 2014

Lazarus / FPC - some of my work

Here are some programs that I am working with. I hope someone will find some of them useful

https://www.dropbox.com/sh/d5bw7h3j33vmu5t/AAARZeUlm4pvHHJwnqUEn4Jqa?dl=0

Raspberry Pi - Fixing some USB issues

    The USB ports appear to be somehow unstable on Raspberry Pi. A complete explanation and a solution that worked for me can be found here:

   http://ludovicrousseau.blogspot.ro/2014/04/usb-issues-with-raspberry-pi.html

In short, this is what I did:

1. Start a file manager with root privileges
        sudo thunar        (thunar is my file manager)

2. Edit the file /boot/cmdline.txt and add dwg_otg.speed=1  Your file should look like this:
   dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200
   dwc_otg.speed=1 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4
   elevator=deadline rootwait

3. Save and reboot

PS: I have a ASIC USB Miner for bitcoins that I'm running on Raspberry Pi just for fun (it didn't produced anything so far and I'm not expecting it to do so). The solution above appears to fix the stability of the system (it was freezing every 5-10 hours, now it's working non-stop for about 2 days)


vineri, 7 noiembrie 2014

OpenSuSE 13.1 / VLC error: No suitable decoder module

I've just switched from OpenSuSE 12.3 to 13.1 and I got this problem. VLC won't play a video file and returned the following error:

"No suitable decoder module: VLC does not support the audio or video format "mp4v". Unfortunately there is no way for you to fix this."

Fortunately, there is a way to fix this, and here is how:

1) Completely remove all VLC files with the following command (open a terminal and type):
sudo zypper rm libavc1394-0 libavutil52 libcaca0 libcddb2 libdirac_encoder0 libdvbpsi7 libdvdnav4 libebml4 libgme0 libmatroska6 libmodplug1 libshout3 libslang2 libswscale2 libupnp6 libvlc5 libvlccore7 libxcb-xv0 libzvbi0 vlc-noX vlc-noX-lang vlc-qt

2) Install VLC with OneClick Install from VLC's home page

That's all!



sâmbătă, 1 noiembrie 2014

OpenSUSE 13.1 / older nVIDIA cards / nVIDIA GeForce G105M

    I have a laptop ACER with nVIDIA GeForce G105M videocard. Yes, it is about 5 years old and I have a lot of problems with OpenSuSE (12.x, 13.1) and nVIDIA drivers.
     I have covered some issues in a previous post when I posted a config file example.
     My videocard requires the nVIDIA G02 package. However, some programs insist to install the nVIDIA G03 package (I don't know why), so I have to be very careful. If the 03 package is installed it will mess up the entire system (OpenGL not working anymore, multiple images of the desktop on the laptop's display). I tried to ban the installation of the 03 package but it didn't seem to work, so the only option is to check very carefully every installation (why is Mozilla Thunderbird trying to install video drivers I can't imagine).

    So far, OpenSuSE 13.1 is working (almost) properly: KDE desktop is not working with OpenGL when I attach a monitor to the laptop (yet other programs that requires OpenGL are working; I can live with that)

luni, 8 septembrie 2014

OpenSuSE 12.3 / MS fonts

... because sometimes you just need "Arial" and "Times New Roman". In order to do that, just install the package fetchmsttfonts  

sâmbătă, 12 iulie 2014

Lazarus FPC / Indy 10 / HTTP / HTTPS (OpenSuSE 12.3)

Can FPC/Lazarus be used to create a web server? Yes, it can! Can it be done in a secure mode? Of course!

1) A simple HTTP server

On a form drop a TIdHTTPServer component from "Indy Server Protocols (am)". Assign a free port to that (let's say 1800) and a "OnCommandGet" event (it will not work without it). A simple example for OnCommandGet:

AResponseInfo.ContentText:= '<!DOCTYPE html>'+
    '<html>'+
    '<body>'+
    'This is a web page! <br>'+
    '</body>'+
    '</html>';

To start the server add the following lines in form's OnShow event:

      hserver1.Bindings.Add.IPVersion:=Id_IPv4;
      hserver1.Active:=true;

(where hserver1 is the name of the TIdHTTPServer component)

Run the program, open a web browser and type the network address of your computer, like this:
   http://192.168.1.100:1800
It should display a white page with the message "This is a web page!"
Make sure the firewall is not interfering (it will be covered in another post)

Some tips for OnCommandGet:

- To read the parameters passed by the client:
      ARequestInfo.queryparams;

- To read the host's address:
     ARequestInfo.Host;

- To read the client's ip:
     Acontext.Binding.PeerIP;

 - To pass a document to the client (let's say it is required like this: http://192.168.1.100:1800/document.doc):
     var t:widestring;
     [...]
     t:=copy(ARequestInfo.document,2,99);
     if t='document.doc' then
         aresponseinfo.servefile(acontext,'document.doc');

The file documet.doc must be in the same place as the executable; if not, you can use the full path like this:
aresponseinfo.servefile(acontext,'c:\Documents\document.doc');

- To display a picture on your web page (let's say it is required like this: http://192.168.1.100:1800/img1.gif) use the following piece of code:
          var t:widestring; s:tmemorystream;
     [...]
     t:=copy(ARequestInfo.document,2,99);
     if t='img.gif' then
       begin
        s:=tmemorystream.create;
        s.loadfromfile('img1.gif');
        AResponseInfo.ContentType:='image/gif';
        aresponseinfo.ContentStream:=s; 
       end;


2) HTTPS - a secure connection

(1) In order to create a secure connection OpenSSL is required.
- OpenSUSE - open YaST and install the following packages: openssl, libopenssl-devel. A restart might be required.
- Windows - the required program can be found freely on the Internet, just google for "windows openssl" (I found this: https://www.openssl.org/related/binaries.html); download, install and restart.

(2) Now a private key and a certificate must be created. It will not work without that. The full documentation can be found here:
     https://www.openssl.org/docs/HOWTO/keys.txt
     https://www.openssl.org/docs/HOWTO/certificates.txt
In short, these are the steps to do just that (the OpenSuSE way):
    - Open Dolphin and go the directory where your program is
    - Open a terminal window
    - Type openssl genrsa -des3 -out privkey.pem 2048
       You will be asked for a password, then the file privkey.pem will be created
    - Type openssl req -new -x509 -key privkey.pem -out cacert.pem -days 1095
        You will be asked for the password of the private key created in the previous step and then for some informations that will be included in the certificate (name, country, etc.), then the file cacert.pem will be created

(3) Back to our program, drop a TIdIOHendlerSSLOpenSSL component from "Indy I/O handler Protocols" on the form with the TIdHTTPServer component (see the first part of this post). I also droped a TIdAntyFreeze component and set it active, I don't know if it helped or not.
Let's configure the components:
 - Check the "Method" property of the OpenSSL component, it should be set to "sslvTLSv1"; if you have problems with the connection and nothing else is working, you may try to select a different value for that property.
 - Assign the TIdHTTPServer component's property "IOhandler" to your OpenSSL component (select the OpenSSL component for that property)
 - Assign  the password of your key to the SSL component at Events> OnGetPassword like this (xxxxx is your key password):
          password:='xxxxx';
 - Assign the key and the certificate to the SSL component before you start the server. So, the OnShow event of the form should contain the following:

     ssl1.SSLOptions.KeyFile:='privkey.pem';
     ssl1.SSLOptions.CertFile:='cacert.pem';
     ssl1.SSLOptions.RootCertFile:='cacert.pem';
     hserver1.Bindings.Add.IPVersion:=Id_IPv4;
     hserver1.Active:=true;

      ssl1 is the name of the TIdIOHendlerSSLOpenSSL component.

Everything goes just like in the first part of this post with one exception: now you will access the page from a web browser by typing:
     https://192.168.1.100:1800
Be aware that the OpenSSL component might generate various exceptions in debugging mode, so if it doesn't seems to work try to build your program and run it without the debugger

joi, 1 mai 2014

OpenSuSE 12.3 / Mozilla Firefox / Error: sec_error_no_token

After some attempts to update Mozilla Firefox on my OpenSuSE 12.3 I was stuck with the following situation: Firefox was working, but when I tried to access a secured page (even Google) the following error occurred:

"An error occurred during a connection to mail.google.com. The security card or
token does not exist, needs to be initialized, or has been removed. (Error
code: sec_error_no_token)
The page you are trying to view cannot be shown because the authenticity of
the received data could not be verified.
Please contact the website owners to inform them of this problem.
Alternatively, use the command found in the help menu to report this broken
site
."

My solution is:

1) Download the latest Mozilla Firefox from http://www.mozilla.org

2) Decompress the archive somewhere (in Documents, for example)

3) Start Dolphin as Superuser (you will need Root access)

4) Copy the content of the folder that you've extracted to /usr/lib/firefox/

Now it should work!

duminică, 23 februarie 2014

Raspberry Pi - The Beginning

I got my hands on a Raspberry Pi board. After reading about it on the internet, I decided to evaluate it myself. In this part I will write about the installation process and my first impressions. Unfortunately I couldn't install OpenSUSE on it, but I promise to try it in the near future.

Hardware

I have the "B" model, with 512 MB RAM and network adapter. To make it work, you need in addition:
     - SD card (not microSD); I recommend at least 8 GB and... the faster, the better; I use a 16 GB one
     - SD card reader on your desktop/laptop computer, so that you can write on the SD card the OS
     - power source - I ordered one with my Raspberry Pi board; it is powered trough microUSB and requires 5V and 1000mAh
     - HDMI cable to connect to monitor or TV (it has a "classic" TV output, I didn't test it)
     - USB mouse and keyboard
     - internet access - I have a router, I don't know if you can set up a connection trough dial-up or something similar

Installation

Using your desktop/laptop computer, you must download the OS. I took the easy way and downloaded the NOOBS version from the official site, here:
     http://www.raspberrypi.org/downloads

The SD card must be FAT formatted. As my SD card was new, it was formatted using FAT32. I didn't change that and it worked.

The containing files of the zip archive must be extracted to the SD card. Once finished, the SD card can be inserted in the Raspberry Pi board, the mouse, keyboard ant monitor must be connected and the device can be powered up. It does not have a start/stop button, so once you connect the power cable, it will start

If everything was done right, the system will present you a list of available operating systems to chose from. I tested the Debian-based Raspbian and the Fedora-based Pidora. The Raspbian is the "official supported" OS, it has a lot of packages and I think it was a little faster. For the moment I remained with Raspbian and I will refer to that one further.

The Raspbian

The OS installs itself without any problems. At a certain point a configuration window will appear, asking for some basic informations. I recommand that you change the password with your own and to enable "boot to desktop" I also overclocked the board from 700 to 800 MHz (it can be overclocked to 1000 MHz, I don't know if that's OK). I must say I saw the difference between 700 and 800. You can change those settings anytime later by typing "sudo raspi-config" in a terminal window.
Once the installation finished you are presented with the familiar Linux LXDE interface. Before anything else, an update is recommended, so open a terminal and type:
     sudo apt-get update
     sudo apt-get upgrade
In order to navigate easier trough the package system you may prefer the graphical variant of synaptic
     sudo apt-get install synaptic
I tried some more sophisticated interfaces (I use OpenSUSE with KDE on my daily basis) so I installed XFCE and KDE
     sudo apt-get install xfce4
     sudo apt-get kde-full
They both worked, but KDE is a little too heavy on resources (in my opinion) so it's slower and does not displays correctly all the colors and effects (I couldn't get the OpenGL to work, nor the widgets) so I remained with XFCE. During the installation of KDE I experienced system crash, I don't know why.

FPC/Lazarus

Yes, my primary motivation: can I work on Raspberry Pi? And the answer is... YES!
All I had to do was to install FPC/Lazarus. I couldn't do that on Pidora, but on Raspbian it was as simple as that:
     sudo apt-get install fpc
     sudo apt-get install lazarus
I copied one of my programs, compiled it and it worked! It even connected to a server using TCP/IP trough a non-visual lnet! I couldn't install the visual lnet component, but the non-visual worked flawlessly!

Next...

In the next days I will evaluate the multimedia and internet capabilities of the Raspberry Pi. I also want to determine how complicated can be to create a program for Android using FPC/Lazarus, since compilation for ARM is no longer a problem.


[UPDATE]

I strongly recommend to disable the screensaver, it seems to be the cause of crashes