Tuesday 5 February 2019

Compiling for Wallet and MasterNode

I have had few struggle to compile some wallets and here some handy information

Make sure you install the package which must be installed before compiling

sudo apt-get install libdb-dev libdb++-dev libboost-all-dev libqrencode-dev qt4-qmake libqtgui4 libqt4-dev automake

If you need to compile the GUI, make sure you have the QT packages otherwise the configure file will skip it

sudo apt-get install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools 

Another important dependency is the old version of DB, therefore you will have to install the 4.8 version. This is not a mandatory step because you can compile with the incompatible db flag, but it will not guarantee it will work.

sudo add-apt-repository ppa:bitcoin/bitcoin
sudo apt-get update
sudo apt-get install libdb4.8-dev libdb4.8++-dev

The incompatible flag is
./configure --with-incompatible-bdb


For Wallet:


  1. Clone the repo of the wallet
  2. Enter the root for the repo
  3. ./autogen.sh
  4. ./configure
  5. make


Once is finished you will have few executable files and under QT folder you will have the GUI version.

For Masternode:
  1. Clone the repo of the wallet
  2. Enter the root for the repo
  3. ./autogen.sh
  4. ./configure --without-gui 
  5. make


Issues:

checking whether htole64 is declared... yes
checking whether be32toh is declared... yes
checking whether be64toh is declared... yes
checking whether htobe32 is declared... yes
checking whether htobe64 is declared... yes
checking for MSG_NOSIGNAL... yes
checking for library containing clock_gettime... none required
checking for visibility attribute... yes
checking whether C++ compiler accepts -fvisibility=hidden... yes
checking for Berkeley DB C++ headers... default
configure: error: Found Berkeley DB other than 4.8, required for portable wallets (--with-incompatible-bdb to ignore or --disable-wallet to disable wallet functionality)

Solution:

/configure  --with-incompatible-bdb


Issue:

configure: error: Detected LibreSSL: This is NOT supported, and may break consensus compatibility!

Solution:

Install only one version of the SSL package, make sure you dont have multiple version
apt-get install libssl1.0-dev

Monday 13 November 2017

Touchscreen Raspberry Pi



Description
Raspberry Pi is a great machine that people want to make amazing stuff with it, and one great think is to use the a visual interface that you can get from the hdmi port.
In my case I wanted to have a screen and touch sensor to interact with a custom GUI.

Item

  • Innolux 7 with touch screen (link)
  • Raspberry Pi ( in my case version 2 )
  • Battery pack
  • USB to DC Jack


Installation

1) Driver
The good news is that Raspberry Pi has finally introduced a simple  system to enable touch screen with most common board on the market ( here a list ) but in my case I had to enable Egalax sensor.

To make sure your device is supported, just connect the usb and run ( make sure its the only device usb connected)
lsusb
and you should see the model and manufacture of the sensor.

In my case everything is supported, if your sensor is not supported, try to poke them on github otherwise you are forced to recompile the kernel with the driver built-in.

The module kernel ( if supported ) has to be enabled by running the command and the sensor connected in the usb slot:
 rpi-update
when the process will be completed, you should be able to access the device.

2) Testing
Make sure you have installed all the tools to test your sensor by running this command:
 sudo apt-get install evtest tslib libts-bin

When you have confirmed that, you have to find the right path to your device by looking into the folder /dev/input/.
The common path are  /dev/input/event0 or /dev/input/touchscreen, but make sure you dont have a keyboard or mouse connected otherwise it might be event1 , event2, etc.. 

After you have discovred the correct path, in my case /dev/input/event0, try to run the command:
sudo evtest /dev/input/event0
and you should see some values after you pressed the  touch screen.
If nothing happened, that means you sensor is not connected properly or the driver module is not loaded.

3) Calibrate
Now that you made sure that the device is plugged, module loaded and something is coming out from the device, you can run the first calibration command:
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 ts_calibrate
after this command has been launch, you should see a calibration screen where you are asked to press 5 different spots.

Once the calibration is completed, you should have a file at the location /etc/pointcal.

Double check that you can draw correctly with this command:
sudo TSLIB_FBDEVICE=/dev/fb1 TSLIB_TSDEVICE=/dev/input/event0 ts_test
then you are ready to go!

4) Issues
You might have some problems by using the device Egalax ( as I had ), which is the missing module in the latest build of  libts-bin ( probably if this guide is a few weeks older, this problem would have been solved ).

I couldn't run the calibration test because the software would close by saying "sensor not supported", this is because the build dint have the Egalax driver embedded in the build.
What you have to do, is to make sure libts-bin is removed from your system and purged all references, usually by using:
apt-get remove --purge libts-bin

Make sure you got all the software to compile the source code of libts:
sudo apt-get install git automake libtool

Checkout the repository ( apparently the patch for the driver has been included on the main repo ):
git clone git://github.com/kergoth/tslib.git
cd libts
and compile
./autogen.sh
./configure
make
sudo make install

then follow the guide here that is just moving the library in the right folder: https://myraspberryandme.wordpress.com/2015/02/12/making-an-egalaxpollin-touchscreen-work-with-tslib/ (pointless to re-write what this guy did best )

Once you finished, you should be able to run ts_calibrate without any errors.

Also, you might want to change some parameters into /etc/ts.conf.

Pygame without X server

You small game, application, script or else dont always need to have a X server running just to access to the graphical unit.
The trick is to use pyscope, offered by Adafruit ( link ), that is a simple class which makes sure your software will inject the output of pygame into the frame buffer.

In my case I had to add few environment variables to make sure that the touch screen would work with pygame:

#Reference to the calibration file
os.putenv('TSLIB_CALIBFILE', '/etc/pointercal')
#Point to the right library folder
os.putenv('TSLIB_PLUGINDIR', '/usr/lib/arm-linux-gnueabihf/ts')
#Setup the touch screen
os.putenv('SDL_MOUSEDRV', 'TSLIB')
os.putenv('SDL_MOUSEDEV', '/dev/input/event0')
otherwise the pointer would be jumpy or not following correctly as the ts_test was showing.

Saturday 5 November 2016

Send AGPS to UBLOX

I wanted to send AGPS data to my UBLOX CAM-M8, so get a faster fix as the chip doesnt have a eeprom to save the data and not even a battery backup.
I understood that every chip needs to download a map of where all the satellites are in the space and then based on that information, the chip can triangulate the position.

The great information is that UBLOX provides a free access to the AGPS servies which you will need to provide a close location ( latitude and longitude) and then a file is generated.

To send this file, you will need to parse the data and send the message via Serial and because I couldnt find anywhere a sample code, I tried to code something which actually worked.

The real sending would be too check the ack message, but this worked fine for me.

Saturday 7 November 2015

PN53x with Raspberry Pi and Python


Install libnfc on your raspberry pi by following Adafruit guide , make sure you are using the Serial pins and shorted the right pins on the board, check the version of the PN53x to short the right ones.

Install the library NFCPY which allows you to read and write through libnfc a nfc tag.


To decode a message:


To write a message

Saturday 18 July 2015

[Arduino] Timestamp function

Arduino don't have the function which convert hhmmss and ddmmyy to unix timestamp and because I was looking to combine my data to one universal time, I did't find a method to achieve that.

I came across to the library TIME which is a good library but because I had to optimise my code and have the sketch as small as possible ( developing for Arduino pro mini ), I extracted the necessary function  and variables to generate timestamp.
The file is available on my github here and this is how you can use the function:

From the date:01.06.2015 and time 20:10:00 you will have call the function like this:



and it will return a long number which is unix timestamp.

Saturday 13 December 2014

Remove Passphrase from SSH Key


Most of the time you create a ssh key for your GIT or SSH login and you wished the system wouldn't ask the password each time, and here there is a solution to it.

openssl rsa -in private_key_with_pass_phrase -out private_key_without_pass_phrase
WARNING: a pass phrase is an added layer of security in case you loose control of your private key. Think carefully about removing the password.

Just replace the old key with the new one and you solved your problem.

Sunday 26 October 2014

J/Box2D first steps

I came across to use JBox2D and I didnt know anything about how a physical engine works, so I am writing some helpful tips here.

Scale and dimensions

Firstable you have to keep on your mind that Box2D works with meters, so forget pixel or dpi, you will need to use some functions to convert these measurements to something that the engine can understand.
In general people use a scale, because the engine works in a world of 100x100 meters, so its better to have it as small as possible. The common scale is 30.

Here a simple way to convert pixel to Box2D dimensions:


Create a simple ball

Let's start with the second step, you have to define all properties of the object, if its a ball, it has to have  round shape and be elastic.

So you have to define the body definition, if the object will be static or dynamic  and set the position in the world:


The position might be tricky to understand, but here is a simple solution:
When you want to draw something in a canvas, you draw something from position (X,Y), so if you want to draw something at the top left corner, you will choose (0,0).
So in this thinking you would put new Vec2(0,0) in this case, but this will be WRONG because in Box2D everything works in another way, you have to tell the position of the centre of the object.

If you object is  10x10 and you want to position to the top left corner, you position will be (5,5).

To continue the body creation, you have to tell the world that this object exists in the engine, so you have to call the method "createBody"


Then tell at the body, what kind of shape your object will be:


In this case we create a CircleShape, because its a ball. In other case you have to use PolygonShape to create a special shape or a simple square.

Another tricky to understand how to create a PolygonShape for a square is the follow:

You have to use "setAsBox", and the dimension that you put inside must to be half of the width and half of the height, because the BodyDefinition has the position of the centre of the object.

Last thing to complete the creation of the ball in the world is the Fixture Definition:


You can change the density, that is the weight of the object, the friction between objects and the restitution that is the elasticity. Play with some values and you will find out what better works with your project.

Joints

Joints are parts that connects two body parts, there are different ones.
There is a joint to simulate a rope connection, an elastic connection, a rotation connection, etc...
You can find more information around in the web, it is very simple to use them but tricky to find the right values or anchor points.