![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Proof of concept for distance and temperature monitoring
Dependencies: mbed mbedConnectorInterface mbedEndpointNetwork
Diff: main.cpp
- Revision:
- 3:b51fcb5fd114
- Parent:
- 1:2d8c4995c5bc
- Child:
- 4:1ca75e77ae33
--- a/main.cpp Fri May 01 23:24:06 2015 +0000 +++ b/main.cpp Sat May 02 01:10:55 2015 +0000 @@ -1,30 +1,72 @@ #include "mbed.h" +#include "EthernetInterface.h" +#include "ConnectorEndpoint.h" +#include "OptionsBuilder.h" + #include "hcsr04.h" #include "GroveTemp.h" +#include "OnBoardLED.h" +#include "StaticResource.h" + +/* CoAP/NSP */ +uint8_t my_nsp_address[NSP_IP_ADDRESS_LENGTH] = {54, 191, 98, 247}; +int my_nsp_coap_port = 5683; +#define MY_NSP_DOMAIN "trash" +#define MY_ENDPOINT_NAME "trashcan" +EthernetInterface ethernet; + +/* Terminal connection */ +RawSerial term(USBTX, USBRX); +Logger logger(&term); + +/* Sensors */ #define TRIG_PIN D6 #define ECHO_PIN D7 #define FIRE_THRESH 32.0 +HCSR04 distS(TRIG_PIN, ECHO_PIN); +GroveTempSensor tempS; -Serial term(USBTX, USBRX); -HCSR04 distS(TRIG_PIN, ECHO_PIN); +/* Resources */ +StaticResource mfg(&logger, "3/0/0", "Freescale"); +StaticResource model(&logger, "3/0/1", "K64F mbed Ethernet demo"); + +/* +DistanceResource distS(&logger, "3302/0/5600", distS); +TemperatureResource tempR(&logger, "3303/0/5700", tempS); +*/ +LEDResource led(&logger, "3311/1/5706"); -// Corey was here +/* invoked through linker magic via Endpoint::start() */ +Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) +{ + logger.log("configure_endpoint: building endpoint configuration..."); + return config.addResource(&mfg) + .addResource(&model) + /* .addResource(&distR) */ + /* .addResource(&tempR) */ + .addResource(&led) + .build(); +} + int main() { - GroveTempSensor tempS; - float temperature; + double temperature; unsigned int distance; + + logger.log("\r\n\r\nSmart Trash Can booting\r\n"); + Connector::Endpoint::plumbNetwork(); + Connector::Endpoint::start(); while (1) { temperature = tempS.getTemp() * 3.0 / 5.0; - term.printf("Temp: %0.1f\n\r", temperature); + logger.logIt("Temp: %0.1f\n\r", temperature); if (temperature > FIRE_THRESH) { - term.printf(" OMG! THE TRASH CAN CAN IS TOTALLY ON FIRE!!\n\r"); + logger.logIt(" OMG! THE TRASH CAN CAN IS TOTALLY ON FIRE!!\n\r"); } distS.start(); wait_ms(500); distance = distS.get_dist_cm(); - term.printf("Distance: %d\n\r", distance); + logger.logIt("Distance: %d\n\r", distance); } -} \ No newline at end of file +}