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