My first attempt to play with the RPC commands and a Visual Basic 2008 program.

Dependencies:   EthernetNetIf HTTPServer RPCInterface TextLCD mbed

Fork of RPC_HTTP by Fernando Machado

Files at this revision

API Documentation at this revision

Comitter:
fernandomachado
Date:
Mon Oct 29 21:25:42 2012 +0000
Parent:
1:71b64a776133
Child:
3:4b05781a0988
Commit message:
The programm is to help some one that is starting with RPC (like me).

Changed in this revision

HTTPServerExample.cpp Show annotated file Show diff for this revision Revisions of this file
RPCInterface.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPServerExample.cpp	Thu Sep 09 13:47:59 2010 +0000
+++ b/HTTPServerExample.cpp	Mon Oct 29 21:25:42 2012 +0000
@@ -1,39 +1,98 @@
-/*
-Copyright (c) 2010 ARM Ltd
- 
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
- 
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
- 
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
-*/
+/* Funcionou com os arquivos 'RPCdemo.htm' e 'mbedRPC.js' na raiz do Mbed */
+/* Funcionou com os arquivos  'launch.htm e 'mbedapp.jar' na raiz do Mbed */
+/* Funcionou com o prg escrito em VB */
+
 #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");
+//DigitalOut led4(LED4, "led4");
+DigitalIn button1(p20, "button1");
 
 LocalFileSystem fs("webfs");
 
-EthernetNetIf eth;  
+EthernetNetIf eth;
 HTTPServer svr;
 
-int main() {
+int main()
+{
     Base::add_rpc_class<AnalogIn>();
     Base::add_rpc_class<AnalogOut>();
     Base::add_rpc_class<DigitalIn>();
@@ -46,41 +105,51 @@
     Base::add_rpc_class<BusInOut>();
     Base::add_rpc_class<Serial>();
 
-  printf("Setting up...\n");
-  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<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");
-    
-  Timer tm;
-  tm.start();
-  //Listen indefinitely
-  while(true)
-  {
-    Net::poll();
-    if(tm.read()>.5)
-    {
-      led1=!led1; //Show that we are alive
-      tm.start();
+
+    printf("Setting up...\n\r");
+    EthernetErr ethErr = eth.setup();
+    if(ethErr) {
+        printf("Error %d in setup.\n\r", ethErr);
+        return -1;
     }
-  }
-  
-  return 0;
+    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();
+        }
+    }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RPCInterface.lib	Mon Oct 29 21:25:42 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/fernandomachado/code/RPCInterface/#ff67e6abe745
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Mon Oct 29 21:25:42 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/pprasad7/code/TextLCD/#de90b67b2bca