![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
INSAT_MiniPRoject
Dependencies: MQTT NDefLib NetworkSocketAPI Servo Light_Sensor_Nucleo X_NUCLEO_IDW01M1v2 mbed
Fork of IDW01M1_Cloud_IBM by
main.cpp@6:0d838d564181, 2016-04-19 (annotated)
- Committer:
- mridup
- Date:
- Tue Apr 19 07:19:55 2016 +0000
- Revision:
- 6:0d838d564181
- Parent:
- 5:e913a401b174
- Child:
- 8:6df01cb43137
removing init() from main
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mridup | 0:cbf8bc43bc9e | 1 | #include "mbed.h" |
mridup | 0:cbf8bc43bc9e | 2 | #include "SPWFInterface.h" |
mridup | 4:1ed7f173eec5 | 3 | #include "TCPSocket.h" |
mridup | 0:cbf8bc43bc9e | 4 | |
mridup | 0:cbf8bc43bc9e | 5 | //------------------------------------ |
mridup | 0:cbf8bc43bc9e | 6 | // Hyperterminal configuration |
mridup | 0:cbf8bc43bc9e | 7 | // 9600 bauds, 8-bit data, no parity |
mridup | 0:cbf8bc43bc9e | 8 | //------------------------------------ |
mridup | 0:cbf8bc43bc9e | 9 | |
mridup | 0:cbf8bc43bc9e | 10 | Serial pc(SERIAL_TX, SERIAL_RX); |
mridup | 4:1ed7f173eec5 | 11 | |
mridup | 3:dfb8c6c8c31b | 12 | DigitalOut myled(LED1); |
mridup | 4:1ed7f173eec5 | 13 | |
mridup | 5:e913a401b174 | 14 | SpwfSAInterface spwf(PA_9, PA_10, PC_12, PC_8, PA_12, true); |
mridup | 5:e913a401b174 | 15 | TCPSocket tcp_(&spwf); |
mridup | 4:1ed7f173eec5 | 16 | |
mridup | 4:1ed7f173eec5 | 17 | int main() { |
mridup | 4:1ed7f173eec5 | 18 | int32_t err; |
mridup | 0:cbf8bc43bc9e | 19 | char * ssid = "STM"; |
mridup | 0:cbf8bc43bc9e | 20 | char * seckey = "STMdemoPWD"; |
mridup | 4:1ed7f173eec5 | 21 | char * data = "Hello World!\r\n"; |
mridup | 4:1ed7f173eec5 | 22 | uint32_t len = strlen(data); |
mridup | 4:1ed7f173eec5 | 23 | |
mridup | 6:0d838d564181 | 24 | pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n"); |
mridup | 4:1ed7f173eec5 | 25 | pc.printf("\r\n[APP] connecting to AP\r\n"); |
mridup | 0:cbf8bc43bc9e | 26 | |
mridup | 5:e913a401b174 | 27 | err = spwf.connect(ssid, seckey, NS_SECURITY_WPA); |
mridup | 4:1ed7f173eec5 | 28 | if(err!=0) |
mridup | 4:1ed7f173eec5 | 29 | { |
mridup | 4:1ed7f173eec5 | 30 | pc.printf("\r\n[APP] error connecting to AP.\r\n"); |
mridup | 4:1ed7f173eec5 | 31 | return -1; |
mridup | 0:cbf8bc43bc9e | 32 | } |
mridup | 4:1ed7f173eec5 | 33 | |
mridup | 4:1ed7f173eec5 | 34 | pc.printf("\r\n[APP] now connected\r\n"); |
mridup | 4:1ed7f173eec5 | 35 | |
mridup | 5:e913a401b174 | 36 | const char *ip = spwf.getIPAddress(); |
mridup | 5:e913a401b174 | 37 | const char *mac = spwf.getMACAddress(); |
mridup | 4:1ed7f173eec5 | 38 | |
mridup | 4:1ed7f173eec5 | 39 | pc.printf("\r\n[APP] IP Address is: %s\r\n", (ip) ? ip : "No IP"); |
mridup | 4:1ed7f173eec5 | 40 | pc.printf("\r\n[APP] MAC Address is: %s\r\n", (mac) ? mac : "No MAC"); |
mridup | 4:1ed7f173eec5 | 41 | |
mridup | 4:1ed7f173eec5 | 42 | pc.printf("\r\n[APP] opening socket\r\n"); |
mridup | 4:1ed7f173eec5 | 43 | |
mridup | 5:e913a401b174 | 44 | err = tcp_.open("time-d.nist.gov", 37); |
mridup | 4:1ed7f173eec5 | 45 | |
mridup | 4:1ed7f173eec5 | 46 | if(err==0) |
mridup | 4:1ed7f173eec5 | 47 | { |
mridup | 4:1ed7f173eec5 | 48 | pc.printf("\r\n[APP] socket open OK\r\n"); |
mridup | 5:e913a401b174 | 49 | pc.printf("\r\n[APP] hostname resolved to: %s\r\n", tcp_.getIPAddress()); |
mridup | 4:1ed7f173eec5 | 50 | |
mridup | 5:e913a401b174 | 51 | err = tcp_.send(data, len); |
mridup | 4:1ed7f173eec5 | 52 | |
mridup | 4:1ed7f173eec5 | 53 | if(err == 0) |
mridup | 4:1ed7f173eec5 | 54 | pc.printf("\r\n[APP] socket send OK\r\n"); |
mridup | 4:1ed7f173eec5 | 55 | else |
mridup | 4:1ed7f173eec5 | 56 | pc.printf("\r\n[APP] socket send error\r\n"); |
mridup | 4:1ed7f173eec5 | 57 | |
mridup | 4:1ed7f173eec5 | 58 | char received[4]; |
mridup | 4:1ed7f173eec5 | 59 | int32_t size = 0; |
mridup | 4:1ed7f173eec5 | 60 | pc.printf("\r\n[APP] waiting for data recv\r\n"); |
mridup | 5:e913a401b174 | 61 | size = tcp_.recv(received, sizeof(received)); |
mridup | 4:1ed7f173eec5 | 62 | if(size==0) |
mridup | 4:1ed7f173eec5 | 63 | pc.printf("\r\n[APP] Receive error."); |
mridup | 4:1ed7f173eec5 | 64 | else |
mridup | 4:1ed7f173eec5 | 65 | pc.printf("\r\n[APP] Received: %ld bytes, 0x%02x 0x%02x 0x%02x 0x%02x\r\n", size, received[0], received[1], received[2], received[3]); |
mridup | 4:1ed7f173eec5 | 66 | } |
mridup | 4:1ed7f173eec5 | 67 | else |
mridup | 4:1ed7f173eec5 | 68 | pc.printf("\r\n[APP] socket open Error\r\n"); |
mridup | 4:1ed7f173eec5 | 69 | |
mridup | 4:1ed7f173eec5 | 70 | while(1) { |
mridup | 4:1ed7f173eec5 | 71 | wait(1); |
mridup | 4:1ed7f173eec5 | 72 | myled = !myled; |
mridup | 3:dfb8c6c8c31b | 73 | } |
mridup | 4:1ed7f173eec5 | 74 | } |