![](/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:
- 7:939fdc8df95b
- Parent:
- 6:bbea44df21e8
- Child:
- 8:c69fe28366d8
diff -r bbea44df21e8 -r 939fdc8df95b main.cpp --- a/main.cpp Tue May 05 05:18:03 2015 +0000 +++ b/main.cpp Wed May 06 02:53:36 2015 +0000 @@ -6,10 +6,10 @@ #include "hcsr04.h" #include "GroveTemp.h" +#include "StaticResource.h" #include "OnBoardLED.h" #include "TemperatureResource.h" - -#include "StaticResource.h" +#include "DistanceResource.h" /* Terminal connection */ RawSerial term(USBTX, USBRX); @@ -17,7 +17,7 @@ /* Sensors */ #define TRIG_PIN D6 -#define ECHO_PIN D7 +#define ECHO_PIN D5 #define FIRE_THRESH 32.0 HCSR04 distS(TRIG_PIN, ECHO_PIN); GroveTempSensor tempS; @@ -26,9 +26,7 @@ StaticResource mfg(&logger, "3/0/0", "Freescale"); StaticResource model(&logger, "3/0/1", "K64F mbed Ethernet demo"); -/* -DistanceResource distR(&logger, "3302/0/5600", distS); -*/ +DistanceResource distR(&logger, "3302/0/5600", &distS, true); TemperatureResource tempR(&logger, "3303/0/5700", &tempS, true); LEDResource led(&logger, "3311/1/5706"); @@ -37,10 +35,11 @@ { /* NSP configuration is in nsp_configuration.h */ logger.log("configure_endpoint: building endpoint configuration..."); - tempR.setMaxAge(0); + tempR.setMaxAge(5); + distR.setMaxAge(15); return config.addResource(&mfg) .addResource(&model) - /* .addResource(&distR) */ + .addResource(&distR) .addResource(&tempR) .addResource(&led) .build(); @@ -53,18 +52,4 @@ logger.log("\r\n\r\nSmart Trash Can booting\r\n"); Connector::Endpoint::plumbNetwork(); Connector::Endpoint::start(); - // actually, we never reach here because the Endpoint takes over - - while (1) { - temperature = tempS.getTemp() * 3.0 / 5.0; - logger.logIt("Temp: %0.1f\n\r", temperature); - if (temperature > FIRE_THRESH) { - logger.logIt(" OMG! THE TRASH CAN CAN IS TOTALLY ON FIRE!!\n\r"); - } - - distS.start(); - wait_ms(500); - distance = distS.get_dist_cm(); - logger.logIt("Distance: %d\n\r", distance); - } }