Example program with HTTPServer and sensor data streaming over TCPSockets, using Donatien Garnier's Net APIs and services code on top of LWIP. Files StreamServer.h and .cpp encapsulate streaming over TCPSockets. Broadcast is done by sendToAll(), and all incoming data is echoed back to the client. Echo code can be replaced with some remote control of the streaming interface. See main() that shows how to periodically send some data to all subscribed clients. To subscribe, a client should open a socket at <mbed_ip> port 123. I used few lines in TCL code to set up a quick sink for the data. HTTP files are served on port 80 concurrently to the streaming.

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LwipNetIf.cpp Source File

LwipNetIf.cpp

00001 
00002 /*
00003 Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com)
00004  
00005 Permission is hereby granted, free of charge, to any person obtaining a copy
00006 of this software and associated documentation files (the "Software"), to deal
00007 in the Software without restriction, including without limitation the rights
00008 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00009 copies of the Software, and to permit persons to whom the Software is
00010 furnished to do so, subject to the following conditions:
00011  
00012 The above copyright notice and this permission notice shall be included in
00013 all copies or substantial portions of the Software.
00014  
00015 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00016 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00017 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00018 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00019 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00020 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00021 THE SOFTWARE.
00022 */
00023 
00024 #include "LwipNetIf.h"
00025 #include "lwip/init.h"
00026 #include "lwip/tcp_impl.h"
00027 #include "lwip/dns.h"
00028 
00029 #include "netCfg.h"
00030 #if NET_LWIP_STACK
00031 
00032 //See doc/rawapi.txt for details
00033 
00034 LwipNetIf::LwipNetIf() : NetIf(), m_tcpTicker(), m_dnsTicker(), m_init(false)
00035 {  
00036 
00037 }
00038 
00039 
00040 LwipNetIf::~LwipNetIf()
00041 {
00042   m_tcpTicker.detach();
00043   m_dnsTicker.detach();
00044 }
00045 
00046 void LwipNetIf::init()
00047 {
00048   if(m_init)
00049     return;
00050   m_init=true;
00051   lwip_init(); //init lwip, see init.c for details
00052   
00053   //Setup Clocks
00054   m_tcpTicker.attach_us( tcp_tmr, TCP_TMR_INTERVAL * 1000 ); //TCP_TMR_INTERVAL = 250 ms in tcp_impl.h
00055   m_dnsTicker.attach_us( dns_tmr, DNS_TMR_INTERVAL * 1000 ); //DNS_TMR_INTERVAL = 1000 ms in dns.h
00056 }
00057 
00058 NetTcpSocket* LwipNetIf::tcpSocket()  //Create a new tcp socket
00059 {
00060   return new LwipNetTcpSocket();
00061 }
00062 
00063 NetUdpSocket* LwipNetIf::udpSocket()  //Create a new udp socket
00064 {
00065   return new LwipNetUdpSocket();
00066 }
00067 
00068 NetDnsRequest* LwipNetIf::dnsRequest(const char* hostname) //Create a new NetDnsRequest object
00069 {
00070   return new LwipNetDnsRequest(hostname);
00071 }
00072 
00073 NetDnsRequest* LwipNetIf::dnsRequest(Host* pHost) //Create a new NetDnsRequest object
00074 {
00075   return new LwipNetDnsRequest(pHost);
00076 }
00077 
00078 void LwipNetIf::poll()
00079 {
00080   //Do some stuff...
00081 }
00082 
00083 #endif