This version has the index file and data pages on a SD card (512Mbyte) it does not suffer from the autorun problem when directly writtin to the mbed flash memory It makes readings from one solar panel for open and loaded voltages every 'interval' seconds Every readingsPerPage a new web page is created and indexed on a readings web page Activty is shown by the flashing blue led (0.5s) means it is connected and output via the serial over usb port. Data is preserved on subsequent power ups by incrementing file number. PMR 15/9/10 */

Dependencies:   EthernetNetIf NTPClient_NetServices mbed SDFileSystem

Committer:
pmr1
Date:
Sat Sep 18 13:31:41 2010 +0000
Revision:
0:d6b2d5c4c48f

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
pmr1 0:d6b2d5c4c48f 1
pmr1 0:d6b2d5c4c48f 2 /*
pmr1 0:d6b2d5c4c48f 3 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
pmr1 0:d6b2d5c4c48f 4
pmr1 0:d6b2d5c4c48f 5 Permission is hereby granted, free of charge, to any person obtaining a copy
pmr1 0:d6b2d5c4c48f 6 of this software and associated documentation files (the "Software"), to deal
pmr1 0:d6b2d5c4c48f 7 in the Software without restriction, including without limitation the rights
pmr1 0:d6b2d5c4c48f 8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
pmr1 0:d6b2d5c4c48f 9 copies of the Software, and to permit persons to whom the Software is
pmr1 0:d6b2d5c4c48f 10 furnished to do so, subject to the following conditions:
pmr1 0:d6b2d5c4c48f 11
pmr1 0:d6b2d5c4c48f 12 The above copyright notice and this permission notice shall be included in
pmr1 0:d6b2d5c4c48f 13 all copies or substantial portions of the Software.
pmr1 0:d6b2d5c4c48f 14
pmr1 0:d6b2d5c4c48f 15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
pmr1 0:d6b2d5c4c48f 16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
pmr1 0:d6b2d5c4c48f 17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
pmr1 0:d6b2d5c4c48f 18 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
pmr1 0:d6b2d5c4c48f 19 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
pmr1 0:d6b2d5c4c48f 20 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
pmr1 0:d6b2d5c4c48f 21 THE SOFTWARE.
pmr1 0:d6b2d5c4c48f 22 */
pmr1 0:d6b2d5c4c48f 23
pmr1 0:d6b2d5c4c48f 24 #include "HTTPServer.h"
pmr1 0:d6b2d5c4c48f 25
pmr1 0:d6b2d5c4c48f 26 //#define __DEBUG
pmr1 0:d6b2d5c4c48f 27 #include "dbg/dbg.h"
pmr1 0:d6b2d5c4c48f 28
pmr1 0:d6b2d5c4c48f 29 HTTPServer::HTTPServer()
pmr1 0:d6b2d5c4c48f 30 {
pmr1 0:d6b2d5c4c48f 31 m_pTCPSocket = new TCPSocket;
pmr1 0:d6b2d5c4c48f 32 m_pTCPSocket->setOnEvent(this, &HTTPServer::onTCPSocketEvent);
pmr1 0:d6b2d5c4c48f 33 }
pmr1 0:d6b2d5c4c48f 34
pmr1 0:d6b2d5c4c48f 35 HTTPServer::~HTTPServer()
pmr1 0:d6b2d5c4c48f 36 {
pmr1 0:d6b2d5c4c48f 37 delete m_pTCPSocket;
pmr1 0:d6b2d5c4c48f 38 }
pmr1 0:d6b2d5c4c48f 39
pmr1 0:d6b2d5c4c48f 40 void HTTPServer::bind(int port /*= 80*/)
pmr1 0:d6b2d5c4c48f 41 {
pmr1 0:d6b2d5c4c48f 42 Host h(IpAddr(127,0,0,1), port, "localhost");
pmr1 0:d6b2d5c4c48f 43 m_pTCPSocket->bind(h);
pmr1 0:d6b2d5c4c48f 44 m_pTCPSocket->listen(); //Listen
pmr1 0:d6b2d5c4c48f 45 }
pmr1 0:d6b2d5c4c48f 46
pmr1 0:d6b2d5c4c48f 47 #if 0 //Just for clarity
pmr1 0:d6b2d5c4c48f 48 template<typename T>
pmr1 0:d6b2d5c4c48f 49 void HTTPServer::addHandler(const char* path)
pmr1 0:d6b2d5c4c48f 50 {
pmr1 0:d6b2d5c4c48f 51 m_lpHandlers[path] = &T::inst;
pmr1 0:d6b2d5c4c48f 52
pmr1 0:d6b2d5c4c48f 53 }
pmr1 0:d6b2d5c4c48f 54 #endif
pmr1 0:d6b2d5c4c48f 55
pmr1 0:d6b2d5c4c48f 56 void HTTPServer::onTCPSocketEvent(TCPSocketEvent e)
pmr1 0:d6b2d5c4c48f 57 {
pmr1 0:d6b2d5c4c48f 58
pmr1 0:d6b2d5c4c48f 59 DBG("\r\nHTTPServer::onTCPSocketEvent : Event %d\r\n", e);
pmr1 0:d6b2d5c4c48f 60
pmr1 0:d6b2d5c4c48f 61 if(e==TCPSOCKET_ACCEPT)
pmr1 0:d6b2d5c4c48f 62 {
pmr1 0:d6b2d5c4c48f 63 TCPSocket* pTCPSocket;
pmr1 0:d6b2d5c4c48f 64 Host client;
pmr1 0:d6b2d5c4c48f 65
pmr1 0:d6b2d5c4c48f 66 if( !!m_pTCPSocket->accept(&client, &pTCPSocket) )
pmr1 0:d6b2d5c4c48f 67 {
pmr1 0:d6b2d5c4c48f 68 DBG("\r\nHTTPServer::onTCPSocketEvent : Could not accept connection.\r\n");
pmr1 0:d6b2d5c4c48f 69 return; //Error in accept, discard connection
pmr1 0:d6b2d5c4c48f 70 }
pmr1 0:d6b2d5c4c48f 71
pmr1 0:d6b2d5c4c48f 72 HTTPRequestDispatcher* pDispatcher = new HTTPRequestDispatcher(this, pTCPSocket); //TCPSocket ownership is passed to dispatcher
pmr1 0:d6b2d5c4c48f 73 //The dispatcher object will destroy itself when done, or will be destroyed on Server destruction
pmr1 0:d6b2d5c4c48f 74
pmr1 0:d6b2d5c4c48f 75 }
pmr1 0:d6b2d5c4c48f 76
pmr1 0:d6b2d5c4c48f 77 }