Evrythng API Example for W5500 (WIZnet chip)
Dependencies: EvrythngApi mbed
Fork of EvrythngApiExample by
Evrythng Example for W5500.
Diff: main.cpp
- Revision:
- 1:5cdbdabe6577
- Parent:
- 0:85d6be554642
diff -r 85d6be554642 -r 5cdbdabe6577 main.cpp --- a/main.cpp Thu Aug 30 13:57:45 2012 +0000 +++ b/main.cpp Wed Aug 20 01:58:11 2014 +0000 @@ -31,12 +31,12 @@ /* * Configuration */ - + // Your EVRYTHNG api key. -const char* API_KEY = ""; +const char* API_KEY = "893TNJV2vmdCsxDEpBqTwc2yIExFuPtuRInmRqGixhcpDZktrIv7YP2VeIsXrTMwtRF991OEJZutZYNI"; // Your thng id, the one that represents your mbed device. -const char* THNG_ID = ""; +const char* THNG_ID = "UdtxHEK4PeKwtwEnqa2wgshc"; // The property you want values to be pushed to. const char* THNG_PROP_SET = "prop3"; @@ -80,7 +80,7 @@ display(s); } -/* +/* * Function to get the number of milliseconds elapsed since the system startup. * It is imprecise and if called repetitively and quickly, it may always return * the same result. It MUST be called at least every 30 minutes. @@ -90,18 +90,18 @@ { static Timer tmr; static int64_t clk = 0; - + tmr.stop(); clk += tmr.read_ms(); tmr.reset(); tmr.start(); - + char str[21]; char* end; sprinti64(str, clk, &end); *end = '\0'; dbg.printf("%s ", str); - + return clk; } @@ -114,60 +114,98 @@ int main() { dbg.printf("Initializing ethernet interface\r\n"); - EthernetInterface eth; +// EthernetInterface eth; +#if defined(TARGET_LPC1114) + SPI spi(dp2, dp1, dp6); // mosi, miso, sclk + EthernetInterface eth(&spi, dp25, dp26); // spi, cs, reset + wait(1); // 1 second for stable state +#elif defined(TARGET_LPC1768) + SPI spi(p11, p12, p13); // mosi, miso, sclk + EthernetInterface eth(&spi, p14, p15); // spi, cs, reset + wait(1); // 1 second for stable state +#elif defined(TARGET_LPC11U68) + SPI spi(P0_9, P0_8, P1_29); // mosi, miso, sclk + EthernetInterface eth(&spi, P0_2, P1_28);//, nRESET(p9); // reset pin is dummy, don't affect any pin of WIZ550io + spi.format(8,0); // 8bit, mode 0 + spi.frequency(7000000); // 7MHz + wait(1); // 1 second for stable state +#endif + eth.init(); //Use DHCP + dbg.printf("init\r\n"); eth.connect(); dbg.printf("IP address: %s\r\n", eth.getIPAddress()); EvrythngApi api(API_KEY); - // intervals in ms - const int SET_INTERVAL = 5000; - const int GET_INTERVAL = 2000; - + /* + // intervals in ms + const int SET_INTERVAL = 5000; + const int GET_INTERVAL = 2000; + */ int curVal = 0; display(curVal); int putVal = 0; - char strPutVal[3]; - int64_t timestamp = 1345736694000LL; // 2012-08-23 10:44:54am EST + char strPutVal[3]; +// int64_t timestamp = 1345736694000LL; // 2012-08-23 10:44:54am EST + int64_t timestamp = 1408494102000LL; // 08/20/2014 @ 12:21am in UTC + + /* + - EventQueue eventQueue; - eventQueue.put(getMillis()+GET_INTERVAL, EVT_GET_PROP); - eventQueue.put(getMillis()+SET_INTERVAL, EVT_SET_PROP); + EventQueue eventQueue; + eventQueue.put(getMillis()+GET_INTERVAL, EVT_GET_PROP); + eventQueue.put(getMillis()+SET_INTERVAL, EVT_SET_PROP); + + while (!eventQueue.empty()) { + EventType event = eventQueue.waitNext(getMillis()); - while (!eventQueue.empty()) { - EventType event = eventQueue.waitNext(getMillis()); + switch (event) { + + case EVT_SET_PROP: + eventQueue.put(SET_INTERVAL + getMillis(), EVT_SET_PROP); - switch (event) { + putVal = (putVal + 1) & 0xF; + sprintf(strPutVal, "%d", putVal); + timestamp++; + api.setThngPropertyValue(THNG_ID, THNG_PROP_SET, string(strPutVal), timestamp); - case EVT_SET_PROP: + break; - eventQueue.put(SET_INTERVAL + getMillis(), EVT_SET_PROP); + case EVT_GET_PROP: + eventQueue.put(GET_INTERVAL + getMillis(), EVT_GET_PROP); - putVal = (putVal + 1) & 0xF; - sprintf(strPutVal, "%d", putVal); - timestamp++; - api.setThngPropertyValue(THNG_ID, THNG_PROP_SET, string(strPutVal), timestamp); - - break; - - case EVT_GET_PROP: - - eventQueue.put(GET_INTERVAL + getMillis(), EVT_GET_PROP); + string v; + int r = api.getThngPropertyValue(THNG_ID, THNG_PROP_GET, v); + if (r == 0) { + flash(); + int newVal = atoi(v.c_str()); + if (newVal != curVal) { + curVal = newVal; + display(curVal); + } + } + break; + } + } + */ - string v; - int r = api.getThngPropertyValue(THNG_ID, THNG_PROP_GET, v); - if (r == 0) { - flash(); - int newVal = atoi(v.c_str()); - if (newVal != curVal) { - curVal = newVal; - display(curVal); - } - } - break; - } +// change to very simple demo, put value and get. finish. + + putVal = 28; + dbg.printf("Putting value is %d\r\n", putVal); + sprintf(strPutVal, "%d", putVal); + timestamp++; + api.setThngPropertyValue(THNG_ID, THNG_PROP_SET, string(strPutVal), timestamp); + + string v; + int r = api.getThngPropertyValue(THNG_ID, THNG_PROP_GET, v); + if (r == 0) { + flash(); + int newVal = atoi(v.c_str()); + display(newVal); + dbg.printf("Getting value is %d\r\n", newVal); } dbg.printf("Disconnecting ethernet interface\r\n");