I'm extremely new to Java and TINI - can you show me how to get a "hello world" program running on my TINI board?
Created May 4, 2012
Tim Rohaly
Here's a walkthrough to get your first piece of code up and running. For more sophisticated examples, including examples of how to read and write to the 1-wire bus, see the examples folder included with the TINI firmware.
-
Create a file HelloWeb.java containing the following:
import java.io.*; import java.net.*; public class HelloWeb { public static void main(String[] args) throws IOException { System.out.println("Hello, Web!"); // Delete the rest of this method if you just want a simple hello world. ServerSocket server = new ServerSocket(80); while (true) { Socket socket = server.accept(); PrintWriter out = new PrintWriter(socket.getOutputStream()); BufferedReader in = new BufferedReader( new InputStreamReader(socket.getInputStream())); // Read in the HTTP headers String s; while ((s = in.readLine()) != null) { System.out.println(s); if (s.equals("")) break; } // HTTP headers done, send reply out.print("HTTP/1.0 200 OK "); out.print("<html><body><h1>Hello, Web!<h1><body><html> "); out.flush(); socket.close(); System.gc(); } } }
- Compile this code using your java compiler.
The TINI firmware is assumed to be installed in C: inibeta3.0,
and Windows syntax is shown:
C:>set TINI_HOME=c: inibeta3.0 C:>javac -bootclasspath %TINI_HOME%bin iniclasses.jar HelloWeb.java
- Next, you need to convert the .class file created by the Java compiler into a .tini file
which can be run on the TINI:
C:>java -classpath %TINI_HOME%bin ini.jar TINIConvertor -f HelloWeb.class -o HelloWeb.tini -d %TINI_HOME%bin ini.db
- Copy the .tini file to your TINI. The hostname of the TINI is assumed to be "tini" here.
C:>ftp tini Connected to tini. 220 Welcome to slush. (Version 1.0 Beta 3) Ready for user login. User (tini:(none)): root 331 root login allowed. Password required. Password: 230 User root logged in. ftp> bin 200 Type set to Binary ftp> put HelloWeb.tini 200 PORT Command successful. 150 BINARY connection open, putting HelloWeb.tini 226 Closing data connection. 381 bytes sent in 0.00 seconds (381000.00 Kbytes/sec) ftp>quit 221 Goodbye.
- Log on to your TINI using TELNET then start the HelloWeb
server with the command:
java HelloWeb.tini &
- At this point, your HelloWeb server is running on your TINI. If you connect to your TINI by entering the URL http://tini/ in your web browser, the HelloWeb server will respond and a message will be displayed in your browser.