IoT Example
Dependencies: C12832 LM75B MMA7660 MQTT mbed-rtos mbed
Fork of IBMIoTClientEthernetExample by
Revision 6:1a37fe371ee0, committed 2014-09-24
- Comitter:
- sam_grove
- Date:
- Wed Sep 24 21:47:40 2014 +0000
- Parent:
- 5:fe907e2e0d6c
- Child:
- 7:2fb7a98b559c
- Commit message:
- Perform a software reset if the Ethernet cable is disconnected. Check for cable present status before connecting too.
Changed in this revision
--- a/EthernetInterface.lib Thu Aug 21 12:42:19 2014 +0000 +++ b/EthernetInterface.lib Wed Sep 24 21:47:40 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/EthernetInterface/#e6b79f0ccd95 +http://mbed.org/users/mbed_official/code/EthernetInterface/#5887ae6c0c2c
--- a/LPC1768.h Thu Aug 21 12:42:19 2014 +0000 +++ b/LPC1768.h Wed Sep 24 21:47:40 2014 +0000 @@ -12,6 +12,7 @@ * * Contributors: * Ian Craggs - initial implementation + * Sam Grove - added mehtod to check the status of the Ethernet cable *******************************************************************************/ #if !defined(LPC1768_H) @@ -19,15 +20,29 @@ C12832 lcd(p5, p7, p6, p8, p11); DigitalOut led2(LED2); -PwmOut r(p23); PwmOut g(p24); PwmOut b(p25); +PwmOut r(p23); +PwmOut g(p24); +PwmOut b(p25); MMA7660 MMA(p28, p27); LM75B sensor(p28, p27); -DigitalIn Down(p12); DigitalIn Left(p13); DigitalIn Click(p14); DigitalIn Up(p15); DigitalIn Right(p16); -AnalogIn ain1(p19); AnalogIn ain2(p20); +DigitalIn Down(p12); +DigitalIn Left(p13); +DigitalIn Click(p14); +DigitalIn Up(p15); +DigitalIn Right(p16); +AnalogIn ain1(p19); +AnalogIn ain2(p20); #define LED2_OFF 0 #define LED2_ON 1 #define DEFAULT_TYPE_NAME "iotsample-mbed-lpc1768" +#include "lpc_phy.h" +// need a wrapper since K64F and LPC1768 wont have the same name for mii read methods +static uint32_t linkStatus(void) +{ + return (lpc_mii_read_data() & 1); +} + #endif \ No newline at end of file
--- a/main.cpp Thu Aug 21 12:42:19 2014 +0000 +++ b/main.cpp Wed Sep 24 21:47:40 2014 +0000 @@ -231,6 +231,12 @@ { int retryAttempt = 0; connected = false; + + // make sure a cable is connected before starting to connect + while (!linkStatus()) { + wait(1.0f); + WARN("Ethernet link not present. Check cable connection\n"); + } while (connect(client, ipstack) != 0) { @@ -373,6 +379,12 @@ int count = 0; while (true) { + if (!linkStatus()) { + NVIC_SystemReset(); + // if ipstack and client were on the heap we could deconstruct and goto a label where they are constructed + // or maybe just add the proper members to do this disconnect and call attemptConnect(...) + } + if (++count == 100) { // Publish a message every second if (publish(&client, &ipstack) != 0)
--- a/mbed-rtos.lib Thu Aug 21 12:42:19 2014 +0000 +++ b/mbed-rtos.lib Wed Sep 24 21:47:40 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#5dfe422a963d +http://mbed.org/users/mbed_official/code/mbed-rtos/#631c0f1008c3
--- a/mbed.bld Thu Aug 21 12:42:19 2014 +0000 +++ b/mbed.bld Wed Sep 24 21:47:40 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file