RE: PPP-Mobile-WAP

"Kelly Smith" <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.tini
Message-ID <[email protected]>
Dear Lars-Erik - Take a look at this (written by Dave McMahon (Smart
Software Consulting) and Bob Hinton); for WAP telephone files, TiniWml,
LoftWml, Control, and Temp classes':

// TiniWml.java - Display TINI info on a WAP phone
//
// Copyright (C) 1999,2000,2001  Smart Software Consulting
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
USA.
//
// Smart Software Consulting
// 1688 Silverwood Court
// Danville, CA  94526-3079
// USA
//
// http://www.smartsc.com
//
// Striped down version for use on a WAP phone 6/05/2001 RJH

import java.io.IOException;
import java.io.PrintWriter;

import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

//import com.dalsemi.system.Clock;
import com.dalsemi.system.TINIOS;

import com.dalsemi.onewire.OneWireException;
import com.dalsemi.onewire.adapter.*;
import com.dalsemi.onewire.container.*;

public class TiniWml
extends HttpServlet
implements SingleThreadModel
{
	public void init()
	throws ServletException
	{
		super.init();
		externalAdapter = new TINIExternalAdapter();
	}

	public void doPost( HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException
	{
		doGet( req, res);
	}

	public void doGet( HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException
	{
		// Do HTTP header stuff
		res.setContentType( "text/vnd.wap.wml");

		// Get Writer
		PrintWriter pw = res.getWriter();

		// Start HTML
		pw.println( "<?xml version=\"1.0\"?>" );
		pw.println( "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"
\"http://www.wapforum.org/DTD/wml_1.1.xml\">");

		pw.println( "\n<wml>\n<head><meta http-equiv=\"Cache-Control\"
content=\"max-age=0\"/></head>");
		pw.println( "<card id=\"Milinfo\">\n<do type=\"accept\"
label=\"Back\">\n<prev/></do>");
		//pw.println( "<do type=\"reset\" label=\"Rfrsh\">\n<go
href=\"Milinfo\"/></do>");

		// Send HTML body
		try { sendBody( pw); }
		catch( OneWireException ibe)
		{
			pw.println( "<p>Got a OneWireException!</p>");
			pw.println( ibe);
		}

		// Finish HTML
		pw.println( "\n</card>\n</wml>");
	}

	public void sendBody( PrintWriter pw)
	throws OneWireException
	{
		pw.println( "<p align=\"center\">Milo Data<br/></p>\n");
		pw.print  ( "<p>at ");
		pw.print  ( getCurrentTime());
		pw.println( "<br/>");

		String hwVersion = TINIOS.getTINIHWVersion();
		if( hwVersion == null) hwVersion = "Unknown";
		pw.print  ( "TINI vers:");
		pw.print  ( hwVersion);
		pw.println( "<br/>");

		pw.print  ( "TINI OS Firmware Version is ");
		pw.print  ( TINIOS.getTINIOSFirmwareVersion());
		pw.println( "<br/>");

		long uptime = TINIOS.uptimeMillis() / 1000;
		long uptimeDays = uptime / (60 * 60 * 24);
		long uptimeHours = (uptime % (60 * 60 * 24)) / (60 * 60);
		long uptimeMinutes = (uptime % (60 * 60)) / 60;
		long uptimeSeconds = uptime % 60;

		pw.print  ( "Up for ");
		pw.print  ( uptime);
		pw.print  ( " seconds (");
		pw.print  ( uptimeDays);
		pw.print  ( " days, ");
		pw.print  ( uptimeHours);
		pw.print  ( " hours, ");
		pw.print  ( uptimeMinutes);
		pw.print  ( " minutes, ");
		pw.print  ( uptimeSeconds);
		pw.print  ( " seconds)<br/>");

		pw.print  ( TINIOS.getFreeRAM() );
		pw.print  ( " bytes free<br/>");

		processes( pw );
		roomtemp( pw );
		pw.print ( "</p>" );
	}
    public void processes( PrintWriter pw)
	// Do ps command - copied from Slush
	{
        String[]    psval = TINIOS.getTaskTable();

        pw.println(psval.length + " process"
                    + ((psval.length == 1) ? " :-<br/>" : "es :-<br/>"));

        String owner = null;
        for (int i = 0; i < psval.length; i++)
        {
            try
            {
                int id = Integer.parseInt((new StringTokenizer(psval[i],
":")).nextToken());
                int ownerID = TINIOS.getOwnerIDByTaskID(id);
                owner = TINIOS.getUserNameByUID((byte)ownerID);
            }
            catch(Exception e)
            {
                owner = "unknown";
            }

            pw.println(psval[i] + " (Owner "+owner+")<br/>");
        }

	}
	public void roomtemp( PrintWriter pw )
	throws OneWireException
	{
    	// Include the temperature if the DS1920 ibutton is attached
		OneWireContainer10 ds1920;

		try
		{
			externalAdapter.targetFamily(DS1920);
			ds1920 = (OneWireContainer10)
externalAdapter.getDeviceContainer(TEMP_IBUTTON);
			byte[] ID = ds1920.getAddress();
			externalAdapter.beginExclusive( true );
			ds1920.setupContainer(externalAdapter,ID);

			if(ds1920.isPresent())
			{
            	byte[] state = ds1920.readDevice();
				//ds1920.doTemperatureConvert(state); - 22/08/01 RJH housemonitor does
conversion
				state = ds1920.readDevice();
				int temp = (int)ds1920.getTemperature(state);

				pw.print( "Room temp = " );
				pw.print( temp );
				pw.print( "C<br/>" );

			}
		}
		catch(OneWireException e)
		{
			pw.print( "No temperature reading<br/>" );
		}
		externalAdapter.endExclusive();
		//externalAdapter.reset(); // Reset one-wire bus
	}
	public static String getCurrentTime()
	{
		return new Date().toString();
	}

	public static final byte DS2502          = (byte)0x09;
	public static final byte DS1920          = (byte)0x10;
	public static final byte CONVERT_TEMP    = (byte)0x44;
	public static final byte READ_STATUS     = (byte)0xaa;
	public static final byte READ_SCRATCHPAD = (byte)0xbe;
	public static final byte READ_MEMORY_CRC = (byte)0xc3;

	public static final String TEMP_IBUTTON    = "940008001A07A110";

	public static final int UNIQUE_WARE     = 0x5e7;

	private TINIInternalAdapter internalAdapter;
	private TINIExternalAdapter externalAdapter;

}


// LoftWml.java - Display state of loft rain protection on a WAP phone
//
// Copyright (C) 1999,2000,2001  Smart Software Consulting
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
USA.
//
// Smart Software Consulting
// 1688 Silverwood Court
// Danville, CA  94526-3079
// USA
//
// http://www.smartsc.com
//
// Striped down version for use on a WAP phone 6/05/2001 RJH

import java.io.IOException;
import java.io.PrintWriter;

import java.util.Date;

import javax.servlet.*;
import javax.servlet.http.*;

//import com.dalsemi.system.Clock;
import com.dalsemi.system.TINIOS;

import com.dalsemi.onewire.OneWireException;
import com.dalsemi.onewire.adapter.DSPortAdapter;
import com.dalsemi.onewire.container.OneWireContainer;
import com.dalsemi.onewire.container.OneWireContainer05;
import com.dalsemi.onewire.container.OneWireContainer10;
import com.dalsemi.onewire.adapter.TINIExternalAdapter;
import com.dalsemi.onewire.adapter.TINIInternalAdapter;
import com.dalsemi.onewire.utils.Address;

public class LoftWml
extends HttpServlet
implements SingleThreadModel
{
	public void init()
	throws ServletException
	{
		super.init();
		externalAdapter = new TINIExternalAdapter();
	}

	public void doPost( HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException
	{
		doGet( req, res);
	}

	public void doGet( HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException
	{
		// Do HTTP header stuff
		res.setContentType( "text/vnd.wap.wml");

		// Get Writer
		PrintWriter pw = res.getWriter();

		// Start HTML
		pw.println( "<?xml version=\"1.0\"?>" );
		pw.println( "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"
\"http://www.wapforum.org/DTD/wml_1.1.xml\">");

		pw.println( "\n<wml>\n<head><meta http-equiv=\"Cache-Control\"
content=\"max-age=0\"/></head>");
		pw.println( "<card id=\"Loftinfo\">" );
		//pw.println( "<do type=\"reset\" label=\"Rfrsh\">\n<go
href=\"#Loftinfo\"/></do>");
		pw.println( "<do type=\"accept\" label=\"Back\">\n<prev/></do>");

		// Send HTML body
		try { sendBody( pw); }
		catch( OneWireException ibe)
		{
			pw.println( "<p>Got a OneWireException!</p>");
			pw.println( ibe);
		}

		// Finish HTML
		pw.println( "\n</card>\n</wml>");
	}

	public void sendBody( PrintWriter pw)
	throws OneWireException
	{
		pw.println( "<p align=\"center\">Loft Status<br/></p>\n");
		pw.print  ( "<p>at ");
		pw.print  ( getCurrentTime());
		pw.println( "<br/>");

		externalAdapter.reset(); // Reset one-wire bus
		window_state(pw, WINDOW1, 1);
		window_state(pw, WINDOW2, 2);
		roomtemp( pw );
		pw.print ( "</p>" );
	}

	public void window_state( PrintWriter pw, String address,int windownum)
	throws OneWireException
    // State if window is open or closed
	{
		OneWireContainer05 ds2405;

		pw.print ( "Window " + windownum + ": ");

		try
		{
			externalAdapter.targetFamily(DS2405);
			ds2405 = (OneWireContainer05)
externalAdapter.getDeviceContainer(address);
			byte[] ID = ds2405.getAddress();
			externalAdapter.beginExclusive( true );
			ds2405.setupContainer(externalAdapter,ID);

			if(ds2405.isPresent())
			{
				byte[] state = ds2405.readDevice();

				pw.print( ds2405.getLevel(0,state) ? "Closed<br/>" : "Open<br/>" );
			}
			else
				pw.print( "UNKNOWN<br/>" );
		}
		catch(OneWireException e)
		{
			pw.print( "READ ERROR<br/>" );
		}
		//externalAdapter.reset(); // Reset one-wire bus
		externalAdapter.endExclusive();
    }
	public void roomtemp( PrintWriter pw )
	throws OneWireException
	{
    	// Include the temperature if the DS1920 ibutton is attached
		OneWireContainer10 ds1920;

		try
		{
			externalAdapter.targetFamily(DS1920);
			ds1920 = (OneWireContainer10)
externalAdapter.getDeviceContainer(TEMP_IBUTTON);
			byte[] ID = ds1920.getAddress();
			externalAdapter.beginExclusive( true );
			ds1920.setupContainer(externalAdapter,ID);

			if(ds1920.isPresent())
			{
            	byte[] state = ds1920.readDevice();
				// ds1920.doTemperatureConvert(state);  - 22/08/01 RJH - housemonitor
does this
				state = ds1920.readDevice();
				int temp = (int)ds1920.getTemperature(state);

				pw.print( "Room temp = " );
				pw.print( temp );
				pw.print( "C<br/>" );

			}
		}
		catch(OneWireException e)
		{
			pw.print( "No temperature reading<br/>" );
		}

		//externalAdapter.reset(); // Reset one-wire bus
		externalAdapter.endExclusive();
	}
	public static String getCurrentTime()
	{
		return new Date().toString();
	}

	public static final byte DS2502          = (byte)0x09;
	public static final byte DS1920          = (byte)0x10;
	public static final byte DS2405          = (byte)0x05;
	public static final byte CONVERT_TEMP    = (byte)0x44;
	public static final byte READ_STATUS     = (byte)0xaa;
	public static final byte READ_SCRATCHPAD = (byte)0xbe;
	public static final byte READ_MEMORY_CRC = (byte)0xc3;

	public static final String TEMP_IBUTTON    = "940008001A07A110";
	public static final String WINDOW1         = "AA0000000E137405";
	public static final String WINDOW2         = "AA0000000E147105";


	public static final int UNIQUE_WARE     = 0x5e7;

	private TINIInternalAdapter internalAdapter;
	private TINIExternalAdapter externalAdapter;

}


// Control.java - Set mode of housemonitor process
// 21/07/2001 Bob Hinton (RJH)
//
// See http://www.smartsc.com
//
// Striped down version for use on a WAP phone 6/05/2001 RJH

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.util.*;
import com.dalsemi.fs.DSFile;
import com.dalsemi.system.*;
import java.net.*;

public class Control
extends HttpServlet
implements SingleThreadModel
{
	private String alert_file;
	private String email_address;
	private boolean state = false;
	private boolean result = false;
	private String on_mode;
	private String off_mode;

	public void init()
	throws ServletException
	{
		super.init();
		alert_file = getInitParameter("alert_file");
		email_address = getInitParameter("email_address");
	}

	public void doPost( HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException
	{
		doGet( req, res);
	}

	public void doGet( HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException
	{
		// Do HTTP header stuff
		res.setContentType( "text/vnd.wap.wml");


		// Get Writer
		PrintWriter pw = res.getWriter();

		// Start HTML
		WapHeader( pw );

		proc: try
		{
			String mode = req.getParameter("mode");
			compute_valid_modes();
			DSFile file = new DSFile(alert_file);

			if(mode.equals(on_mode))
			{
				FileWriter f = new FileWriter(file);
				f.write(email_address + "\n");
				f.close();
				state = true;
				result = true;
				PrintResult( pw );
				break proc;  // All done
			}

			if(mode.equals(off_mode))
			{
				if(file.exists())
					file.delete();
				state = false;
				result = true;
				PrintResult( pw );
				break proc; // All done
			}

			// Else display the current state
			if(file.exists())
				state = true;
			else
				result = false;
			PrintResult( pw );
		}
		catch(Exception e)
		{
        	pw.println( "<p>Exception occurred:" );
			pw.println( e + "</p>" );
		}


		// Finish HTML
		WapFooter( pw );
	}
	public void WapHeader( PrintWriter pw)
	{
		pw.println( "<?xml version=\"1.0\"?>" );
		pw.println( "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"
\"http://www.wapforum.org/DTD/wml_1.1.xml\">");

		pw.println( "\n<wml>\n<head><meta http-equiv=\"Cache-Control\"
content=\"max-age=0\"/></head>");
		pw.println( "<card id=\"emailst\">" );
		pw.println( "<do type=\"accept\" label=\"OK\">\n<prev/></do>");
	}

	public void WapFooter( PrintWriter pw)
	{
		pw.println( "\n</card>\n</wml>");
	}
	public void PrintResult( PrintWriter pw)
	{
		pw.println( "<p>" + (state ? "Enabled" : "Disabled") +
			(result ? " OK" : "") + "</p>" );
	}
	private void compute_valid_modes()
	{
 		Calendar cal = new GregorianCalendar();
		int month = cal.get(Calendar.MONTH);
		int day = cal.get(Calendar.DAY_OF_MONTH);
		int date = (day * 100) + month + 10001;
		StringBuffer date_part = new StringBuffer((new Long(date)).toString());

		date_part.reverse();
		on_mode = "38" + date_part;
		off_mode = "83" + date_part;

		System.out.println("ON: " + on_mode);
		System.out.println("OFF: " + off_mode);
	}
	public static String getCurrentTime()
	{
		return new Date().toString();
	}


}

// Temp.java - Display the values read from the temperature sensors
// 17/07/2001 Bob Hinton (RJH)
//
// See http://www.smartsc.com
//
// Striped down version for use on a WAP phone 6/05/2001 RJH

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.util.*;
import housemonitor.*;
import com.dalsemi.system.*;

public class Temp
extends HttpServlet
implements SingleThreadModel
{
	public void init()
	throws ServletException
	{
		super.init();
	}

	public void doPost( HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException
	{
		doGet( req, res);
	}

	public void doGet( HttpServletRequest req, HttpServletResponse res)
	throws ServletException, IOException
	{
		// First determine whether to send HTML or WML
		boolean do_html;
		String agent = req.getHeader( "User-Agent" );

		if(agent != null && agent.startsWith( "Mozilla" ))
			do_html = true;
		else
			do_html = false;

		// Do HTTP header stuff
		res.setContentType( do_html ? "text/html" : "text/vnd.wap.wml");


		// Get Writer
		PrintWriter pw = res.getWriter();

		// Start HTML
		if(do_html)
			HtmlHeader( pw );
		else
			WapHeader( pw );

		try
		{
			DisplayTemps( pw );
		}
		catch(Exception e)
		{
        		pw.println( "<p>Exception occurred:" );
			pw.println( e + "</p>" );
		}


		// Finish HTML
		if(do_html)
			HtmlFooter( pw );
		else
			WapFooter( pw );
	}
	public void WapHeader( PrintWriter pw)
	{
		pw.println( "<?xml version=\"1.0\"?>" );
		pw.println( "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"
\"http://www.wapforum.org/DTD/wml_1.1.xml\">");

		pw.println( "\n<wml>\n<head><meta http-equiv=\"Cache-Control\"
content=\"max-age=0\"/></head>");
		pw.println( "<card id=\"temps\">" );
		pw.println( "<do type=\"accept\" label=\"OK\">\n<prev/></do>");

		pw.println( "<p>Temps:-<br/>at " +  getCurrentTime() + "<br/>");
	}

	public void WapFooter( PrintWriter pw)
	{
		pw.println( "\n</card>\n</wml>");
	}

	public void HtmlHeader( PrintWriter pw )
	{
		pw.println( "<html>" );
		pw.println( "<head><title>Housemon</title></head>");
		pw.println( "<body>");
		pw.println( "<h1>Temperature readings on " + getCurrentTime() + "</h1>" );
	}

	public void HtmlFooter( PrintWriter pw )
	{
		pw.println( "</body></html>" );
	}

	public void DisplayTemps( PrintWriter pw) throws Exception
	// Display the temperatures from each of the TempAlarm sensors
	{
		Enumeration devices;

		try
		{
			devices = HousemonThread.getMonitor().getDevices().elements();
		}
		catch(Exception e)
		{
			pw.println( "<p>Device list Exception occurred:" );
			pw.println( e + "</p>" );
			return;
		}
		while(devices.hasMoreElements())
		{
			Sensor sensor = (Sensor)devices.nextElement();

			if(sensor != null && sensor instanceof TempAlarm)
			{
				pw.print( sensor.getDescription() );
				try
				{
					pw.println( " " + ((TempAlarm)sensor).getTemperature() + " C" );
				}
				catch(com.dalsemi.onewire.OneWireException e)
				{
					pw.println( " UNKNOWN" );
				}
				pw.println("<br/>");
			}
		}
		pw.println(  "</p>" );
	}
	public static String getCurrentTime()
	{
		return new Date().toString();
	}

}


<<< - CUT: End of code section (watch for the email line wrap, and cleanup
on your editor!

Best regards, Kelly Smith

-----Original Message-----
From: tini-admin-6tN4nzCoH/[email protected] [mailto:[email protected]]On Behalf Of
Lars-Erik Bengtsson
Sent: Wednesday, March 31, 2004 2:15 PM
To: tini-6tN4nzCoH/[email protected]
Subject: [TINI]PPP-Mobile-WAP


I try to reach my Tini threw a PPP-connection from a
WAP browser in my mobile. I got the PPP-connection but
then I can't follow what's going on. I guess my
browser are looking for a WAP-gateway and that I have
to handle that in my TINI somehow. I will be happy if
anyone can give me a hint.
Regards Lars

Höstrusk och grå moln - köp en resa till solen på Yahoo! Resor på adressen
http://se.docs.yahoo.com/travel/index.html
_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini


_______________________________________________
TINI mailing list
TINI-6tN4nzCoH/[email protected]
To UNSUBSCRIBE, edit your profile, or see list archives:
http://lists.dalsemi.com/mailman/listinfo/tini
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.