Small demo to purely test UDP, depends on the module already being configured to auto connect to an access point
Dependencies: USBDevice cc3000_hostdriver_mbedsocket mbed
Fork of WifiDipCortex-UDPDemo by
Wifi-DipCortex - Test application that shows you how to listen for UDP message on one port while sending messages on another
- Listens on UDP_LISTEN_PORT, upon data being recvied it can be found in UDP_RecvBuffer - Transmits UDP_TX_Buffer on UDP_TARGET_PORT to UDP_TARGET_IP
Revision 0:ff40ad3448c5, committed 2014-07-08
- Comitter:
- SolderSplashLabs
- Date:
- Tue Jul 08 18:56:37 2014 +0000
- Child:
- 1:5fa4efb214e7
- Commit message:
- WifiDipCortex - UDP Test
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBDevice.lib Tue Jul 08 18:56:37 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/SolderSplashLabs/code/USBDevice/#722133315bbb
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/cc3000_hostdriver_mbedsocket.lib Tue Jul 08 18:56:37 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/SolderSplashLabs/code/cc3000_hostdriver_mbedsocket/#ca8c234997c0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Jul 08 18:56:37 2014 +0000 @@ -0,0 +1,130 @@ +#include "mbed.h" +#include "cc3000.h" +#include "wifi.h" +#include "UDPSocket.h" +#include "USBSerial.h" + +using namespace mbed_cc3000; + +#define SERIAL_BAUD_RATE 115200 + +cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37)); +Serial uart(p19, p20); + +// USB CDC serial port +USBSerial pc; + +// ------------------------------------------------------------------------------------------------------------ +/*! + @brief WaitForConnection +*/ +// ------------------------------------------------------------------------------------------------------------ +void WaitForConnection ( void ) +{ +tNetappIpconfigRetArgs ipinfo; + + while (! ( wifi.is_dhcp_configured() ) ) + { + // Still not connected + pc.printf("No Connection\r\n"); + wait(1); + } + + if (( wifi.is_enabled() ) && ( wifi.is_dhcp_configured() )) + { + wifi.get_ip_config(&ipinfo); + } + + pc.printf("Connected to (%s) %s \r\n", ipinfo.uaSSID, wifi.getIPAddress()); + +} + +// ------------------------------------------------------------------------------------------------------------ +/*! + @brief WaitForUser +*/ +// ------------------------------------------------------------------------------------------------------------ +void WaitForUser ( void ) +{ +char charIn; + + pc.printf("Press Enter to Continue\r\n"); + + while (1) + { + charIn = pc.getc(); + + pc.printf("%c", charIn); + if ((charIn == '\n') || (charIn == '\r')) + { + break; + } + } +} + + +const char* UDP_TARGET_IP = "192.168.0.10"; +const int UDP_TARGET_PORT = 1500; + +// ------------------------------------------------------------------------------------------------------------ +/*! + @brief UdpTx +*/ +// ------------------------------------------------------------------------------------------------------------ +void UdpTx ( void ) +{ +char message[] = "Hello World\n"; +UDPSocket udpSocket; +Endpoint target; + + udpSocket.init(); + target.set_address(UDP_TARGET_IP, UDP_TARGET_PORT); + + pc.printf("Sending UDP Message ..\r\n"); + udpSocket.sendTo(target, message, sizeof(message)); + pc.printf("UDP Message Sent..\r\n"); +} + +// ------------------------------------------------------------------------------------------------------------ +/*! + @brief Init +*/ +// ------------------------------------------------------------------------------------------------------------ +void init() +{ + NVIC_SetPriority(SSP1_IRQn, 0x0); + NVIC_SetPriority(PIN_INT0_IRQn, 0x1); + + // SysTick set to lower priority than Wi-Fi SPI bus interrupt + NVIC_SetPriority(SysTick_IRQn, 0x2); + + // Enable RAM1 + LPC_SYSCON->SYSAHBCLKCTRL |= (0x1 << 26); + + uart.baud(SERIAL_BAUD_RATE); + + wait(1); +} + +// ------------------------------------------------------------------------------------------------------------ +/*! + @brief main loop +*/ +// ------------------------------------------------------------------------------------------------------------ +int main( void ) +{ + // Initalise the WiFi Module + init(); + + WaitForUser(); + + wifi.start(0); + + WaitForConnection(); + + while (1) + { + WaitForUser(); + UdpTx(); + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Jul 08 18:56:37 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/04dd9b1680ae \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wifi.h Tue Jul 08 18:56:37 2014 +0000 @@ -0,0 +1,44 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef WIFI_H +#define WIFI_H + +#include "cc3000.h" + +#define WIGO 1 +#define WIFI_DIPCORTEX 2 +#define UNDEFINED 3 + +#define MY_BOARD WIFI_DIPCORTEX + +// use this defines in AP_SECURITY +#define NONE 0 +#define WEP 1 +#define WPA 2 +#define WPA2 3 + +// use smart config +#define USE_SMART_CONFIG 0 + + // Default SSID Settings +#define SSID "soldersplash" +#define AP_KEY "wifidipcortex" +#define AP_SECURITY WPA2 + +void init(); + + +#endif