This is a modification of the NTPClient_HelloWorld to use the wifly link instead of the eth link
Dependencies: mbed LM75B NTPClient WiflyInterface MMA7660 WebSocketClient
Revision 7:cf51acd03e52, committed 2019-11-10
- Comitter:
- jpelletier
- Date:
- Sun Nov 10 04:58:15 2019 +0000
- Parent:
- 6:b420491ecd8d
- Commit message:
- Initial commit
Changed in this revision
diff -r b420491ecd8d -r cf51acd03e52 NTPClient.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/NTPClient.lib Sun Nov 10 04:58:15 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/donatien/code/NTPClient/#881559865a93
diff -r b420491ecd8d -r cf51acd03e52 main.cpp --- a/main.cpp Fri Feb 08 13:14:09 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,49 +0,0 @@ -#include "mbed.h" -#include "WiflyInterface.h" -#include "Websocket.h" -#include "LM75B.h" -#include "MMA7660.h" - - -/* wifly interface: -* - p9 and p10 are for the serial communication -* - p30 is for the reset pin -* - p29 is for the connection status -* - "mbed" is the ssid of the network -* - "password" is the password -* - WPA is the security -*/ - -WiflyInterface wifly(p9, p10, p30, p29, "mbed", "password", WPA); - -// accelerometer -MMA7660 acc(p28, p27); - -// temperature sensor -LM75B tmp(p28,p27); - - -int main() -{ - char json_str[100]; - - wifly.init(); //Use DHCP - while (!wifly.connect()); - printf("IP Address is %s\n\r", wifly.getIPAddress()); - - // See the output on http://sockets.mbed.org/app-board/viewer - Websocket ws("ws://sockets.mbed.org:443/ws/app-board/wo"); - - // connect WS server - while (!ws.connect()); - - while (1) { - // create json string with acc/tmp data - sprintf(json_str, "{\"id\":\"app_board_wifly_EW2013\",\"ax\":%d,\"ay\":%d,\"az\":%d, \"tmp\":%d}", (int)(acc.x()*360), (int)(acc.y()*360), (int)(acc.z()*360), (int)tmp.read()); - - // send str - ws.send(json_str); - - wait(0.1); - } -} \ No newline at end of file
diff -r b420491ecd8d -r cf51acd03e52 wifly-ntpc.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wifly-ntpc.cpp Sun Nov 10 04:58:15 2019 +0000 @@ -0,0 +1,36 @@ +#include "mbed.h" +#include "WiflyInterface.h" +#include "LM75B.h" +#include "MMA7660.h" +#include "NTPClient.h" + +/* wifly interface: +* - p9 and p10 are for the serial communication +* - p30 is for the reset pin +* - p29 is for the connection status +* - "mbed" is the ssid of the network +* - "password" is the password +* - WPA is the security +*/ +WiflyInterface wifly(p9, p10, p30, p29, "mbed", "password", WPA); +NTPClient ntp; + +int main() +{ + wifly.init(); //Use DHCP + while (!wifly.connect()); + printf("IP Address is %s\n\r", wifly.getIPAddress()); + + printf("Trying to update time...\r\n"); + if (ntp.setTime("0.pool.ntp.org") == 0) + { + printf("Set time successfully\r\n"); + time_t ctTime; + ctTime = time(NULL); + printf("Time is set to (UTC): %s\r\n", ctime(&ctTime)); + } + else + { + printf("Error\r\n"); + } +} \ No newline at end of file