Category Archives: Ideas

Kodi with tvaddons

This really is Future of television Open source entertainment

I am not a fan of news and television programs broadcasted in India so my tv was just lying there never being used. I had a spare CPU connected with tv but it wasn’t used extensively. You can watch movies tv-series on your laptop so why bother.

I was thinking about buying chromecast but wasn’t sure how helpful it is another option was Teewe. There are so many from chinese vendors (Allcast, MiraScreen, Anycast etc). I was weighing on which one to buy then I realize that I have a spare board which I ordered sometime back on aliexpress when I was experimenting with raspberry pi/cubieboard/beaglebone/odroid.

The board name is not important as you can use any of the boards you will find someway to run kodi. I realized there is a android lollipop image available for that board. Just took the micro-sdcard from my camera and flashed the image. It was okay fast. Downloaded some apps like netflix, hotstar, gaana, wynk music, google drive, one drive, youtube, tvf, Kodi etc. The option would have been to use Open-elec. That will be faster but android suited my purpose it had a familiar interface for everyone. Open-elec may scare some new friend using the television.

I was thinking of signing into netflix then I realized let me first try Kodi. I saw some youtube videos on how to add addons on kodi and boom. It was so simple to setup everything. with tvaddons my simple plain board which was useless has made my tv a smart useful piece of entertainment system. I can watch any movie, tv -series in no time. You name it and it is there. I tried some recently released movies and it is there.

No torrent required no wait for download etc. anyway now torrent sites are getting banned in India this will also get blocked someday but for now enjoy streaming from putlocker. primewire, alluc etc.

There is one more service which I liked most it is called Trakt.tv. This is really cool service for movies and tv-series watchlist. It is better than IMDB for this particular service. Since you can directly configure it with Kodi it will keep tracking what you are watching just like last.fm for movies/tv-series.
I like the web interface and the data they show. Example:

 

Screen Shot 2017-01-05 at 10.48.02 PM.png

 

Even better:

Screen Shot 2017-01-05 at 10.49.28 PM.png

Trakt.tv may be a cancer for privacy and for pirate users as the data is synced on their server and can be used/shared. Technically you can make your profile private by checking the box in your profile settings page.

Screen Shot 2017-01-05 at 10.51.46 PM.png

If you open a movie or tv-series page you will get lot more user insight:

Screen Shot 2017-01-05 at 10.59.08 PM.png

I generally used Exodus and for most of the time I am just satisfied with the service. I have other addons but I never feel any need to use them.

 

 

Advertisements

Alexa on Raspberry pi

Amazon has done a good job for hobbyist by opening their Alexa API. They have even given the boilerplate code base to start.

You an create almost same experience as Amazon echo with Raspberry-pi.

After first sexting up raspberry pi by raspbian and then installing Debian. You need to configure raspberry. One mistake I did was installing raspbian and then installing debian from that while I should have directly written debian on my sd card. Installing debian via rasbian path is so much time consuming.

Anyway configuring raspberry-pi is very simple

after first debian boot do

sudo apt-get update

sudo apt-get upgrade

then

sudo rasps-config

Now enable ssh (in In advanced optionsI don’t know why they have disabled this to begin with (security reason I know but why?)

You can overclock your raspberry pi for better performance.
Alexa RPi

Follow the steps from:

https://github.com/alexa/alexa-avs-sample-app

Very simple to setup just need time.

At last open three tabs in command window T1, T2, T3

T1

cd ~/Desktop/alexa-avs-sample-app/samples
cd companionService && npm start

T2

cd ~/Desktop/alexa-avs-sample-app/samples
cd javaclient && mvn exec:exec
authorization
T3
To use the Sensory wake word engine, type –

cd ~/Desktop/alexa-avs-sample-app/samples
cd wakeWordAgent/src && ./wakeWordAgent -e kitt_ai

My experience with RPi-Alexa was not so great because I used old RPi which was not supported/mentioned in the blog. And frankly speaking this was damm slow not very usable. Overclock help a little bit. It was a good experience/fun and good toy 🙂 that is all I can say for echo. I don’t think it is really usable to be more than a toy right now. You can enjoy it for a month or two max.

Alexa has (great I am not so sure of) many addons which you can add to your raspberry pi via web interface. This can make it more interesting for may be more than a month. You can say like “Whats my briefing” You an play guessing games. Adding items to shopping list and emailing them setting reminder for gym, grocery shopping etc.

Some Commands in not any particular order:

  • Tell me a joke
  • Add X to my shopping list
  • Add 34 + 67
  • Who is X?
  • How tall is X?
  • Whats on my shopping list?
  • Create a new to-do.?
  • What time is it?
  • What time is it in Bengaluru?
  • What is the weather like in Bengaluru?
  • Set a timer for X seconds/minutes
  • What’s on my to-do list?
  • How old is X (Obama)
  • How many grams in an ounce?
  • News highlights
  • knock knock
  • Do you have any new features?
  • How do you say tomato in hindi /french
  • Define X
  • How many calories in a tomato ?
  • How do you spell entrepreneur ?
  • Flip a coin
  • Roll a dice
  • Rock paper scissor
  • When is holi?
  • Wikipedia X
  • One fish two fish
  • Do you like green eggs and  ham ?
  • Where are you from ?
  • I want the truth
  • Surely you can’t be serious.
  • I need to buy deodorant.
  • Good afternoon
  • What’s the meaning of life
  • Sing happy birthday
  • What day of the week christmas fall
  • Can you rap?
  • What’s my flash briefing?
  • Whats in the news ?
  • Alexa inspire me
  • How to make bloody marry ?
  • Start workout
  • Start Akinator
  • play jeopardy

For some you may need to enable addons like for news, for workout you need 7 -minutes workout.

Add Alexa in front of all command which makes it really annoying citing her name each time. They should have made it more smart and keep it triggered for at least 5 extra minutes. Could have add this to user agreement. I know people are worried about security, privacy. Amazon/Google listening our conversation always. But I guess main problem for amazon would have been understanding a whole para to make sense out of questions directed to Echo  when listening for five full minutes.

Some recording:

Reply for Alexa, When is holy?

Reply for Alexa, One fish two fish 

Some more:

 

Web Server on android

ideas

I never knew that I will need a complete web-server on android. I was also in the league of people thinking why would someone need a server on their phone. What purpose can it serve apart from just the joy that “Holla!! I have a full-fledged web server in my pocket!!”.
For my current product it seemed such a useful thing that now I can think of multiple ways where running server on android can be so helpful and it can be used for so many ways. Just think it as a cheap Web Server with its own small network when WiFi hotspot mode is on. You can create your own server client environment, specific to your needs. Like for sharing things may be in a conference room setup.

Getting the server going

Now coming to original point of the blog how to do it.
First the major part is getting the web-server. There are so many open source products I like the PAW server
http://paw-android.fun2code.de/ Other options are i-jetty
https://code.google.com/p/i-jetty/
nanohttpd

https://github.com/NanoHttpd/nanohttpd
JWS

http://tjws.sourceforge.net/
etc. After you get the webserver running you will need to put your own webpages in proper places as for PAW server I just deleted everything inside the folder /sdcard/paw/html and put my own pages as I like them. You just need to copy your web space assuming this is the starting directory. I used PAW because it needed least configuration. You can use whatever suits you. Just overwrite everything they have in that directory.
After getting the server running you can see your webpage getting displayed at http://192.168.43.1:port_no. Of-course you will need to turn on hotspot and connect your device(from where you want to browse) to the hotspot.
For PAW server it is http://192.168.43.1:8080 . Where 192.168.43.1 is default ip for android hotspot if not changed by manufacturer. If your devices are on same network you have to know the ip of the android device hosting web.

This surely is not good if you want the web-server serving many people. You want to remove the ip address and the port make it something like http://www.myserver.com huh? or http://myandroid.com with or without www replacing anything in place of com. Just for fun or say aha!! Now I can host anything without paying.
For removing IP from url you just need small changes but your device should be rooted.

Making it more real

Port forwarded is a great app to forward traffic to specified port. Since http requests come to port 80 you will need to create a rule in port forwarder to forward all incoming traffic on port 80 to port 8080 or the port number your server is running on. This will remove the port specification from url.
Finally we have to remove the ip address typing in URL. For this you just need to edit one file and add your own domain name and address. Mount your system in write mode:
mount -o rw,remount /system
location of system directory is device specific.
You can get the ip address of the device by connecting to hotspot and checking the default gateway. In general it is 192.168.43.1

Change /system/etc/hosts file and add below line

192.168.43.1 com myphone.com

com is my domain name and myphone is my hostname you can put whatever you like. This just indicate that given device address

Now change or create /etc/dnsmasq.conf file and add domain name like this:

local=/com/
domain=com

now you can even connect via adb like this:
adb connect android.com
cool huh!!.
Just restart hotspot and you are done :).

USB data Sniffing and recreating similar behaviour

Sniff.. Sniff…

Recently I had to work on a USB camera device for Linux. The vendor has just given the example code for Windows. That example code also uses some pre-compiled library and dll file. So there is no way to know what exactly is happening when the software is run and device is controlled via the software. Basically I have to make filter switcher of the camera work in Linux. For windows vendor has provided with one filter switching application.

Usblyzer ( http://www.usblyzer.com/ ) is a great tool for sniffing USB traffic. It gives you almost everything required to re-create the scenario. I used this to see the USB packets and then used libusb for windows to re-create the scenario.

libusb: A Great Open source usb library

Making windows work with libusb:

Download most recent version of libusb. I used :

http://kaz.dl.sourceforge.net/project/libusb-win32/libusb-win32-releases/1.2.6.0/libusb-win32-bin-1.2.6.0.zip

go to bin folder and run the install-filter exe. Now you need to copy the dll and sys file. I did below for my PC:
ALL ARCHITECTURES:
x86\libusb0_x86.dll: x86 32-bit library. Must be renamed to libusb0.dll
On 32 bit, Installs to Windows\system32\libusb0.dll.

X86 ONLY ARCHITECTURES:
x86\libusb0.sys: x86 32-bit driver.
Installs to Windows\system32\drivers\libusb0.sys

After above steps you will be able to able to see your device info when you run testlibusb-win.exe from bin folder.

Get to work

Now create an empty Visual studio project.

Add proper libusb.lib in Linker => Input additional dependency. For my PC it was in lib/msvc/libusb.lib.

Include lusb0_usb.h in your main file.

Now you can write code to get device handle and send data. I am pasting my code for reference:

#include <stdio.h>
#include "lusb0_usb.h"
#include <iostream>
#include <windows.h>

using namespace std;

int main(int argc, char** argv)
{
usb_dev_handle *my_dev_hndl = NULL; /* the device handle */
struct usb_device *my_dev;

struct usb_bus *busses;

void usb_init(void);
usb_find_busses(); /* find all busses */
usb_find_devices(); /* find all connected devices */
busses = usb_get_busses();
struct usb_bus *bus;

/* ... */

for (bus = busses; bus; bus = bus->next)

{
struct usb_device *dev;

for (dev = bus->devices; dev; dev = dev->next)

{
/* Check if this device is a printer */
if (dev->descriptor.bDeviceClass == 239) {//you can find this in info of testlibusb
/* Open the device, claim the interface and do your processing */
printf("I am so happy \n");
my_dev = dev;
printf("%d\n",dev->descriptor.bDeviceClass);
cout<<"Number of possible configurations: "<descriptor.bnumconfigurations<<" "<<<span="" class="hiddenSpellError" pre="">endl;
cout<<"VendorID: "
cout<<"ProductID: "
my_dev_hndl = usb_open(dev);
/* only one configuration: #1 */
int ret = usb_set_configuration(my_dev_hndl, 1);
if (ret < 0)
{
printf("usb_set_configuration failed ret code: %d.\n", ret);
printf("%s\n", usb_strerror());
}

/* configuration #1, interface #0 */
ret = usb_claim_interface(my_dev_hndl, 0);
if (ret < 0)
{
printf("usb_claim_interface failed ret code: %d\n", ret);
printf("%s\n", usb_strerror());
//usb_close(my_dev_hndl);
}
}
char bmRequestType= 0x21;

unsigned char bRequest = 0x01;
unsigned short wValue = 0x400;
unsigned short wIndex = 0x400;
unsigned short wLength = 4;
unsigned int timeout = 1000;

char data_rec[2] = { 0x04, 0x00 };//20 32 B0 22
usb_control_msg(my_dev_hndl, 0xA1, 0x85, wValue, wIndex, data_rec, 2, timeout);

char data_init[4] = { 0x00, 0x00, 0x00, 0x00 };//20 32 B0 22
usb_control_msg(my_dev_hndl, bmRequestType, bRequest, wValue, wIndex, data_init,  wLength, timeout);

usb_control_msg(my_dev_hndl, 0xA1, 0x85, wValue, wIndex, data_rec, 2, timeout);

usb_control_msg(my_dev_hndl, 0xA1, 0x85, wValue, wIndex, data_rec, 2, timeout);

char data_init1[4] = { 0x00, 0x00, 0x00, 0xAA };//20 32 B0 22
usb_control_msg(my_dev_hndl, 0xA1, 0x81, wValue, wIndex, data_init1, wLength, timeout);
Sleep( 3 );
}
}
}

if (dev->descriptor.bDeviceClass == 239) {//you can find this in info of testlibusb

What I noticed here is when you are recreating the scenario you have to be careful about timing also otherwise it may result in “Bulk or Interrupt Transfer failure”

To get the info about usb_control_msg parameters you can check USBLYZER output. More info is displayed at bottom in summary and Analysis section.

Offset Field Size Value Description
0 bmRequestType 1 40h
4..0: Recipient ...00000 Device
6..5: Type .10..... Vendor
7: Direction 0....... Host-to-Device
1 bRequest 1 01h
2 wValue 2 0400h
4 wIndex 2 0400h
6 wLength 2 0004h

Now I recreated the same message sequence passing in Linux using libusb. I was able to achieve the same result on Linux without any help from device vendor. 🙂

In linux I faced the issue where device was always busy error code -6. This can be resolved by

libusb_detach_kernel_driver(h, 0);

h is device handle 0 is interface.

The sequence is same here also first list the device and find your device of interest. After this open your device and get dev handle detach the device to make sure no one else is using it. cal set_configuration and claim_interface. Prepare required data and send.

 

For debugging in Linux you can use usbmon. It comes with linux so nothing is required. Commands to see usbmon output:

sudo mount -t debugfs none_debugs /sys/kernel/debug

sudo modprobe usbmon

sudo cat /sys/kernel/debug/usb/devices

lsusb

ls /sys/kernel/debug/usb/usbmon

sudo cat /sys/kernel/debug/usb/usbmon/2u > ~/2u.mon.out

After above command see the output in file 2u.mon.out

2u is my device you can see output of all usb with 0u otherwise you need to search for your device bus with lsusb and sudo cat /sys/kernel/debug/usb/devices commands.