-
1Step 1
Ebook Tools
Prepare an ebook with one of the tool above
- Calibre (overkill for a mobi but perfect for azw3 generation)
- One of the numerous online ebook converters.
Keep in mind : only mobi or azw3. Other (pdf, txt) appear weirdly in log.
You can also pick one of mine in my repo.
-
2Step 2
Kindle Toolchain
Download kindle toolchain ( = all the tools to compile source code). Here is the toolchain i used Samsheff's for linux. You can build your own on Mac OS, and maybe on Windows.
If you build your own toolchain, consider enabling C99.
I strongly recommend you to use the same directory you use in step 1 and in this case :
~/dev-kindle/ $ git clone https://github.com/samsheff/Amazon-Kindle-Cross-Toolchain
-
3Step 3
Cloning my repo
If you plan to only test, I suggest to clone my repo on /tmp/ because it's wiped on reboot.
$ cd /tmp/
Otherwise, if you plan to hack my stuff use your development directory.$ mdir ~/dev-kindle/ $ cd ~/dev-kindle/
Then clone my github repo :
~/dev-kindle/ $ git clone https://github.com/cekage/kindle-home-automation
-
4Step 4
1st build (for computer)
The toolchain provided by Samsheff supports C99 so am I. If you have a decent C compiler (clang or gcc), first of all check on your computer everything is ok.
kindle-home-automation $ make build cc -Werror -Wall -ggdb -pedantic -std=c99 -O0 -fno-stack-protector -lm read_fifo.c -o read_fifo kindle-home-automation $ file read_fifo read_fifo: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, not stripped
If you plan to hack my stuff, I warmly recommend you to stick to pure C99 and do all tests on your computer instead of uploading to your kindle. -
5Step 5
1st build (for kindle)
Now read_fifo.c is checked against your computer's C Compiler, check with the toolchain.
kindle-home-automation $ make build CC=../Amazon-Kindle-Cross-Toolchain-master/arm-kindle-linux-gnueabi/bin/arm-kindle-linux-gnueabi-cc ../Amazon-Kindle-Cross-Toolchain-master/arm-kindle-linux-gnueabi/bin/arm-kindle-linux-gnueabi-cc -Werror -Wall -ggdb -pedantic -std=c99 -O0 -fno-stack-protector -lm read_fifo.c -o read_fifo
Yes, LONG PATH IS LONG, but now you have a kindle ready binary
kindle-home-automation $ file read_fifo read_fifo: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux.so.3, for GNU/Linux 2.6.27, not stripped
-
6Step 6
Fit code to your network 1/2
In read_fifo.c, I've hardcoded that when program see
cvm[1234]: I SupplementarInfoBox:QUICK_LOOKUP:asin=51b5315f-77e9-4927-80b1-a9afbe1c4d76,word=Cuisine:
it connects to http://mbp:8080/?toggle=CUISINEI provide with source code some logs you can test by typing make run :
kindle-home-automation $ make run ./read_fifo < Docs/kindle.log process_SupplementarInfoBox() with cvm[1234]: I SupplementarInfoBox:QUICK_LOOKUP:asin=51b5315f-77e9-4927-80b1-a9afbe1c4d76,word=Cuisine: \_____ match : asin=51b5315f-77e9-4927-80b1-a9afbe1c4d76 / word=Cuisine Could not connect: Connection refused Makefile:16: recipe for target 'run' failed make: *** [run] Error 1
If you have a computer named mbp and listening on port 8080 (what I deeply doubt ;-) ) then you'll have seen that :kindle-home-automation $ make run ./read_fifo < Docs/kindle.log process_SupplementarInfoBox() with cvm[1234]: I SupplementarInfoBox:QUICK_LOOKUP:asin=51b5315f-77e9-4927-80b1-a9afbe1c4d76,word=Cuisine: \_____ match : asin=51b5315f-77e9-4927-80b1-a9afbe1c4d76 / word=Cuisine HTTP/1.0 200 OK Server: BaseHTTP/0.3 Python/2.7.9 Date: Tue, 11 Aug 2015 16:55:37 GMT Content-type: text/html <!-- done /?toggle=Cuisine --> (…) process_SupplementarInfoBox() with cvm[1234]: I SupplementarInfoBox:QUICK_LOOKUP:asin=3258236f-e9de-416b-bb6f-ed462cd2b1d0,word=pendant: \_____ match : asin=3258236f-e9de-416b-bb6f-ed462cd2b1d0 / word=pendant HTTP/1.0 200 OK Server: BaseHTTP/0.3 Python/2.7.9 Date: Tue, 11 Aug 2015 16:55:37 GMT Content-type: text/html <!-- done /?toggle=pendant -->
-
7Step 7
Fit code to your network 2/2
Modify Docs/http_relay.py to change "mbp" :
HOST_NAME = 'mbp'
To the host of your computer. You can use IP either. And then start the "http relay" with python2 :
kindle-home-automation/Docs $ python2 http_relay.py Server Starts - mbp:8080
That's ok, Now the C source code.Modify lib/htmlrequest.h and modify
const char* host = "mbp";
to replace "mbp" by the host of your computer. You can use IP either.const char* host = "192.168.1.123";
and then rerun test :
kindle-home-automation $ make run ./read_fifo < Docs/kindle.log process_SupplementarInfoBox() with cvm[1234]: I SupplementarInfoBox:QUICK_LOOKUP:asin=51b5315f-77e9-4927-80b1-a9afbe1c4d76,word=Cuisine: \_____ match : asin=51b5315f-77e9-4927-80b1-a9afbe1c4d76 / word=Cuisine HTTP/1.0 200 OK Server: BaseHTTP/0.3 Python/2.7.9 Date: Tue, 11 Aug 2015 16:55:37 GMT Content-type: text/html <!-- done /?toggle=Cuisine --> (…)
-
8Step 8
Copying to kindle
Now we have everything working fine on our computer. Let's gathering everything for a pre-demo in the kindle :
- THE kindle binary ( see instruction on point 5)
- ONE log for testing (see in Docs/)
- ONE ebook the mobi (asin unknown) or azw3
Upload to the kindle to see stuff in live. I assume your kindle ip is 192.168.1.110.
Upload binary to /tmp :
kindle-home-automation $ scp read_fifo root@192.168.1.110:/tmp/ Welcome to Kindle! root@192.168.1.110's password: read_fifo 100% 20KB 19.9KB/s 19.9KB/s 00:00
Upload ebook to /tmp :
kindle $ scp Docs/domotique.azw3 root@192.168.1.110:/tmp/ Welcome to Kindle! root@192.168.1.110's password: domotique.azw3 100% 11KB 10.7KB/s 10.7KB/s 00:00
Upload log to /tmp :kindle-home-automation $ scp Docs/kindle.log root@192.168.1.110:/tmp/ Welcome to Kindle! root@192.168.1.110's password: kindle.log 100% 58KB 57.8KB/s 57.8KB/s 00:00
-
9Step 9
1st run on the kindle
Now it's time to tap inside kindle through ssh :
kindle-home-automation $ ssh root@192.168.1.110 Welcome to Kindle! root@192.168.1.110's password: ################################################# # N O T I C E * N O T I C E * N O T I C E # ################################################# Rootfs is mounted read-only. Invoke mntroot rw to switch back to a writable rootfs. #################################################
Go to /tmp/ and fire read_fifo
[root@kindle tmp]# ./read_fifo < cvm.log process_SupplementarInfoBox() with cvm[3363]: I SupplementarInfoBox:QUICK_LOOKUP:asin=unknown,word=switch: \_____ match : asin=unknown / word=switch HTTP/1.0 200 OK Server: BaseHTTP/0.3 Python/2.7.9 Date: Tue, 11 Aug 2015 19:36:36 GMT Content-type: text/html <!-- done /?toggle=switch --> (…)
By curiosity here is the time for read_fifo to parse the entire log and trigger http connection :
[root@kindle tmp]# time ./read_fifo < cvm.log process_SupplementarInfoBox() with cvm[3363]: I SupplementarInfoBox:QUICK_LOOKUP:asin=unknown,word=switch: \_____ match : asin=unknown / word=switch HTTP/1.0 200 OK Server: BaseHTTP/0.3 Python/2.7.9 Date: Tue, 11 Aug 2015 19:42:09 GMT Content-type: text/html <!-- done /?toggle=switch --> (…) <!-- done /?toggle=BUREAU --> real 0m 0.11s user 0m 0.04s sys 0m 0.01s
Quite quick isn't it ? :-)
-
10Step 10
Plumbery : syslog-ng.conf
WARNING IF YOU FOLLOW THIS STEP YOU WILL HAVE TO UNDO IT : SEE STEP 14 !
Now it's time to vi, if you are not familiar with this prehistoric tool, spend time with a cheatsheet.
First, set root partition read-writeable :
[root@kindle root]# mntroot rw system: I mntroot:def:Making root filesystem writeable /dev/mmcblk0p1 on / type ext3 (rw,noatime,nodiratime)
and BACKUP syslog-ng.conf !
[root@kindle root]# cd /etc/syslog-ng/ [root@kindle root]# cp syslog-ng.conf syslog-ng.conf.ok
and then "vi /etc/syslog-ng/syslog-ng.conf".
Edit the file to match mine :
[root@kindle root]# grep cvm /etc/syslog-ng/syslog-ng.conf destination cvm { program("/tmp/read_fifo" template("$MSG\n")); }; filter f_cvm { match("cvm"); }; log { source(src); filter(f_cvm); destination(cvm); };
I explain those 3 lines :
- Tells syslog-ng to create a destination named cvm which aims a program (yes our read_fifo from /tmp/ ) and use a minimal template.
- Tells syslog-ng to create a filter named f_cvm with search for the string in the entire line (both header and message according to manual)
- Tells syslog-ng to create a log (= a real rule) who take source, apply filter, and if filter matches then send it to destination (= our program in point 1)
It's not mandatory but a good habit. We have finished tempering root filesystem so :
[root@kindle root]# mntroot ro system: I mntroot:def:Making root filesystem read-only /dev/mmcblk0p1 on / type ext3 (ro,noatime,nodiratime)
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.