![](/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
Diff: main.cpp
- Revision:
- 5:e913a401b174
- Parent:
- 4:1ed7f173eec5
- Child:
- 6:0d838d564181
--- a/main.cpp Thu Apr 14 06:35:46 2016 +0000 +++ b/main.cpp Tue Apr 19 06:29:47 2016 +0000 @@ -11,23 +11,19 @@ DigitalOut myled(LED1); -SpwfSAInterface *spwf; -TCPSocket *tcp_; +SpwfSAInterface spwf(PA_9, PA_10, PC_12, PC_8, PA_12, true); +TCPSocket tcp_(&spwf); int main() { int32_t err; char * ssid = "STM"; char * seckey = "STMdemoPWD"; - char * hostname = "192.168.1.5"; char * data = "Hello World!\r\n"; uint32_t len = strlen(data); pc.printf("\r\nX-NUCLEO-IDW01M1 mbed Application\r\n"); - - spwf = createSPWFInstance(); - tcp_ = new TCPSocket(spwf); - err = spwf->init(); + err = spwf.init(); if(err!=0) { pc.printf("\r\n[APP] error initializing.\r\n"); @@ -36,7 +32,7 @@ pc.printf("\r\n[APP] connecting to AP\r\n"); - err = spwf->connect(ssid, seckey, NS_SECURITY_WPA); + err = spwf.connect(ssid, seckey, NS_SECURITY_WPA); if(err!=0) { pc.printf("\r\n[APP] error connecting to AP.\r\n"); @@ -45,23 +41,22 @@ pc.printf("\r\n[APP] now connected\r\n"); - const char *ip = spwf->getIPAddress(); - const char *mac = spwf->getMACAddress(); + const char *ip = spwf.getIPAddress(); + const char *mac = spwf.getMACAddress(); pc.printf("\r\n[APP] IP Address is: %s\r\n", (ip) ? ip : "No IP"); pc.printf("\r\n[APP] MAC Address is: %s\r\n", (mac) ? mac : "No MAC"); pc.printf("\r\n[APP] opening socket\r\n"); - //err = tcp_->open((const char *)hostname, 32000); - err = tcp_->open("time-d.nist.gov", 37); + err = tcp_.open("time-d.nist.gov", 37); if(err==0) { pc.printf("\r\n[APP] socket open OK\r\n"); - pc.printf("\r\n[APP] hostname resolved to: %s\r\n", tcp_->getIPAddress()); + pc.printf("\r\n[APP] hostname resolved to: %s\r\n", tcp_.getIPAddress()); - err = tcp_->send(data, len); + err = tcp_.send(data, len); if(err == 0) pc.printf("\r\n[APP] socket send OK\r\n"); @@ -71,7 +66,7 @@ char received[4]; int32_t size = 0; pc.printf("\r\n[APP] waiting for data recv\r\n"); - size = tcp_->recv(received, sizeof(received)); + size = tcp_.recv(received, sizeof(received)); if(size==0) pc.printf("\r\n[APP] Receive error."); else