HTTPServer, Custom RPC functions and stream classes wont work together

19 May 2011

Hello, I tried to combine the HTTPServer with the RPCLibrary and custom rpc functions. Everything works fine up until the point, when I try to include either <iostream> or <fstream> into the project. Whenever I do that and call my custom rpc function "dimLed" via web-browser, the mbed crashes. As soon as I comment out the "#include <iostream>" and "#include <fstream>" statements and the corresponding lines further donwn in the code( for example: "cout << "Unable to open file";" , "ifstream myfile ("/local/20110519.txt");" , ect....) everything works fine again. Has anybody made similar experiences?? Does anybody have a suggestion what the problem could be here?

#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPServer.h"
#include "RPCFunction.h"
#include <iostream>
#include <fstream>

DigitalOut myled(LED1);

LocalFileSystem local("local");               // Create the local filesystem under the name "local"

EthernetNetIf eth;  
HTTPServer svr;

//setting up custom rpc function
//***************************************************
//Create a function of the required format
void dimLed(char * input, char * output);
//Attach it to an RPC object
RPCFunction rpc_dimLed(&dimLed, "LedDimmer");

void dimLed(char * input, char * output){
   float x;
   sscanf(input, "%f", &x);
   PwmOut myLed3 = LED3;
   myLed3 = x;
   sprintf(output, "%f", x);
}

void GetGlobalDateArray ()
{        
       ifstream myfile ("/local/20110519.txt");
    
        if (myfile.is_open()) 
        {     
            while ( myfile.good() ) 
            {
                //do something here
            }
            myfile.close();
        } 
        else 
        {
            cout << "Unable to open file";
        }    
}

int main() 
{ 
  Base::add_rpc_class<DigitalOut>();

  printf("Setting up...\n");
  EthernetErr ethErr = eth.setup();
  if(ethErr)
  {
    printf("Error %d in setup.\n", ethErr);
    return -1;
  }
  printf("Setup OK\n");

  svr.addHandler<RPCHandler>("/rpc");
  svr.bind(80);
  
  printf("Listening...\n");
  
  void GetGlobalDateArray ()
   
  Timer tm;
  tm.start();
  //Listen indefinitely
  while(true)
  { Net::poll();
    if(tm.read()>.5)
    {
      myled=!myled; //Show that we are alive
      tm.start();
    }
  }
   
}