Sunday, 28 December 2014

Building Apps with MerOBS and Github using Webhooks


So you've heard about this OBS thing and it sounds like a good idea but how do you use it? If you already use Github then getting the MerOBS to work for you is really easy, and will automatically build release RPMs for your tagged Github releases.

What is MerOBS?
build.merproject.org is an Open Build Service useful for compiling programs in a standardised and repeatable way for SailfishOS. Using MerOBS to build your app for release is a good idea, and allows it to be added into other community distribution repositories like Chum.

Sounds cool, how do I set it up?
I am assuming you are already set up with your project on Github, as it seems to be the most popular of source control SaaS platforms out there.

1. Get yourself a MerOBS login
To register for the OBS you need to get yourself a Mer Bugzilla login and wait a few minutes after creation to allow it to sync across to the OBS.

2. Create your home project
Once you've logged into the MerOBS you will need to set up your home project. This is your own personal area on the OBS which you can develop your build packages as well as distribute apps for testing by direct download or adding your repository URL into pkcon/zypper on your SailfishOS device.

3. Add SailfishOS repository to your Home Project
Once you're in your Home Project, go to the Repositories tab and add SailfishOS Latest. This tells all packages in your Home Project that you want to build them for SailfishOS.

4. Create a Package for your App
Back on the home screen for your Home Project, give it the name of your Sailfish App package and a brief description.

5. Add user cibot to your package maintainers
In your Package, go to the Users Tab and add user cibot to your package with the role maintainer. This is the user which receives Webhook events from Github and makes the magic happen.

6. Add _service file
Create a file on your computer with your favourite text editor named _service (be careful to remove any file extentions on windows).

in this file we will insert some XML, using the Github URL for your Sailfish App repository.

 <services>
   <service name="webhook">
     <param name="repourl">https://github.com/[your_user]/[your_app_repository].git</param>
     <param name="branch">master</param>
   </service>
 </services>

 and upload this _service file into your MerOBS package using the 'Add File' menu.

7. Configure Webhooks in Github
We need to configure Github to send Webhooks to the MerOBS when a new release is tagged. To do this open up your Github repository and go to Settings > Webhooks & Services > Add a Webhook.

Use https://webhook.merproject.org/webhook/ as the Payload URL

These following items should be set to default, but just check:
  1. Content type should be application/json
  2. Enable SSL verification
  3. Enable Just the push event
  4. Enable Active

8. Tag a release and watch it build!
By this point if you have already tagged a release on your Github project, then the latest release should be building on MerOBS. Otherwise create a release in Github using the releases menu and once that's completed have a look back at your package in MerOBS and there should be extra files there now and a build status on the right side.

9. So it says it built successfully, now what?

You can add your MerOBS repository to your SailfishOS device through Terminal
ssu ar merobs-[your_user] http://repo.merproject.org/obs/home:/[your-user]/sailfish_latest_armv7hl/
pkcon refresh

and from there you should be able to install your newly built app using:
pkcon install [your-package-name]

10. Enjoy your automatic MerOBS Builds!
Now whenever you tag a new release MerOBS will build it for you, and from there you can download it and release on OpenRepos, install it using pkcon from your Home Project, upload it onto your Github, whatever you want really!

If you need help with the MerOBS best place is to pop into #mer on irc.freenode.net

Saturday, 30 August 2014

SirenSong Music Player for SailfishOS

I've been working on a Music Player App for SailfishOS largely due to the fact that there isn't a lot to choose from currently and there seems to be a reasonable demand for a good Music Player aside from the stock one from Jolla.

Currently this Music Player is fairly basic and no configuration options, but it provides simple but effective library navigation and playback features.

SirenSong v0.2

https://github.com/r0kk3rz/SirenSong-Media-Player

https://openrepos.net/content/r0kk3rz/siren-song-music-player




Features

  • People Style List Menu for large library support
  • Random Infinitely Queuing Playlist
  • Next/Play/Pause Cover Actions 
  • Headset Buttons Functionality

To Be Implemented 

  • Album/Artist/Genre Sorting Options
  • Search Functionality
  • Playlist Management
  • Equalizer
  • DBus Interface
  • Headphone Jack Events Detection
  • App Drawer Icon
  • Lots...

Known Issues

  • Maybe memory issues if left running for a long time

Monday, 11 August 2014

Qt5Sparql and Tracker

Tracker is a service that runs in the background and collects information about things that are on the phone and stores it all into a Sparql database. On the Jolla, Tracker is used for things like the Gallery App and the Media App, so if you wanted to create a gallery or a music player app half the work is already done for you.

You can query the Tracker database from the command line using the tracker-sparql command
eg. tracker-sparql -q "SELECT
?title ?artist ?length ?album
WHERE { ?song a nmm:MusicPiece .
    ?song nie:title ?title .
    ?song nfo:duration ?length .
        ?song nie:url ?url .
    ?song nmm:performer ?aName .
    ?aName nmm:artistName ?artist .
    ?song nmm:musicAlbum ?malbum .
    ?malbum nmm:albumTitle ?album
    FILTER regex(?title, '^A', 'i')
}"


This is a select query that will return info about the music files indexed by tracker, notice the FILTER line is a regex that will only return items that start with 'A'.

Another cool type of query is the ASK query, which will return true or false depending on whether any results exist
eg. tracker-sparql -q "ASK {
    ?song a nmm:MusicPiece .
    ?song nie:title ?title
    FILTER regex(?title, '^A', 'i') 
}"


Sound great! But how do you use it?

First thing is you need to install the Qt5Sparql libraries into your development environment

You can do this by opening your project in QtCreator and
  1. Click on SailfishOS on the side menu
  2. Under Targets click Manage Target on your desired environment
  3. In the search area, type in sparql
  4. Install all shown packages
Once you've done that you need to add QtSparql to the CONFIG area in your .pro file

In your QML file you can now write import QtSparql 1.0, but it will still have a red line underneath it with a "QML Module does not contain information about components contained in plugins" error. This error can be ignored and will still compile and run, but the QtCreator IDE will not autocomplete for you. If you want to fix the error then you need to use a qmlplugdump program to generate the required file, but it doesn't come with the SailfishOS SDK and I couldn't be bothered trying to compile it myself from source.

Instead you can use the git repository as documentation on the objects and what signals/properties/methods they have

https://github.com/nemomobile/libqtsparql/tree/master/src/sparql

Also in there is a bunch of examples which are fairly handy

https://github.com/nemomobile/libqtsparql/tree/master/examples/sparql

Example Code

The easiest way to get going is with something like the following, its a ListModel QML object that gets its ListItems from Tracker using a SPARQL query

SparqlListModel {
   id: queryModel
   objectName: queryModel
 
   // create a new SparqlConnection for the queryModel
   connection: SparqlConnection { id:sparqlConnection;  
                                  objectName:"sparqlConnection";  
                                  driver:"QTRACKER_DIRECT" }

   // This is the query for the model

   query: "SELECT ?title ?artist ?length ?album ?url "+
      "WHERE { ?song a nmm:MusicPiece . "+
      "?song nie:title ?title . "+
      "?song nfo:duration ?length . "+
      "?song nie:url ?url ." +
      "?song nmm:performer ?aName . "+
      "?aName nmm:artistName ?artist . "+
      "?song nmm:musicAlbum ?malbum . "+
      "?malbum nmm:albumTitle ?album "+
      "} "
}

Thursday, 31 July 2014

i2c breakout TheOtherHalf

I started modifying my Shapeways 3d printed TheOtherHalf cover to provide an easy way to wire up the pogo pins on the Jolla to a breadboard or protoboard.

The whole thing is fairly simple, I started off with some copper tape to act as contacts for the pins and ran the strips of copper tape to the back of the cover.



I then cut up some wires bent them into the rough shape I wanted and used epoxy resin to fix them to the back of the case, making sure to hold the wire to the copper contact pad as the resin cured.

Next steps are to terminate the wires into a 4 pin plug, and to figure out a way to fix the wires to the contact pads in a more solid way, at the moment they are just sitting there and continuity is ok but I would prefer something that will give a more reliable connection.


For a first attempt I think this will be workable, I made friends with the guys at the Newcastle Makerspace who have a lot of equipment including 3d printers so I should be able to make something a bit better

The Other Half from Flypig @ Shapeways

 I wanted something I can use as a TheOtherHalf development platform to drill holes in a and glue stuff on to get easy access to the pogopins on the Jolla, and I didn't really feel like destroying the original cover it came with.

Since there is currently an extreme lack of options for TheOtherHalf covers for the Jolla phone, I thought I would order one of the ones from Shapeways 3D printing service as its readily available and less expensive than buying one directly from Jolla.

Initial impressions are fairly poor to be honest, I expected the finish to be a bit rough but the whole thing feels super thin and flimsy, likely to snap with much use, (un)fortunately the case takes very little effort to take on and off the phone so less force needs to be applied than the original cover.

This can probably be remedied in two ways, creating a new shapeways object that is thicker on the back and sides than the original case, but more sturdier as a result. or using something like thin fiberglass to cover the back and sides to give it a bit more rigidity. 

With that in mind, the fact that nobody has used the supplied 3d files in TheOtherHalf SDK and sent them off to an injection molding manufacturer is rather surprising, I might start a conversation with Jolla to see if there is any requirements they have in using the provided files in a commercial manner.



Sunday, 20 July 2014

Contacts List UI

Navigating long lists is something that the Jolla doesn't do very well (Media app is a prime example), except in one specific case: The People App.

The problem is that this alphabetic sorted list type menu is heavily baked into the app itself and is only really useful for displaying contacts without a lot of hacking. Ideally I would like to get it to be something flexible that can be customised for specific purposes though Silica components.

Since it seems like something that would be useful for Sailfish app developers to use, I've started to break the menu out into something generic that can be used to display a list data type

https://github.com/r0kk3rz/sailfish-alphabet-sort

All the good stuff is in the qml/pages directory, the rest is just the standard sailfish stuff to get it to run on the device.

The menu is mostly broken out into a standalone object, with the Example.qml showing an example of how to create the menu and get it to display something.

I've made it so the inner menu is passed in as a Component so you can easily customize the look to fit your data.

Aside from the top level A-Z menu, the rest is procedurally generated which is good. It might need some performance tweaks for large lists as the way it generates sublists is fairly inefficient at present

i2c on the Jolla Phone

As part of TheOtherHalf the Jolla has a two wire i2c bus accessible by jump pins on the back, but how to get started with it?

There's plenty of resources around the hobby electronics community about i2c and how to go about using it on linux based devices like the Raspberry Pi and the Beagleboard, and the Jolla is a linux based device so I figured it should be fairly similar.

First Problem

All the guides I've found reference this command line package i2c-tools, which at first doesn't seem to be available on the Jolla through pkcon or any of the third party repositories. Turns out the package works fine you just have to compile it from source on the Jolla, which of course requires installing make, gcc, gcc-c++ via pkcon (if you don't know how, follow this).

Might be an idea to get it submitted to the usual Jolla repository or in mer-tools or something, but thats a story for another day.

Make sure you install it using devel-su otherwise it will fail, but once thats done you can now probe the i2c bus using  i2cdetect -r 1 (/dev/i2c-1 is the i2c port on the jolla) which will probe the i2c bus for connected devices.

This is the output of the Jolla with no devices connected, as you can see the 50x00 to 50x07 addresses are already in use, but all others are free for use.

the i2ctool app on the Jolla Store by kimmoli does mostly the same stuff as i2c-tools, but from a silica app rather than the command line.

Where to Next?

Next I need to actually wire up some i2c devices and try and talk to them using C++ or Python, I'm still deciding which i2c module to buy as there's a fair few out there, currently thinking of making a GPIO breakout TheOtherHalf using one of these i2c GPIO expanders, which should allow some very flexible prototypes with the Jolla.