Proof of concept for distance and temperature monitoring

Dependencies:   mbed mbedConnectorInterface mbedEndpointNetwork

main.cpp

Committer:
coyotebush
Date:
2015-05-06
Revision:
8:c69fe28366d8
Parent:
7:939fdc8df95b
Child:
9:16b63cd4aba8

File content as of revision 8:c69fe28366d8:

#include "mbed.h"
#include "EthernetInterface.h"
#include "ConnectorEndpoint.h"
#include "OptionsBuilder.h"

#include "hcsr04.h"
#include "GroveTemp.h"

#include "StaticResource.h"
#include "OnBoardLED.h"
#include "TemperatureResource.h"
#include "DistanceResource.h"

/* Terminal connection */
RawSerial term(USBTX, USBRX);
Logger logger(&term);

/* Sensors */
#define TRIG_PIN D6
#define ECHO_PIN D5
#define FIRE_THRESH 32.0
HCSR04 distS(TRIG_PIN, ECHO_PIN); 
GroveTempSensor tempS;

/* Resources */
StaticResource mfg(&logger, "3/0/0", "Freescale");
StaticResource model(&logger, "3/0/1", "K64F mbed Ethernet demo");

DistanceResource distR(&logger, "3302/0/5600", &distS, true);
TemperatureResource tempR(&logger, "3303/0/5700", &tempS, true);
LEDResource led(&logger, "3311/1/5706");

/* invoked through linker magic via Endpoint::start() */
Connector::Options *configure_endpoint(Connector::OptionsBuilder &config)
{
    /* NSP configuration is in nsp_configuration.h */
    logger.log("configure_endpoint: building endpoint configuration...");
    tempR.setMaxAge(5);
    distR.setMaxAge(15);
    return config.addResource(&mfg)
                 .addResource(&model)
                 .addResource(&distR)
                 .addResource(&tempR)
                 .addResource(&led)
                 .build();
}

int main() {
   logger.log("\r\n\r\nSmart Trash Can booting\r\n");
   Connector::Endpoint::plumbNetwork();
   Connector::Endpoint::start();
}