s
wifi_example.cpp@2:a327e877a94c, 2022-03-01 (annotated)
- Committer:
- yezhong
- Date:
- Tue Mar 01 08:50:07 2022 +0000
- Revision:
- 2:a327e877a94c
- Parent:
- 1:8512a7d76959
- Child:
- 3:ff4d7f4f379c
1
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
TaylorGy | 0:cbe8a0553d45 | 1 | /************************************************************/ |
TaylorGy | 0:cbe8a0553d45 | 2 | /* (C) 2016 Beijing ARM Accelerator Technology Co., Ltd. */ |
TaylorGy | 0:cbe8a0553d45 | 3 | /* Description: Wifi Client by using Grove_wifi module. */ |
TaylorGy | 0:cbe8a0553d45 | 4 | /* Author: ss.pan */ |
TaylorGy | 0:cbe8a0553d45 | 5 | /* Version: 1.01 */ |
TaylorGy | 0:cbe8a0553d45 | 6 | /* Date: 2017-03-28 */ |
TaylorGy | 0:cbe8a0553d45 | 7 | /************************************************************/ |
TaylorGy | 0:cbe8a0553d45 | 8 | |
TaylorGy | 0:cbe8a0553d45 | 9 | #include "wifi_example.h" |
yezhong | 2:a327e877a94c | 10 | #include "ESP8266.h" |
yezhong | 2:a327e877a94c | 11 | #include "data_pc.h" |
TaylorGy | 0:cbe8a0553d45 | 12 | |
TaylorGy | 0:cbe8a0553d45 | 13 | ESP8266 wifi(PA_9,PA_10); |
TaylorGy | 0:cbe8a0553d45 | 14 | |
TaylorGy | 0:cbe8a0553d45 | 15 | |
TaylorGy | 0:cbe8a0553d45 | 16 | /** |
TaylorGy | 0:cbe8a0553d45 | 17 | * @brief initial ESP8266,and connect to wifi ap |
TaylorGy | 0:cbe8a0553d45 | 18 | **/ |
TaylorGy | 0:cbe8a0553d45 | 19 | void connectInit(void) |
TaylorGy | 0:cbe8a0553d45 | 20 | { |
yezhong | 2:a327e877a94c | 21 | bool ret; |
TaylorGy | 0:cbe8a0553d45 | 22 | pc.printf("starting......\r\n"); |
TaylorGy | 0:cbe8a0553d45 | 23 | wifi.reset(); |
TaylorGy | 0:cbe8a0553d45 | 24 | wait_ms(500); |
yezhong | 2:a327e877a94c | 25 | ret = wifi.startup(3); //start as client mode |
TaylorGy | 0:cbe8a0553d45 | 26 | wait_ms(200); |
TaylorGy | 0:cbe8a0553d45 | 27 | if(ret != true) { |
TaylorGy | 0:cbe8a0553d45 | 28 | pc.printf("startup failed\r\n"); |
TaylorGy | 0:cbe8a0553d45 | 29 | ret = true; |
TaylorGy | 0:cbe8a0553d45 | 30 | } else { |
TaylorGy | 0:cbe8a0553d45 | 31 | pc.printf("set as client mode\r\n"); |
TaylorGy | 0:cbe8a0553d45 | 32 | } |
yezhong | 2:a327e877a94c | 33 | |
TaylorGy | 0:cbe8a0553d45 | 34 | wifi.connect(APNAME,APPASSWD); //conenet to a existed wifi ap |
TaylorGy | 0:cbe8a0553d45 | 35 | wait_ms(200); |
TaylorGy | 0:cbe8a0553d45 | 36 | ret = wifi.isConnected(); //check whether connect successed |
TaylorGy | 0:cbe8a0553d45 | 37 | if(ret != true) { |
TaylorGy | 0:cbe8a0553d45 | 38 | pc.printf("connect failed\r\n"); |
TaylorGy | 0:cbe8a0553d45 | 39 | ret = true; |
TaylorGy | 0:cbe8a0553d45 | 40 | } else { |
TaylorGy | 0:cbe8a0553d45 | 41 | pc.printf("now connected!\r\n"); |
TaylorGy | 0:cbe8a0553d45 | 42 | } |
TaylorGy | 0:cbe8a0553d45 | 43 | pc.printf("the ip address is : %s\r\n",wifi.getIPAddress()); //send ip address to pc |
yezhong | 2:a327e877a94c | 44 | ret = wifi.open("UDP", TCPNUM, TCPADD, TCPPORT); //connte to a TCP socket |
yezhong | 2:a327e877a94c | 45 | if(ret != true) { |
yezhong | 2:a327e877a94c | 46 | pc.printf("connect failed\r\n"); |
yezhong | 2:a327e877a94c | 47 | ret = true; |
yezhong | 2:a327e877a94c | 48 | } else { |
yezhong | 2:a327e877a94c | 49 | pc.printf("connected success\r\n"); |
TaylorGy | 0:cbe8a0553d45 | 50 | } |
TaylorGy | 0:cbe8a0553d45 | 51 | } |
TaylorGy | 0:cbe8a0553d45 | 52 | |
TaylorGy | 0:cbe8a0553d45 | 53 | |
TaylorGy | 0:cbe8a0553d45 | 54 | |
TaylorGy | 0:cbe8a0553d45 | 55 |