This is a sample application program for GR-PEACH_WlanBP3595AP library. GR-PEACH_WlanBP3595AP library only works with GR-PEACH. This sample works as TCP socket sever, and this program sends a message when a connection is accepted.
Dependencies: EthernetInterface GR-PEACH_WlanBP3595AP mbed-rtos mbed
Fork of GR-PEACH_WlanBP3595AP_sample by
Revision 1:3eae92f063c3, committed 2016-05-31
- Comitter:
- tousaki
- Date:
- Tue May 31 07:20:18 2016 +0000
- Parent:
- 0:d1c30577e772
- Child:
- 2:59a519fa59d0
- Commit message:
- Changed the structure of the library
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Tue May 31 07:20:18 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#183490eb1b4a
--- a/EthernetInterface_GR-PEACH_WlanBP3595AP.lib Fri Dec 25 08:28:10 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -https://developer.mbed.org/teams/Rohm/code/EthernetInterface_GR-PEACH_WlanBP3595AP/#86da568fe761
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GR-PEACH_WlanBP3595AP.lib Tue May 31 07:20:18 2016 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/teams/Rohm/code/GR-PEACH_WlanBP3595AP/#4110367a9949
--- a/main.cpp Fri Dec 25 08:28:10 2015 +0000
+++ b/main.cpp Tue May 31 07:20:18 2016 +0000
@@ -2,16 +2,9 @@
/* This program works as TCP socket sever, and this program sends a message */
/* when a connection is accepted. The setting of the WLAN is WPA2+AES. */
-/*
-This program works with the following libraries.
- mbed-rtos : revision 84
- EthernetInterface_GR-PEACH_WlanBP3595AP : revision 50
-*/
-
#include "mbed.h"
#include "rtos.h"
-#include "EthernetInterface.h"
-#include "WlanBP3595.h"
+#include "GR_PEACH_WlanBP3595.h"
/* Please change the following macro definition to your setting. */
#define WLAN_SSID ("GR-PEACH_WlanTest") // SSID
@@ -20,11 +13,9 @@
#define SERVER_PORT (50000) // TCP server socket port number
#define SUBNET_MASK ("255.255.255.0") // Subnet mask
#define DEFAULT_GATEWAY ("192.168.1.1") // Default gateway
-#define CONNECT_TIMEOUT (3*60*1000) // Connect-Timeout in ms
#define SEND_MESSAGE ("Hello, world!\r\n") // Send-message
static void _wlan_inf_callback(uint8_t ucType, uint16_t usWid, uint16_t usSize, uint8_t *pucData);
-static int _wlan_connect(void);
DigitalOut red_led(LED1); // On: error
DigitalOut green_led(LED2); // On: WLAN has been connected
@@ -33,47 +24,23 @@
*
*/
int main() {
- EthernetInterface eth;
+ GR_PEACH_WlanBP3595 wlan;
TCPSocketServer server;
TCPSocketConnection connection;
- uint32_t status;
int ret;
- /* Initialize WlanBP3595 */
- ret = WlanBP3595_Init(_wlan_inf_callback);
+ wlan.setWlanCbFunction(_wlan_inf_callback);
+
+ /* Initialize GR_PEACH_WlanBP3595 */
+ ret = wlan.init(SERVER_IP, SUBNET_MASK, DEFAULT_GATEWAY);
if (ret != 0) {
/* error */
red_led = 1;
while (1) { Thread::wait(1000); }
}
- /* Wait until WLAN_BP3595_START */
- while (1) {
- Thread::wait(200);
- status = WlanBP3595_GetWlanSts();
- if (status == WLAN_BP3595_START) {
- break;
- }
- }
-
- /* Initialize EthernetInterface */
- ret = eth.init(SERVER_IP, SUBNET_MASK, DEFAULT_GATEWAY);
- if (ret != 0) {
- /* error */
- red_led = 1;
- while (1) { Thread::wait(1000); }
- }
-
- /* Connect(WLAN) */
- ret = _wlan_connect();
- if (ret != 0) {
- /* error */
- red_led = 1;
- while (1) { Thread::wait(1000); }
- }
-
- /* Connect(EthernetInterface) */
- ret = eth.connect(CONNECT_TIMEOUT);
+ /* Connect(GR_PEACH_WlanBP3595) */
+ ret = wlan.connect(WLAN_SSID, WLAN_PSK);
if (ret != 0) {
/* error */
red_led = 1;
@@ -103,70 +70,16 @@
*/
static void _wlan_inf_callback(uint8_t ucType, uint16_t usWid, uint16_t usSize, uint8_t *pucData)
{
- if (ucType == 'I')
- {
- if (usWid == 0x0005) // WID_STATUS
- {
- if (pucData[0] == 0x01) // CONNECTED
- {
+ if (ucType == 'I') {
+ if (usWid == 0x0005) { // WID_STATUS
+ if (pucData[0] == 0x01) { // CONNECTED
/* Notify the EthernetInterface driver that WLAN has been connected */
- WlanBP3595_Connected();
green_led = 1;
- }
- else
- {
+ } else {
/* Notify the EthernetInterface driver that WLAN has been disconnected */
- WlanBP3595_Disconnected();
green_led = 0;
}
}
}
}
-/** WLAN connecting function
- *
- */
-static int _wlan_connect(void)
-{
- grp_u8 ucWidData8; // 8bit wid data
- grp_wld_byte_array tBAWidData; // byte array wid data
- int ret;
-
- /* Set BSS type */
- ucWidData8 = 0x02; // AP(Access Point)
- ret = WlanBP3595_Ioctl(GRP_WLD_IOCTL_SET_BSS_TYPE, &ucWidData8);
- if (ret != 0) {
- /* error */
- return -1;
- }
-
- /* Set SSID */
- tBAWidData.pucData = (grp_u8 *)WLAN_SSID;
- tBAWidData.ulSize = strlen((char *)tBAWidData.pucData);
- ret = WlanBP3595_Ioctl(GRP_WLD_IOCTL_SET_SSID, &tBAWidData);
- if (ret != 0) {
- /* error */
- return -1;
- }
-
- /* Set 11i mode */
- ucWidData8 = 0x01 | // Encryption is enable
- 0x10 | // WPA2 is enable
- 0x20; // CCMP(AES) is enable
- ret = WlanBP3595_Ioctl(GRP_WLD_IOCTL_SET_11I_MODE, &ucWidData8);
- if (ret != 0) {
- /* error */
- return -1;
- }
-
- /* Set PSK */
- tBAWidData.pucData = (grp_u8 *)WLAN_PSK;
- tBAWidData.ulSize = strlen((char *)tBAWidData.pucData);
- ret = WlanBP3595_Ioctl(GRP_WLD_IOCTL_SET_11I_PSK, &tBAWidData);
- if (ret != 0) {
- /* error */
- return -1;
- }
-
- return 0;
-}
--- a/mbed-rtos.lib Fri Dec 25 08:28:10 2015 +0000 +++ b/mbed-rtos.lib Tue May 31 07:20:18 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#143955ffb790 +http://mbed.org/users/mbed_official/code/mbed-rtos/#11950e007d8a
--- a/mbed.bld Fri Dec 25 08:28:10 2015 +0000 +++ b/mbed.bld Tue May 31 07:20:18 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/4336505e4b1c \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/7c328cabac7e \ No newline at end of file
