Using RPCVariable so PC can query a temperature

27 Nov 2010

I'm a novice C++ user, but I'm having fun with the mbed.

I want the mbed to read a temperature, and make that temperature available for PC query using Javascript.

I have had good results with the examples of remotely turning on/off LEDs using RPC. I have also interfaced a temperature sensor (using the TMP102 library) and can display the value locally on a LCD.

But when I try to use RPCVariable to allow the temperature to be queried over HTTP, I get compiler error 70 (Incomplete type is not allowed) at line 80 of the RPCVariable library.

I'm stuck. Any suggestions would be welcome!

Listing below: __________________

  1. include "mbed.h"
  2. include "EthernetNetIf.h"
  3. include "HTTPServer.h"
  4. include "RPCVariable.h"
  5. include "TMP102.h"
  6. include "TextLCD.h"

float TempC;

LocalFileSystem fs("webfs");

TextLCD lcd(p11, p25, p12, p15, p16, p29, p30); rs, rw, e, d0, d1, d2, d3 ;

EthernetNetIf eth;

TMP102 temperature(p9, p10, 0x90); A0 pin is connected to ground

HTTPServer svr;

Make this variable accessible over RPC by attaching them to an RPCVariable;

RPCVariable<float> RPCTempC(&TempC, "TempC");

int main() { lcd.printf("Setting up...\n");

EthernetErr ethErr = eth.setup();

if(ethErr) { lcd.printf("Error %d in setup.\n", ethErr); return -1; } lcd.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 svr.bind(80);

lcd.printf("Listening...\n");

Listen indefinitely

while (true) { TempC = temperature.read();

lcd.printf("Temp: %f\n", TempC);

wait(.5); }

return 0; }

27 Nov 2010

Update the Library(in the compiler right click on the library). I've fixed an error in the Library- there should now not be any issues with this. Thanks for finding this

Michael

27 Nov 2010

Michael,

THANK YOU!!

Being new at this, I thought it was my code. With your update, my code compiled without error.

Now the fun begins with Javascript.... ;-)

Russ Steinbach