endpoint including temperature and distance sensors
Dependencies: mbed mbedConnectorInterface mbedEndpointNetwork TrashSensors
Fork of TempAndDistTest by
main.cpp@6:bbea44df21e8, 2015-05-05 (annotated)
- Committer:
- coyotebush
- Date:
- Tue May 05 05:18:03 2015 +0000
- Revision:
- 6:bbea44df21e8
- Parent:
- 4:1ca75e77ae33
- Child:
- 7:939fdc8df95b
Add TemperatureResource
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Luminoscity | 0:cb422b231ea5 | 1 | #include "mbed.h" |
coyotebush | 2:b51fcb5fd114 | 2 | #include "EthernetInterface.h" |
coyotebush | 2:b51fcb5fd114 | 3 | #include "ConnectorEndpoint.h" |
coyotebush | 2:b51fcb5fd114 | 4 | #include "OptionsBuilder.h" |
coyotebush | 2:b51fcb5fd114 | 5 | |
Luminoscity | 0:cb422b231ea5 | 6 | #include "hcsr04.h" |
Luminoscity | 0:cb422b231ea5 | 7 | #include "GroveTemp.h" |
coyotebush | 6:bbea44df21e8 | 8 | |
coyotebush | 2:b51fcb5fd114 | 9 | #include "OnBoardLED.h" |
coyotebush | 6:bbea44df21e8 | 10 | #include "TemperatureResource.h" |
Luminoscity | 0:cb422b231ea5 | 11 | |
coyotebush | 2:b51fcb5fd114 | 12 | #include "StaticResource.h" |
coyotebush | 2:b51fcb5fd114 | 13 | |
coyotebush | 2:b51fcb5fd114 | 14 | /* Terminal connection */ |
coyotebush | 2:b51fcb5fd114 | 15 | RawSerial term(USBTX, USBRX); |
coyotebush | 2:b51fcb5fd114 | 16 | Logger logger(&term); |
coyotebush | 2:b51fcb5fd114 | 17 | |
coyotebush | 2:b51fcb5fd114 | 18 | /* Sensors */ |
Luminoscity | 0:cb422b231ea5 | 19 | #define TRIG_PIN D6 |
Luminoscity | 0:cb422b231ea5 | 20 | #define ECHO_PIN D7 |
Luminoscity | 0:cb422b231ea5 | 21 | #define FIRE_THRESH 32.0 |
coyotebush | 2:b51fcb5fd114 | 22 | HCSR04 distS(TRIG_PIN, ECHO_PIN); |
coyotebush | 2:b51fcb5fd114 | 23 | GroveTempSensor tempS; |
Luminoscity | 0:cb422b231ea5 | 24 | |
coyotebush | 2:b51fcb5fd114 | 25 | /* Resources */ |
coyotebush | 2:b51fcb5fd114 | 26 | StaticResource mfg(&logger, "3/0/0", "Freescale"); |
coyotebush | 2:b51fcb5fd114 | 27 | StaticResource model(&logger, "3/0/1", "K64F mbed Ethernet demo"); |
coyotebush | 2:b51fcb5fd114 | 28 | |
coyotebush | 2:b51fcb5fd114 | 29 | /* |
coyotebush | 4:1ca75e77ae33 | 30 | DistanceResource distR(&logger, "3302/0/5600", distS); |
coyotebush | 2:b51fcb5fd114 | 31 | */ |
coyotebush | 6:bbea44df21e8 | 32 | TemperatureResource tempR(&logger, "3303/0/5700", &tempS, true); |
coyotebush | 2:b51fcb5fd114 | 33 | LEDResource led(&logger, "3311/1/5706"); |
Luminoscity | 0:cb422b231ea5 | 34 | |
coyotebush | 2:b51fcb5fd114 | 35 | /* invoked through linker magic via Endpoint::start() */ |
coyotebush | 2:b51fcb5fd114 | 36 | Connector::Options *configure_endpoint(Connector::OptionsBuilder &config) |
coyotebush | 2:b51fcb5fd114 | 37 | { |
coyotebush | 4:1ca75e77ae33 | 38 | /* NSP configuration is in nsp_configuration.h */ |
coyotebush | 2:b51fcb5fd114 | 39 | logger.log("configure_endpoint: building endpoint configuration..."); |
coyotebush | 6:bbea44df21e8 | 40 | tempR.setMaxAge(0); |
coyotebush | 2:b51fcb5fd114 | 41 | return config.addResource(&mfg) |
coyotebush | 2:b51fcb5fd114 | 42 | .addResource(&model) |
coyotebush | 2:b51fcb5fd114 | 43 | /* .addResource(&distR) */ |
coyotebush | 6:bbea44df21e8 | 44 | .addResource(&tempR) |
coyotebush | 2:b51fcb5fd114 | 45 | .addResource(&led) |
coyotebush | 2:b51fcb5fd114 | 46 | .build(); |
coyotebush | 2:b51fcb5fd114 | 47 | } |
coyotebush | 2:b51fcb5fd114 | 48 | |
Luminoscity | 0:cb422b231ea5 | 49 | int main() { |
coyotebush | 2:b51fcb5fd114 | 50 | double temperature; |
Luminoscity | 0:cb422b231ea5 | 51 | unsigned int distance; |
coyotebush | 2:b51fcb5fd114 | 52 | |
coyotebush | 2:b51fcb5fd114 | 53 | logger.log("\r\n\r\nSmart Trash Can booting\r\n"); |
coyotebush | 2:b51fcb5fd114 | 54 | Connector::Endpoint::plumbNetwork(); |
coyotebush | 2:b51fcb5fd114 | 55 | Connector::Endpoint::start(); |
coyotebush | 4:1ca75e77ae33 | 56 | // actually, we never reach here because the Endpoint takes over |
Luminoscity | 0:cb422b231ea5 | 57 | |
Luminoscity | 0:cb422b231ea5 | 58 | while (1) { |
Luminoscity | 0:cb422b231ea5 | 59 | temperature = tempS.getTemp() * 3.0 / 5.0; |
coyotebush | 2:b51fcb5fd114 | 60 | logger.logIt("Temp: %0.1f\n\r", temperature); |
Luminoscity | 0:cb422b231ea5 | 61 | if (temperature > FIRE_THRESH) { |
coyotebush | 2:b51fcb5fd114 | 62 | logger.logIt(" OMG! THE TRASH CAN CAN IS TOTALLY ON FIRE!!\n\r"); |
Luminoscity | 0:cb422b231ea5 | 63 | } |
Luminoscity | 0:cb422b231ea5 | 64 | |
Luminoscity | 0:cb422b231ea5 | 65 | distS.start(); |
Luminoscity | 0:cb422b231ea5 | 66 | wait_ms(500); |
Luminoscity | 0:cb422b231ea5 | 67 | distance = distS.get_dist_cm(); |
coyotebush | 2:b51fcb5fd114 | 68 | logger.logIt("Distance: %d\n\r", distance); |
Luminoscity | 0:cb422b231ea5 | 69 | } |
coyotebush | 2:b51fcb5fd114 | 70 | } |