New to Mbed

I recently started to port from an old 8051 system, I have been working on for more than 20 years, when I was told to look for LPC_1768 processor. On my way I found Mbed project.

I have now been working after hours just to see how far I could get by using the Cookbook.

I have miss read the cookbook several times. To understand Mbed speaking, did gave me some troubles, which many sure fall into.

First of all, Mbed cookbook should state very clear, that working with Mbed, the connection to/with the USB terminal function is a MUST! The description of How to setup the Terminal is however straight forward and worked as explained.

Second, my aim was to get the Mbed to generate a simple text homepage which presented some variables coming from a dataaqusition system, ie a AD converter connected to some I/O pins or some variables collected from polling on a RS232 channel a multimeter or other equipment.

The example with HTTPClientExample helped me to get started, mayor problem was the hardware connection from a RJ45 connector to the Mbed. For me worked RJ45-pin 1 as TX+ connected to Mbed pin 33, RJ45-pin 2 as TX- connected to Mbed pin 34, RJ45-pin 3 as RX+ connected to Mbed pin 35, RJ45-pin 6 as RX- connected to Mbed pin 36.

With some miss read I finally understood how to enter the assigned IP adress I read at the terminal into my browser, with the [filename].htm

Then I only missed to make a program actually writing a txt homepage, but the cookbook helped once again on understanding the local filesystem.

With a modofication of the HTTPserver with this filesystem write example, I reacheded my goal within 8 days!

The code I use so far is inserted here.

 

#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPServer.h"

DigitalOut led1(LED1, "led1");
DigitalOut led2(LED2, "led2");
DigitalOut led3(LED3, "led3");
DigitalOut led4(LED4, "led4");

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

int AD_data;                                    // variabel counted each write of homepage

EthernetNetIf eth;  
HTTPServer svr;

int main() {
  Base::add_rpc_class();
  printf("tsr4...\n");  // Test write to terminal that my program running
  printf("Setting up...\n");
  AD_data = 0;
  EthernetErr ethErr = eth.setup();
  if(ethErr)
  {
    printf("Error %d in setup.\n", ethErr);
    return -1;
  }
  printf("Setup OK\n");
  
  FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
  FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
  
  svr.addHandler("/hello");
  svr.addHandler("/rpc");
  svr.addHandler("/files");
  svr.addHandler("/"); //Default handler
  //Example : Access to mbed.htm : http://a.b.c.d/mbed.htm or http://a.b.c.d/files/mbed.htm
  
  svr.bind(80);
  
  printf("Listening...\n");
    
  Timer tm;
  Timer data_server;
  
  tm.start();
  data_server.start();      // timer for writing homepage
  //Listen indefinitely
  while(true)
  {
    Net::poll();
    if(tm.read()>.5)
    {
      led1=!led1; //Show that we are alive
      tm.start();
    }
    if(data_server.read()>5)
    {
      led2=!led2; //Show that we are updating data
      AD_data++;
      FILE *fp = fopen("/local/Test.htm", "w");  // Open "out.txt" on the local file system for writing
      fprintf(fp, "\r\n");  //\r\n means CR & LF
      fprintf(fp, "\r\n");
      fprintf(fp, "\r\n");
      fprintf(fp, "\r\n");
      fprintf(fp, "\r\n");
      fprintf(fp, "This is a test made by Torben Rasmussen\r\n");
      fprintf(fp, "to show a variabel on a homepage AD_Volt =%03d\r\n", AD_data);
      fprintf(fp, "\r\n");
      fprintf(fp, "\r\n");
      fclose(fp);

      data_server.start();
    }
    
  }
  
  return 0;

}

All my regards to Mbed designers.

Continued when RS232 and/or AD channel is connected.

Some of the code disapeared when copied. Here are the correct code writing the homepage

      FILE *fp = fopen("/local/Test.htm", "w");  // Open "Test.htm" on the local file system for writing
      fprintf(fp, "<html>\r\n");
      fprintf(fp, "<head>\r\n");
      fprintf(fp, "<title>Mbed Test Website</title>\r\n");
      fprintf(fp, "</head>\r\n");
      fprintf(fp, "<body>\r\n");
      fprintf(fp, "This is a Homepage made by Torben Rasmussen\r\n");
      fprintf(fp, "to show a variabel on a homepage AD_Volt =%03d\r\n", AD_data);
      fprintf(fp, "</body>\r\n");
      fprintf(fp, "</html>\r\n");
      fclose(fp);

 


0 comments

You need to log in to post a comment