Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: EthernetInterface mbed-rtos mbed GR-PEACH_WlanBP3595STA
main.cpp
00001 /* This is a sample application program for GR-PEACH_WlanBP3595STA library. */ 00002 /* GR-PEACH_WlanBP3595STA library only works with GR-PEACH. */ 00003 /* This sample works as TCP socket sever, and this program sends a message */ 00004 /* when a connection is accepted. */ 00005 00006 /* 00007 Warning! 00008 When exporting and using it, increase the following stack size. 00009 00010 [EthernetInterface/lwip/lwipopts.h]--------- 00011 #define TCPIP_THREAD_STACKSIZE 1024 00012 -> 00013 #define TCPIP_THREAD_STACKSIZE 2048 00014 -------------------------------------------- 00015 */ 00016 00017 /* 00018 This works with the following library. 00019 mbed-rtos : revision 115 00020 */ 00021 00022 #include "mbed.h" 00023 #include "rtos.h" 00024 #include "GR_PEACH_WlanBP3595.h" 00025 00026 /* Please change the following macro definition to your setting. */ 00027 #define WLAN_SSID ("SSIDofYourAP") // SSID 00028 #define WLAN_PSK ("PSKofYourAP") // PSK(Pre-Shared Key) 00029 #define SERVER_IP ("192.168.1.200") // Server IP address 00030 #define SERVER_PORT (50000) // TCP server socket port number 00031 #define SUBNET_MASK ("255.255.255.0") // Subnet mask 00032 #define DEFAULT_GATEWAY ("192.168.1.1") // Default gateway 00033 #define SEND_MESSAGE ("Hello, world!\r\n") // Send-message 00034 00035 static void _wlan_inf_callback(uint8_t ucType, uint16_t usWid, uint16_t usSize, uint8_t *pucData); 00036 00037 DigitalOut red_led(LED1); // On: error 00038 DigitalOut green_led(LED2); // On: WLAN has been connected 00039 00040 /** Main function 00041 * 00042 */ 00043 int main() { 00044 GR_PEACH_WlanBP3595 wlan; 00045 TCPSocketServer server; 00046 TCPSocketConnection connection; 00047 int ret; 00048 00049 wlan.setWlanCbFunction(_wlan_inf_callback); 00050 00051 /* Initialize GR_PEACH_WlanBP3595 */ 00052 ret = wlan.init(SERVER_IP, SUBNET_MASK, DEFAULT_GATEWAY); 00053 if (ret != 0) { 00054 /* error */ 00055 red_led = 1; 00056 while (1) { Thread::wait(1000); } 00057 } 00058 00059 /* Connect(GR_PEACH_WlanBP3595) */ 00060 ret = wlan.connect(WLAN_SSID, WLAN_PSK); 00061 if (ret != 0) { 00062 /* error */ 00063 red_led = 1; 00064 while (1) { Thread::wait(1000); } 00065 } 00066 00067 /* Bind and listen */ 00068 server.bind(SERVER_PORT); 00069 server.listen(); 00070 00071 /* Loop */ 00072 while (1) { 00073 /* Accept */ 00074 server.accept(connection); 00075 printf("Connection from: %s\n", connection.get_address()); 00076 00077 /* Send a message */ 00078 connection.send_all((char *)SEND_MESSAGE, sizeof(SEND_MESSAGE)-1); 00079 00080 /* Close */ 00081 connection.close(); 00082 } 00083 } 00084 00085 /** WLAN Information callback function 00086 * 00087 */ 00088 static void _wlan_inf_callback(uint8_t ucType, uint16_t usWid, uint16_t usSize, uint8_t *pucData) 00089 { 00090 if (ucType == 'I') { 00091 if (usWid == 0x0005) { // WID_STATUS 00092 if (pucData[0] == 0x01) { // CONNECTED 00093 green_led = 1; 00094 } else { 00095 green_led = 0; 00096 } 00097 } 00098 } 00099 }
Generated on Sun Jul 17 2022 01:57:32 by
1.7.2
BP3595 for GR-PEACH