s
wifi_example.cpp
- Committer:
- yezhong
- Date:
- 2022-03-01
- Revision:
- 2:a327e877a94c
- Parent:
- 1:8512a7d76959
- Child:
- 3:ff4d7f4f379c
File content as of revision 2:a327e877a94c:
/************************************************************/ /* (C) 2016 Beijing ARM Accelerator Technology Co., Ltd. */ /* Description: Wifi Client by using Grove_wifi module. */ /* Author: ss.pan */ /* Version: 1.01 */ /* Date: 2017-03-28 */ /************************************************************/ #include "wifi_example.h" #include "ESP8266.h" #include "data_pc.h" ESP8266 wifi(PA_9,PA_10); /** * @brief initial ESP8266,and connect to wifi ap **/ void connectInit(void) { bool ret; pc.printf("starting......\r\n"); wifi.reset(); wait_ms(500); ret = wifi.startup(3); //start as client mode wait_ms(200); if(ret != true) { pc.printf("startup failed\r\n"); ret = true; } else { pc.printf("set as client mode\r\n"); } wifi.connect(APNAME,APPASSWD); //conenet to a existed wifi ap wait_ms(200); ret = wifi.isConnected(); //check whether connect successed if(ret != true) { pc.printf("connect failed\r\n"); ret = true; } else { pc.printf("now connected!\r\n"); } pc.printf("the ip address is : %s\r\n",wifi.getIPAddress()); //send ip address to pc ret = wifi.open("UDP", TCPNUM, TCPADD, TCPPORT); //connte to a TCP socket if(ret != true) { pc.printf("connect failed\r\n"); ret = true; } else { pc.printf("connected success\r\n"); } }