Bluetooth Breakdown: Sending gatttool commands from my Ubuntu Touch Phone!

Here I am, typing commands from my phone and controlling a Bluetooth Feather!

Of course, the moment of truth! The goal of this whole Bluetooth breakdown project was to figure out how to make my home made auto start work on my Ubuntu Touch phone. Well, here it is, working!

Although the interface could use a face lift.

Last we looked at this, we saw that we could write custom scripts to send the commands from the desktop computer to the BLE auto start, or use interactive mode of gatttool and do the work there. Now we can actually do the same from the terminal of the cell phone.

While this technically counts. We now need a snazzy program that just works with clicky buttons and that sort of thing. So, I suppose that will be the next phase of this project! Stay tuned for adventure!

Linux – keep it simple.

Advertisements

Bluetooth Breakdown: Sending my own commands with gatttool

Yes, there is purposely one too many t’s in GattTool.

bt_success

Last time we looked at the Bluetooth Low Energy (BLE) packets being sent from my Android app to my home made auto start. Here’s what we saw:

214231313a – Button 1 pressed
214231303b – Button 1 released
2142323139 – Button 2 pressed
214232303a – Button 2 released

With a little more digging, I also found that the “handle” is important, and per the Bluetooth packet breakdown in WireShark, that handle is 0x001a. Further, my particular Bluetooth feather’s MAC address is F4:64:8E:90:D8:C3.

With all of this in mind, I entered gatttool in the interactive mode, but I kept having trouble connecting to my device. With further research, I found an article on WordPress by a guy named Jack. He got me pointed in the right direction!

What I needed to do before connecting was this:

# btmgmt le on
# btmgmt bredr off

To set the computer’s Bluetooth manager to the proper Low Energy reading/writing state. Then I entered interactive mode while monitoring my auto start with a USB serial monitor. Here’s what I typed:

root@alaskalinuxuser-OptiPlex-7010:/home/alaskalinuxuser# gatttool -t random -b F4:64:8E:90:D8:C3 -I
[F4:64:8E:90:D8:C3][LE]> connect
Attempting to connect to F4:64:8E:90:D8:C3
Connection successful
[F4:64:8E:90:D8:C3][LE]> char-write-cmd 0x001a 214231313a
[F4:64:8E:90:D8:C3][LE]> char-write-cmd 0x001a 214231303b
[F4:64:8E:90:D8:C3][LE]> char-write-cmd 0x001a 2142323139
[F4:64:8E:90:D8:C3][LE]> char-write-cmd 0x001a 214232303a
[F4:64:8E:90:D8:C3][LE]> char-write-cmd 0x001a 214232303a
[F4:64:8E:90:D8:C3][LE]> char-write-cmd 0x001a 214231303b
[F4:64:8E:90:D8:C3][LE]> char-write-cmd 0x001a 2142323139
[F4:64:8E:90:D8:C3][LE]> char-write-cmd 0x001a 214232303a
[F4:64:8E:90:D8:C3][LE]> char-write-cmd 0x001a 2142323139
[F4:64:8E:90:D8:C3][LE]> disconnect

(gatttool:22352): GLib-WARNING **: Invalid file descriptor.

[F4:64:8E:90:D8:C3][LE]> disconnect
[F4:64:8E:90:D8:C3][LE]> exit
root@alaskalinuxuser-OptiPlex-7010:/home/alaskalinuxuser#

And here is what I saw on the monitor:

Less than 13v, Pin A3: 0.00
Less than 13v, Pin A3: 0.00
Less than 13v, Pin A3: 0.00
Less than 13v, Pin A3: 0.00
Button 1 released
Less than 13v, Pin A3: 0.00
startTimer 4
Less than 13v, Pin A3: 0.00
startTimer 3
Less than 13v, Pin A3: 0.00
startTimer 2
Less than 13v, Pin A3: 0.00

Success! Great! I was able to enter interactive mode, connect, and send the right commands! This is great!

Then I switched to non-interactive mode, by writing a custom script or two. This is the first one, to start the auto start:

#!/bin/bash

btmgmt le on
btmgmt bredr off
gatttool -t random -b F4:64:8E:90:D8:C3 –char-write-req -a 0x001a -n 214231313a
gatttool -t random -b F4:64:8E:90:D8:C3 –char-write-req -a 0x001a -n 214231303b
#gatttool -t random -b F4:64:8E:90:D8:C3 –char-write-req -a 0x001a -n 2142323139
#gatttool -t random -b F4:64:8E:90:D8:C3 –char-write-req -a 0x001a -n 214232303a
exit 0

And one to stop the auto start:

#!/bin/bash

btmgmt le on
btmgmt bredr off
#gatttool -t random -b F4:64:8E:90:D8:C3 –char-write-req -a 0x001a -n 214231313a
#gatttool -t random -b F4:64:8E:90:D8:C3 –char-write-req -a 0x001a -n 214231303b
gatttool -t random -b F4:64:8E:90:D8:C3 –char-write-req -a 0x001a -n 2142323139
gatttool -t random -b F4:64:8E:90:D8:C3 –char-write-req -a 0x001a -n 214232303a
exit 0

And a quick test was successful! Now I can send my commands to start or stop the auto start from the command line with my computer. Now it’s just time to set it up on my Ubuntu Touch phone!

Linux – keep it simple.

Video Tutorial on How to Compile Android and Modify Kernels

video

For those interested, I have just posted a video tutorial series on XDA for building Android Oreo, Nougat, Marshmallow, and Lollipop on 5 different phones, the emulator, and 5 different ROMs. Also included are custom kernel editing, adding apps, changing source code, backgrounds, and more. Here’s what I posted:

From XDA: https://forum.xda-developers.com/android/general/guide-how-to-build-custom-roms-kernel-t3814251

===========================================================================

Praise God! Finally a video tutorial of how to build Android and modify kernels!

I have created a video tutorial and guide for how to compile Android, from Lollipop through Marshmallow, Nougat, and Oreo. The video series covers several different phones, the emulator, kernel and rom editing, app source code editing, and much more!

Who is this video series for?
Well, this video tutorial is a step by step guide built primarily for the beginner. This is written for those who already know how to flash TWRP, CWM, or the like, and who have installed a custom rom before. This is designed to help those who are ready to move up from flashing and installing other peoples custom rom to actually start making their own custom roms. I recommend that a beginner watch the entire series in numerical/alphabetical order (the videos are marked).

That said, I believe that an intermediate developer may find a useful trick here and there, and they should just skip ahead to videos of interest. Perhaps kernel development, or something along those lines.

An advanced rom/kernel developer will probably far exceed my feeble abilities, and will not likely find much useful information here. Perhaps if you are an advanced developer, you would consider continuing the tutorial or making an advanced video series! (See further posts for recommendations on contributing videos.)

Why did you put this together?
Well, after building roms for several different devices, I started receiving requests from users who wanted to start building their own roms, but didn’t know how. I didn’t have enough time to answer everyones questions, so I wrote a few guides, pointed others to guides that were available, but there are some things that you just need to see to understand. Hence, the video tutorial. I just hope that someone finds it useful.

This course was written in order! While Lollipop and Marshmallow are old by today’s standards, there is still good learning value in building them, and there are topics covered there that really make them worth watching.

What’s in the videos?
During the series, we will be building for the emulator, as well as 5 different phones of various brands, and 5 different roms. I hope that this will give the viewer a good idea of how to build for their own specific phone as they see the differences and similarities across the phones and custom roms.

[CODE]
+ Ubuntu installation
+ Java installations
+ Using Git, GitHub, GitKraken, and the command line
+ Fastboot and ADB
+ Heimdall/Odin
+ QFIL, QPST, SALT, and other tools
+ AOSP, SlimRoms, PACrom, AOKP, AOSCP
+ Lollipop, Marshmallow, Nougat, Oreo
+ Errors
+ Overclocking CPU/GPU
+ Adding Governors and I/O Schedulers
+ Sound modifications
+ Changing app colors, text, and icons
+ Adding prebuilt apps
+ Adding source code
+ Converting device from one rom to another
+ AND MORE!
[/CODE]

**** This is an UNOFFICIAL TUTORIAL. Use at your own risk! ****
Download links:
Ogg Vorbis Video GitLab:
[url]https://gitlab.com/alaskalinuxuser/course_android_developer_guide[/url]
Clicking on a video in GitLab will allow you to watch it online.

Ogg Vorbis Video Downloads:
[url]https://gitlab.com/alaskalinuxuser/course_android_developer_guide/-/archive/master/course_android_developer_guide-master.zip[/url]
This download is rather large due to the multiple videos.

MP4 Video GitLab:
[url]https://gitlab.com/alaskalinuxuser/course_android_developer_guide_mp4[/url]
Clicking on a video in GitLab will allow you to watch it online.

MP4 Video Downloads:
[url]https://gitlab.com/alaskalinuxuser/course_android_developer_guide_mp4/-/archive/master/course_android_developer_guide_mp4-master.zip[/url]
This download is rather large due to the multiple videos.

I also have several written guides available on XDA, here are a few:

Building ROMs for the Galaxy Note Edge: [url]https://forum.xda-developers.com/note-edge/general/guide-build-aosp-roms-kernels-note-edge-t3488840[/url]
Building ROMs for the Galaxy S4: [url]https://forum.xda-developers.com/galaxy-s4-tmobile/general/guide-step-step-instructions-building-t3402637[/url]

===========================================================================

Be sure to check out the videos or the XDA thread! I hope that these will help some of the aspiring Android developers out there!

Linux – keep it simple.

Ubuntu Touch: Make your own Jabber/XMPP app in 10 minutes…

You probably think that I’m joking, but I’m not. You can actually build a jabber/xmpp app in less than 10 minutes if you have a good internet connection, and have already set up your system with “clickable”. If not, be sure to check out my last post about it.

Are you ready to get started? Okay, here we go!

The magic that makes this work is that someone (or rather a group of someones) has already made a javascript xmpp client called convers.js. Head over to their website (https://conversejs.org/) and download it, or more directly, just click here: https://github.com/conversejs/converse.js/archive/v3.3.4.zip

Now jump over to your downloads folder and unzip it, or extract it if you grabbed the tar version. Great job, we are 20% done!

Open up your terminal and start typing:

$ mkdir xmmpapp
$ cd xmmpapp/
$ clickable init
Available app templates:
[1] pure-qml-cmake – Pure QML App (built using CMake)
[2] cmake – C++/QML App (built using CMake)
[3] python-cmake – Python/QML App (built using CMake)
[4] html – HTML App
[5] webapp – Simple Webapp
Choose an app template [1]: 4
Generating new app from template: HTML App
You’ve cloned /home/alaskalinuxuser/.cookiecutters/ut-app-html-template before. Is it okay to delete and re-clone it? [yes]: yes
Cloning into ‘ut-app-html-template’…
remote: Counting objects: 28, done.
remote: Total 28 (delta 0), reused 0 (delta 0), pack-reused 28
Unpacking objects: 100% (28/28), done.
Checking connectivity… done.
title [App Title]: xmppapp
description [A short description of your app]: xmpp app.
app_name [appname]: xmppapp
app_full_name [appname.yourname]: xmppapp.alaskalinuxuser
version [1.0.0]: 1.0.0
maintainer_name [Your FullName]: Alaskalinuxuser
maintainer_email [email@domain.org]:
Select open_source_license:
1 – GNU General Public License v3
2 – MIT license
3 – BSD license
4 – ISC license
5 – Apache Software License 2.0
6 – Not open source
Choose from 1, 2, 3, 4, 5, 6 [1]: 5
Your new app has been generated, go to the app’s directory and run clickable to get started
$

All we did was make a directory, run clickable, and choose to make a html app. Notice that this is not a web-app, which is basically a shortcut to some web site. This app is all on the users phone and just opens up an html file. We are now 40% done!

Open up your file manager. Find the downloads folder with your extracted convers.js files. In my case it is ~/Downloads/c/converse.js-3.3.4. Be sure to be in the folder, so you see the files like dev.html. In another tab or window, open up the place that you made your new app, in may case it is ~/ubports_apps/xmmpapp/xmppapp. Be sure to be in this folder so that you see the www folder.

Open the www folder, and drag all of the contents of the converse folder into it. It will ask you if you want to overwrite index.html, say yes. You are 60% done! Five minutes down, five minutes to go!

Now back to you (hopefully) still open terminal. You should still be in the folder outside of the folder of the app you just made. Change directory to your app, like so:

$ cd xmppapp/
$ ls
clickable.json manifest.json www xmppapp.desktop
LICENSE README.md xmppapp.apparmor
$

Typing the ls command should show the same files I have, if you named the app the same as I did. Plug in your phone and be sure developer mode is enabled with Settings->about->Developer mode. You are 80% there!

All you have left to do is type:

$ clickable

 

Copied files to temp directory for click building
Successfully built package in ‘./xmppapp.alaskalinuxuser_1.0.0_all.click’.
3724 KB/s (3190648 bytes in 0.836s)
Installing files [=========================]
Finished [=========================]
Installing files [=========================]
Starting [=========================]
Finished [=========================]
Installed xmppapp.alaskalinuxuser-1.0.0.all (installed:click,removable=1,app_name=xmppapp) summary goes here
$

And you are 100% done! If all went as well as it did here, you should see this:

And now you can start jabber-ing! Obviously, you need an account somewhere. Currently, with this setup, you are using conversjs.org’s BOSH server, and you can connect to your xmpp server. However, this should only be done for testing purposes.

To really utilize this app, you should set up your own BOSH server, and perhaps your own XMPP server. I use ejabber2, so it is an XMPP server and a BOSH server all in one. In the index.html file is this line:

bosh_service_url: ‘https://conversejs.org/http-bind/’,

which should point to your BOSH server. But for testing purposes, the above line works flawlessly. Just recognize that since you are borrowing their BOSH server, it may be down at their leisure, or they can give your sessions the boot if they so desire.

As is, this app will run a non-encrypted conversation with no issues at all. Encryption does work, but it seems a bit funky. I was able to have one successful encrypted conversation, and two that were failures at encrypting. One other issue is that when you close the app, your encrypted “tunnel” ends, so you need to re-establish encryption after that, and I think you have to make sure that the other user turns off encryption so you can re-encrypt with them again.

Big thanks to the convers.js team for making such a great java script that we could drop into our app!

Linux – keep it simple.

Ubuntu Touch: Making a new app

Realizing that there are a few apps missing from the Ubuntu Touch OpenStore, and being an Android app developer, I thought I would try to bridge the gap. Rolling up my sleeves proved to be a bit harder than I thought, though. I came to realize that UT doesn’t use java – at all. The Mir interface doesn’t support the java commands to display or draw things on the screen, so I was a bit stuck.

However, wanting to press on, I did manage to learn how to make a basic “hello world” app. While there are a few tutorials available, it got overly complicated, and I ran into some snags, so I thought I’d share the simplified version here. This is the pertinent info from the UBports website:

 

  • Add the PPA to your system: sudo add-apt-repository ppa:bhdouglass/clickable
  • Update your package list: sudo apt-get update
  • Install clickable: sudo apt-get install clickable
  • Configure docker for clickable: clickable setup-docker

After learning how this works, creating a new, blank or empty app is simple:

alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps$ mkdir newapp
alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps$ cd newapp/
alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps/newapp$ clickable init
Available app templates:
[1] pure-qml-cmake – Pure QML App (built using CMake)
[2] cmake – C++/QML App (built using CMake)
[3] python-cmake – Python/QML App (built using CMake)
[4] html – HTML App
[5] webapp – Simple Webapp
Choose an app template [1]: 4
Generating new app from template: HTML App
You’ve cloned /home/alaskalinuxuser/.cookiecutters/ut-app-html-template before. Is it okay to delete and re-clone it? [yes]: yes
Cloning into ‘ut-app-html-template’…
remote: Counting objects: 28, done.
remote: Total 28 (delta 0), reused 0 (delta 0), pack-reused 28
Unpacking objects: 100% (28/28), done.
Checking connectivity… done.
title [App Title]: newapp
description [A short description of your app]: this is my newapp
app_name [appname]: newapp
app_full_name [appname.yourname]: newapp.alaskalinuxuser
version [1.0.0]:
maintainer_name [Your FullName]: alaskalinuxuser
maintainer_email [email@domain.org]:
Select open_source_license:
1 – GNU General Public License v3
2 – MIT license
3 – BSD license
4 – ISC license
5 – Apache Software License 2.0
6 – Not open source
Choose from 1, 2, 3, 4, 5, 6 [1]: 5
Your new app has been generated, go to the app’s directory and run clickable to get started
alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps/newapp$

After creating a directory to store your app, you just run the command “clickable init” to create a new app. The prompts will ask you for your name, version number, email address and license type for the app. Pretty straight forward. Then you can edit the created app files to your liking, and just run clickable to build it:

alalaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps/newapp$ clickable
No clickable.json was found, using defaults and cli args
Auto detected template to be “pure”
Copied files to temp directory for click building
Successfully built package in ‘./newapp.alaskalinuxuser_1.0.0_all.click’.
337 KB/s (15836 bytes in 0.045s)
Installing files [=========================]
Finished [=========================]
Installing files [=========================]
Starting [=========================]
Finished [=========================]
Installed newapp.alaskalinuxuser-1.0.0.all (installed:click,removable=1,app_name=newapp) summary goes here
alaskalinuxuser@alaskalinuxuser-OptiPlex-7010:~/ubports_apps/newapp$

And voila! If your phone is plugged in, and developer mode is enabled, it can install it and run it on your phone. I also found it useful to use:

$ clickable –desktop

when you want to test it out on your computer, rather than put it on the phone. It seems to work rather well. As a side note, the first time you run it, clickable will download about 500 MB of UT files. This only happens once, not once per app, just once on your machine.

There is also the Ubuntu-sdk, although not supported, it is available if you would like a gui, rather than command line when making your apps. You can install it like so:

sudo add-apt-repository ppa:ubuntu-sdk-team/ppa
sudo apt update && sudo apt dist-upgrade
sudo apt install ubuntu-sdk
sudo reboot # or logout/login

ubuntu-sdk

I’ve tried it out, and to be honest, I prefer the command line, but I might just need to play with it a bit more to get the hang of using it. Hopefully, this will help you if you are trying to get started on app making. I plan to go over how to make an app for XMPP soon.

Linux – keep it simple.

Fool’s Mate Friday: UT and Chess.com

As I mentioned earlier. I jumped off the deep end and dove into the world of Ubuntu Touch. One of the principle hangups I found was that there was not a FICS chess app. While this still remains to be solved, there was a great web-app for Chess.com.

 

Overall, the mobile interface for Chess.com works great. Just like playing on any chess server, there are buttons and doo-dads that allow you to pick different game types and lengths, as well as tons (and I mean tons) of options to change the graphical view. The view you see above is my mix/match version of the numerous options available. There are superior looking themes, backgrounds, pieces, and boards, but I wanted to focus on the game, so that’s why I chose this setup.

There was a few problems when using it with UT. You can see one here:

screenshot20180318_082019721

This pop-up appears before the start of every game, which is a little annoying. Fortunately, just tapping anywhere on the screen makes it go away, so that’s no problem. The other two issues are a bit more of a hassle, but as you will see, only if you really needed them.

The first is that I cannot upload my profile picture from the UT phone. Every time I click “change image” on my profile screen, it asks me to choose an app, if I choose gallery or the file manager, the picture can be chosen, but it never actually uploads.

The only other issue is strangely related. After a game is over, you can download or share the pgn/gif of the game, but with UT, I couldn’t download it. A little annoying, but overall not really a show-stopper. The tap and drag interface worked flawlessly, and the availability of games seemed much quicker than on FICS. I might be hooked!

Linux – keep it simple.

Ubuntu Touch: Making the plunge.

I recently took the plunge, and jumped in on a used Oneplus One phone, converting it to UBPorts community maintained Ubuntu Touch distro. Yes, I now have a true Linux phone. Arguably, Android is Linux, since Linux is really just a kernel, but in most people’s minds, when they say Linux, they mean GNU Linux. Feel free to debate it in the comments. Either way, my phone is now Linux and a flavor of GNU/Linux.

With the plunge came many advancements, and several drawbacks. I’d like to take a few minutes to discuss what those are for potential end users and enthusiasts. I gave it a pretty intensive test by switching to UT cold turkey, and using that as my daily driver for over a week, part of which was while at work. It’s still on my phone, and I think it will be for quite some time.

First and foremost, it did everything a cellular phone should do. I made and received phone calls, I sent text messages, I sent MMS messages, I received the same in return. For a cellular phone, it quite literally was perfect. It took a while to get used to the interface, as it is different from Android or iOS. Once used to it, though, the interface itself was fairly pleasant. To be honest, I now am struggling when trying to use an Android interface on one of my other old phones!

There really were only two major problems with using it. Apps and programs. Due to these issues, I actually was going to give up on it, but decided to stick with it, and now I’m glad I did.

Don’t get me wrong, there are some really great apps on this thing, but there are many apps missing for my daily routine. I use my phone to Jabber (XMPP), but there wasn’t an app for that. I often grab a quick game of Chess on FICS, but there wasn’t a chess app that allowed me to do that. My email from some contacts is sometimes encrypted, but there wasn’t an app that could handle that. So, while it works great as a cellular phone, it didn’t meet my day to day app needs. I was fortunate enough to find several work-arounds for these issues, the details of which I’ll plan on sharing in another article.

Just to give you an idea though, I got really creative. I added onto my ejabber2 server with nginx, and hosted my own webmail client, although I’m still ironing out all the pgp encryption details, it is getting the job done for now. I also hosted a page with convers.js built in, it is a web based xmpp client. Eventually I converted it to it’s own HTML app for the phone as well. As for FICS and online chess, well, there is already an UT app for Chess.com, so I went that route. Don’t worry, if you are looking for details, I’ll be sure to dive into those in future posts.

The only other issue was the desktop app function. Since it is Ubuntu, you can run desktop apps inside a scope’s compatibility function. This is a great idea, and I made numerous apps work, and work fairly well. However, I had some great difficulty with several of the “regular” desktop apps.

For instance, I tried to load three different desktop email clients to work around the email encryption issue (I really was trying to make this my daily driver). However, on all three email programs, I would get to a point where I needed to enter a password, and for some reason, when I clicked in the password fields, the automatic hiding keyboard would not show up so I could type. If you are trying this out yourself, Claws-mail was working for me.

In several programs the keyboard would refuse to auto hide, making half of the screen the keyboard. However, it was only my inexperience that led to this, as I found I could “swipe” down to hide the keyboard. It’s a little clunky, but then again, using a desktop application on your phone, regardless of the OS, is a bit clunky in and of itself.

In an attempt to work around the missing jabber (XMPP) client, I loaded Gajim, an excellent desktop program for this purpose, and it did work! Unfortunately, one of my main contacts required me to install a pidgin plug-in, which, after loading, caused Gajim to crash the phone every time I opened it.

Gimp, however, worked flawlessly, and I was able to utilize it very well. One of the shortcomings I found though, was that the desktop apps and the phone apps are separate, and so are the file systems. So, if you download a picture in an email on the phone side, you can’t see it in the gimp desktop app, since the files are in different containers.

But overall it works really great as a modern day smart phone. The testament to this fact is that I’m still using it. They also have a really great OpenStore with the typical app updating features, manual or automatic, which is really nice, as well as the usual fare of apps, Telegram, Instagram, etc.

The UT team also did a great job with Google integration, if you are into that. If you wanted to sync your calendar and contacts from Google, which can make the switch from Android to UT very easy. The Web Browser app was really intuitive and functioned well. I never once had an issue with it playing or functioning. The camera app was really straight-forward and was flawless in function, which was great!

Later I’ll be talking specifically about the Oneplus One’s function, which I feel is separate from the Ubuntu Touch interface.

Linux – keep it simple.