Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetNetIf HTTPServer RPCInterface TextLCD mbed
Fork of RPC_HTTP by
HTTPServerExample.cpp
- Committer:
- fernandomachado
- Date:
- 2012-10-29
- Revision:
- 3:4b05781a0988
- Parent:
- 2:15c92a540ad2
- Child:
- 4:bf7431934cf5
File content as of revision 3:4b05781a0988:
/* HTTP and RPC */
#include "mbed.h"
#include "EthernetNetIf.h"
#include "HTTPServer.h"
#include "RPCVariable.h"
#include "RPCFunction.h"
#include "TextLCD.h"
TextLCD lcd(p21, p22, p23, p24, p25, p26); // rs, e, d4-d7
AnalogIn ain1(p15);
AnalogIn ain2(p16);
float temp;
float volt;
using namespace mbed;
//***************************************************************
//Create a function of the required format LER DATA e HORA
void DateHour(char * input, char * output);
//Attach it to an RPC object
RPCFunction LeDataHora(&DateHour, "LeDataHora");
void DateHour(char * input, char * output)
{
time_t seconds = time(NULL);
sprintf(output, "%s", ctime(&seconds));
}
//***************************************************************
//Create a function of the required format CONTROLA BRILHO do LED
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 myLed4 (LED4);
myLed4 = x/100;
sprintf(output, "%f", x);
}
//**************************************************************
// Função para ler voltagem do potenciometro
void Levolt(char * input, char * output);
RPCFunction Voltagem(&Levolt, "Voltagem");
void Levolt(char * input, char * output)
{
// float volt;
volt = ain1.read() * 3.3;
sprintf (output,"%2.2f", volt);
}
//**************************************************************
// Função para ler a temperatura por meio de um LM35
void Letemp(char * input, char * output);
RPCFunction Temperatura(&Letemp, "Temperatura");
void Letemp(char * input, char * output)
{
// float temp;
temp = ain2.read() * 330;
sprintf (output, "%2.1f", temp);
}
//**************************************************************
//Primeiro: crio as variaveis que vou usar via RPC
//float f;
//int i;
//char c;
//Segundo: associo as variaveis aos RPCVariable Object
//RPCVariable<float> rpc_f(&f, "f");
//RPCVariable<int> rpc_i(&i, "i");
//RPCVariable<char> rpc_c(&c, "c");
//Defino os led´s e o botão
DigitalOut led1(LED1, "led1");
DigitalOut led2(LED2, "led2");
DigitalOut led3(LED3, "led3");
//DigitalOut led4(LED4, "led4");
DigitalIn button1(p20, "button1");
LocalFileSystem fs("webfs");
EthernetNetIf eth;
HTTPServer svr;
int main()
{
Base::add_rpc_class<AnalogIn>();
Base::add_rpc_class<AnalogOut>();
Base::add_rpc_class<DigitalIn>();
Base::add_rpc_class<DigitalOut>();
Base::add_rpc_class<DigitalInOut>();
Base::add_rpc_class<PwmOut>();
Base::add_rpc_class<Timer>();
Base::add_rpc_class<BusOut>();
Base::add_rpc_class<BusIn>();
Base::add_rpc_class<BusInOut>();
Base::add_rpc_class<Serial>();
printf("Setting up...\n\r");
EthernetErr ethErr = eth.setup();
if(ethErr) {
printf("Error %d in setup.\n\r", ethErr);
return -1;
}
printf("Setup OK\n\r");
FSHandler::mount("/webfs", "/files"); //Mount /webfs path on /files web path
FSHandler::mount("/webfs", "/"); //Mount /webfs path on web root path
svr.addHandler<SimpleHandler>("/hello");
svr.addHandler<RPCHandler>("/rpc");
svr.addHandler<FSHandler>("/files");
svr.addHandler<FSHandler>("/"); //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\r");
Timer tm;
tm.start();
//Listen indefinitely
while(true) {
Net::poll();
if(tm.read()>.1) {
//led1=!led1; //Show that we are alive
printf("Funcionando...\n\r");
//time_t seconds = time(NULL);
//printf("Data e hora = %s\n\r", ctime(&seconds));
//f = 0.23;
//i = i + 1;
//c = 'a';
volt = ain1.read() * 3.3;
temp = ain2.read() * 330; /* temp = ain.read() * 3.3 * 100; */
lcd.locate(0,0);
lcd.printf ("Voltagem= %2.2f V \n", volt);
lcd.locate(0,1);
lcd.printf ("Temp= %2.1f C \n", temp);
tm.start();
}
}
}
