HTTP RPC Server mit vordefinierten Objekten

Dependencies:   EthernetInterface HttpServer Servo mbed-rtos mbed

Fork of RPCHTTPServerVariable by th.iotkit2.ch

Mittels RPCVariable lassen sich lokale Variablen setzen. Diese Variablen können gesetzt write oder gelesen read werden.

Mittels Ticker u.ä. Varianten lassen sich damit auch Objektwerte setzen, welche von RPC nicht unterstützt werden, z.B. Servo's.

Client

Wert setzen: http://<IP-Adresse mbed>/rpc/servo2/write+0.5

main.cpp

Committer:
marcel1691
Date:
2015-01-14
Revision:
6:c9c7ffa0594e
Parent:
5:bfa9878aa274
Child:
7:8a319a112fba

File content as of revision 6:c9c7ffa0594e:

//#define DNS_SERVER_ADDRESS(ipaddr)        (ip4_addr_set_u32(ipaddr, ipaddr_addr("208.67.222.222"))) /* resolver1.opendns.com */

#include "mbed.h"
#include "rtos.h"
#include "EthernetInterface.h"
#include "HTTPServer.h"
#include "mbed_rpc.h"
#include "SDFileSystem.h"

EthernetInterface eth;

DigitalOut led4(LED4);

//LocalFileSystem local("local");
SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "local"); 

void aliveState(void const *args)
{
    while (true) 
    {
        led4 = !led4;
        Thread::wait(2000);
    }
}

uint32_t do_list(const char *fsrc)
{
    DIR *d = opendir(fsrc);
    struct dirent *p;
    uint32_t counter = 0;

    while ((p = readdir(d)) != NULL) {
        counter++;
        printf("%s\n", p->d_name);
    }
    closedir(d);
    return counter;
}

int main()
{
    printf("********* PROGRAM START ***********\r\n");
    Thread thread(aliveState);
    RPC::add_rpc_class<RpcDigitalOut>();
    RPC::construct<RpcDigitalOut, PinName, const char*>(PTC3, "led1");
    RPC::construct<RpcDigitalOut, PinName, const char*>(PTC2, "led2");
    RPC::construct<RpcDigitalOut, PinName, const char*>(PTA2, "led3");
    //RPCFunction rpcFunc(LcdWrite, "LcdWrite"); //ADD Here!!

    printf("EthernetInterface Setting up...\r\n");
    if(eth.init()!=0) 
    {                             //for DHCP Server
        //if(eth.init(IPAddress,NetMasks,Gateway)!=0) { //for Static IP Address
        printf("EthernetInterface Initialize Error \r\n");
        return -1;
    }
    if(eth.connect()!=0) 
    {
        printf("EthernetInterface Connect Error \r\n");
        return -1;
    }
    printf("IP Address is %s\r\n", eth.getIPAddress());
    printf("NetMask is %s\r\n", eth.getNetworkMask());
    printf("Gateway Address is %s\r\n", eth.getGateway());
    printf("Ethernet Setup OK\r\n");

    printf("\nList all directories/files /local.\n");
    do_list("/local");

    HTTPServerAddHandler<SimpleHandler>("/hello"); //Default handler
    FSHandler::mount("/local", "/");
    HTTPServerAddHandler<FSHandler>("/");
    HTTPServerAddHandler<RPCHandler>("/rpc");
    HTTPServerStart(80);
}

void LcdWrite(Arguments* arg, Reply* r)  //ADD Here!!
{
    printf("%s",arg->argv[0]);
}