11.06.2015 Views

ODROID-Magazine-201506

ODROID-Magazine-201506

ODROID-Magazine-201506

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ANDROID DEVELOPMENT<br />

The Android.mk is similar to other projects inside the external/<br />

directory. Notice that there are 2 files being copied as part<br />

of the build process:<br />

• httpd.conf → contains the configuration for the webserver<br />

• mime.types → contains the file types that are allowable by<br />

the webserver app<br />

Once you have successfully compiled the <strong>ODROID</strong>-U3<br />

Android source code, you will see a gohttp executable file inside<br />

the out/target/product/odroidu/system/bin directory, as<br />

shown in Figure 2.<br />

Initialization<br />

The last step of the porting is to run the gohttp application<br />

as part of Android startup process. In order to do that, we<br />

will need to modify the file called init.odroidu.rc inside device/<br />

hardkernel/odroidu/conf directory, as shown in Figure 3.<br />

Figure 4: mkdir for creating directory<br />

We also need to add a service to start gohttp:<br />

Figure 2: gohttp executable<br />

The webserver is configured to listen at port 8888, which is<br />

declared inside the httpd.conf file.<br />

The other item that need to be modified inside the app is<br />

the logging, since it make sense to make sure that the app sends<br />

any logging information to the logcat service. Here is the new<br />

code that is added inside GoHttp.c that will do the logging:<br />

#ifdef DEBUG_ANDROID<br />

#include <br />

#define LOG_TAG “gohttp”<br />

#define PRINT(...) __android_log_print(ANDROID_LOG_<br />

INFO, LOG_TAG, __VA_ARGS__)<br />

#else<br />

#define PRINT(...) fprintf(stdout, “%s\n”, __VA_<br />

ARGS__)<br />

#endif<br />

service gohttp /system/bin/gohttp<br />

class core<br />

Under the “on post-fs-data” section, you need to add the<br />

statement indicated in Figure 4. This statement is used to create<br />

the directory where you will put the .html files that you<br />

want to make available for the user to access.<br />

Once you boot up your <strong>ODROID</strong>-U3, you can then copy<br />

an index.html file to /data/www folder and access it via the<br />

server by using any browser to navigate to the local site at<br />

http://:8888/index.html.<br />

If you’d like to learn more about Android programming,<br />

contact Nanik directly, or follow his latest posts, please visit his<br />

website at http://naniktolaram.com.<br />

With Nanik’s help, you’re now fully equipped to create your<br />

own custom Android service<br />

Figure 3: init file for <strong>ODROID</strong>-U3<br />

<strong>ODROID</strong> MAGAZINE 47

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!