A very simple http server in python would look like this
from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer
class MyServer(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(200, 'OK')
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write( "hello" )
HTTPServer(('', 8888), MyServer).serve_forever()
in the do_Get method you can add the code necessary to access your arduino program
...
ser = serial.Serial('/dev/tty.usbserial', 9600)
ser.write('5')
ser.readline()
...
another option would be coding this in ruby by using webrick as the webserver part
require "serialport.so"
require 'webrick';
SERIALPORT="/dev/ttyUSB0"
s = HTTPServer.new( :Port => 2000 )
class DemoServlet < HTTPServlet::AbstractServlet
def getValue()
begin
sp = SerialPort.new( SERIALPORT, 9600, 8, 1, SerialPort::NONE)
sp.read_timeout = 500
sp.write( "... whatever you like to send to your arduino" )
body = sp.readline()
sp.close
return body
rescue
puts "cant open serial port"
end
end
def do_GET( req, res )
body = "--.--"
body = getValue()
res.body = body
res['Content-Type'] = "text/plain"
end
end
s.mount( "/test", DemoServlet )
trap("INT"){ s.shutdown }
s.start
a third option would be using an ethernet-shield on the arduino and skipping the proxy code completely