Wifi Pressure Sensor
Dependencies: HTTPClient MPL3115A2 NTPClient TMP102 USBDevice cc3000_hostdriver_mbedsocket mbed
main.cpp@7:3d9d776dc20b, 2014-01-08 (annotated)
- Committer:
- markirwin
- Date:
- Wed Jan 08 05:17:13 2014 +0000
- Revision:
- 7:3d9d776dc20b
- Parent:
- 6:65fb503512ad
- Child:
- 11:8a3bc0e3255d
Post Temp to Xively
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
SolderSplashLabs | 0:0bce3a738bcb | 1 | |
SolderSplashLabs | 0:0bce3a738bcb | 2 | #include "mbed.h" |
SolderSplashLabs | 0:0bce3a738bcb | 3 | #include "cc3000.h" |
SolderSplashLabs | 0:0bce3a738bcb | 4 | #include "wifi.h" |
SolderSplashLabs | 0:0bce3a738bcb | 5 | #include "UDPSocket.h" |
SolderSplashLabs | 0:0bce3a738bcb | 6 | #include "tcpTests.h" |
SolderSplashLabs | 0:0bce3a738bcb | 7 | #include "main.h" |
SolderSplashLabs | 0:0bce3a738bcb | 8 | #include "USBSerial.h" |
SolderSplashLabs | 0:0bce3a738bcb | 9 | #include "NTPClient.h" |
SolderSplashLabs | 0:0bce3a738bcb | 10 | #include <time.h> |
SolderSplashLabs | 0:0bce3a738bcb | 11 | |
SolderSplashLabs | 0:0bce3a738bcb | 12 | using namespace mbed_cc3000; |
SolderSplashLabs | 0:0bce3a738bcb | 13 | |
SolderSplashLabs | 0:0bce3a738bcb | 14 | /* cc3000 module declaration specific for user's board. Check also init() */ |
SolderSplashLabs | 0:0bce3a738bcb | 15 | #if (MY_BOARD == WIGO) |
SolderSplashLabs | 0:0bce3a738bcb | 16 | cc3000 wifi(PTA16, PTA13, PTD0, SPI(PTD2, PTD3, PTC5), PORTA_IRQn); |
SolderSplashLabs | 0:0bce3a738bcb | 17 | #elif (MY_BOARD == WIFI_DIPCORTEX) |
SolderSplashLabs | 2:8f5776c287c5 | 18 | cc3000 wifi(p28, p27, p30, SPI(p21, p14, p37)); |
SolderSplashLabs | 0:0bce3a738bcb | 19 | Serial uart(p19, p20); |
SolderSplashLabs | 0:0bce3a738bcb | 20 | USBSerial pc; // USB CDC serial port |
SolderSplashLabs | 0:0bce3a738bcb | 21 | #else |
SolderSplashLabs | 0:0bce3a738bcb | 22 | |
SolderSplashLabs | 0:0bce3a738bcb | 23 | #endif |
SolderSplashLabs | 0:0bce3a738bcb | 24 | |
SolderSplashLabs | 0:0bce3a738bcb | 25 | #ifndef CC3000_UNENCRYPTED_SMART_CONFIG |
SolderSplashLabs | 0:0bce3a738bcb | 26 | const uint8_t smartconfigkey[] = {0x73,0x6d,0x61,0x72,0x74,0x63,0x6f,0x6e,0x66,0x69,0x67,0x41,0x45,0x53,0x31,0x36}; |
SolderSplashLabs | 0:0bce3a738bcb | 27 | #else |
SolderSplashLabs | 0:0bce3a738bcb | 28 | const uint8_t smartconfigkey = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 29 | #endif |
SolderSplashLabs | 0:0bce3a738bcb | 30 | |
SolderSplashLabs | 0:0bce3a738bcb | 31 | const int ECHO_SERVER_PORT_UDP = 81; |
SolderSplashLabs | 0:0bce3a738bcb | 32 | uint8_t *HostToPing = (uint8_t *)"google.com"; |
SolderSplashLabs | 0:0bce3a738bcb | 33 | tNetappIpconfigRetArgs ipinfo; |
SolderSplashLabs | 0:0bce3a738bcb | 34 | extern char tmpBuffer[512]; |
SolderSplashLabs | 0:0bce3a738bcb | 35 | |
SolderSplashLabs | 0:0bce3a738bcb | 36 | MENU_LEVEL currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 37 | |
SolderSplashLabs | 0:0bce3a738bcb | 38 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 39 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 40 | @brief Resolve a hostname and ping it |
SolderSplashLabs | 0:0bce3a738bcb | 41 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 42 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 43 | void PingTest ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 44 | { |
SolderSplashLabs | 0:0bce3a738bcb | 45 | uint32_t ip; |
SolderSplashLabs | 0:0bce3a738bcb | 46 | int32_t resolveRetCode = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 47 | |
SolderSplashLabs | 0:0bce3a738bcb | 48 | pc.printf("Get an IP address for %s\r\n",HostToPing); |
SolderSplashLabs | 0:0bce3a738bcb | 49 | resolveRetCode = wifi._socket.gethostbyname(HostToPing,strlen((const char *)HostToPing), &ip); |
SolderSplashLabs | 0:0bce3a738bcb | 50 | pc.printf("gethostbyname Returned code : %i \r\n", resolveRetCode); |
SolderSplashLabs | 0:0bce3a738bcb | 51 | |
SolderSplashLabs | 0:0bce3a738bcb | 52 | if (resolveRetCode > -1) |
SolderSplashLabs | 0:0bce3a738bcb | 53 | { |
SolderSplashLabs | 0:0bce3a738bcb | 54 | uint8_t add0 = (ip >> 24); |
SolderSplashLabs | 0:0bce3a738bcb | 55 | uint8_t add1 = (ip >> 16); |
SolderSplashLabs | 0:0bce3a738bcb | 56 | uint8_t add2 = (ip >> 8); |
SolderSplashLabs | 0:0bce3a738bcb | 57 | uint8_t add3 = (ip >> 0); |
SolderSplashLabs | 0:0bce3a738bcb | 58 | pc.printf("IP address of %s: %d.%d.%d.%d \r\n", HostToPing, add0, add1, add2, add3); |
SolderSplashLabs | 0:0bce3a738bcb | 59 | |
SolderSplashLabs | 0:0bce3a738bcb | 60 | pc.printf("Sending ping\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 61 | uint32_t reply_count = wifi.ping(ip, 5, 500, 32); |
SolderSplashLabs | 0:0bce3a738bcb | 62 | pc.printf("Received %d replies\r\n", reply_count); |
SolderSplashLabs | 0:0bce3a738bcb | 63 | pc.printf("Ping complete.\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 64 | } |
SolderSplashLabs | 0:0bce3a738bcb | 65 | else |
SolderSplashLabs | 0:0bce3a738bcb | 66 | { |
SolderSplashLabs | 0:0bce3a738bcb | 67 | pc.printf("Failed to resolve\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 68 | } |
SolderSplashLabs | 0:0bce3a738bcb | 69 | } |
SolderSplashLabs | 0:0bce3a738bcb | 70 | |
SolderSplashLabs | 0:0bce3a738bcb | 71 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 72 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 73 | @brief Test the NTP library |
SolderSplashLabs | 0:0bce3a738bcb | 74 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 75 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 76 | void NtpTest ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 77 | { |
SolderSplashLabs | 0:0bce3a738bcb | 78 | NTPClient ntp; |
SolderSplashLabs | 0:0bce3a738bcb | 79 | struct tm *currentTime; |
SolderSplashLabs | 0:0bce3a738bcb | 80 | if (ntp.setTime("0.pool.ntp.org",123,10000) == 0) |
SolderSplashLabs | 0:0bce3a738bcb | 81 | { |
SolderSplashLabs | 0:0bce3a738bcb | 82 | pc.printf("\r\nGot the time successfully\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 83 | currentTime = localtime(&ntp.NTPLastResult); |
SolderSplashLabs | 0:0bce3a738bcb | 84 | pc.printf("NTP Response : %s\r\n", asctime(currentTime)); |
SolderSplashLabs | 0:0bce3a738bcb | 85 | } |
SolderSplashLabs | 0:0bce3a738bcb | 86 | else |
SolderSplashLabs | 0:0bce3a738bcb | 87 | { |
SolderSplashLabs | 0:0bce3a738bcb | 88 | pc.printf("NTP Update Failed\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 89 | } |
SolderSplashLabs | 0:0bce3a738bcb | 90 | } |
SolderSplashLabs | 0:0bce3a738bcb | 91 | |
SolderSplashLabs | 0:0bce3a738bcb | 92 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 93 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 94 | @brief Send a UDP Packet, wait for response |
SolderSplashLabs | 0:0bce3a738bcb | 95 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 96 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 97 | void UdpClientTest ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 98 | { |
SolderSplashLabs | 0:0bce3a738bcb | 99 | UDPSocket socket; |
SolderSplashLabs | 0:0bce3a738bcb | 100 | int n = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 101 | Endpoint outEndpoint; |
SolderSplashLabs | 0:0bce3a738bcb | 102 | Endpoint inEndpoint; |
SolderSplashLabs | 0:0bce3a738bcb | 103 | |
SolderSplashLabs | 0:0bce3a738bcb | 104 | if (0 == socket.bind(ECHO_SERVER_PORT_UDP) ) |
SolderSplashLabs | 0:0bce3a738bcb | 105 | { |
SolderSplashLabs | 0:0bce3a738bcb | 106 | |
SolderSplashLabs | 0:0bce3a738bcb | 107 | // 2 second timeout |
SolderSplashLabs | 0:0bce3a738bcb | 108 | socket.set_blocking(false, 2000); |
SolderSplashLabs | 0:0bce3a738bcb | 109 | |
SolderSplashLabs | 0:0bce3a738bcb | 110 | pc.printf("\r\n!! Press any key to stop !!\r\n\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 111 | |
SolderSplashLabs | 0:0bce3a738bcb | 112 | while (1) |
SolderSplashLabs | 0:0bce3a738bcb | 113 | { |
SolderSplashLabs | 0:0bce3a738bcb | 114 | if( outEndpoint.set_address(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT_UDP) < 0 ) |
SolderSplashLabs | 0:0bce3a738bcb | 115 | { |
SolderSplashLabs | 0:0bce3a738bcb | 116 | pc.printf("Failed to set endpoint address.\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 117 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 118 | } |
SolderSplashLabs | 0:0bce3a738bcb | 119 | else |
SolderSplashLabs | 0:0bce3a738bcb | 120 | { |
SolderSplashLabs | 0:0bce3a738bcb | 121 | if ( socket.sendTo( outEndpoint, hello, sizeof(hello) ) < 0 ) |
SolderSplashLabs | 0:0bce3a738bcb | 122 | { |
SolderSplashLabs | 0:0bce3a738bcb | 123 | pc.printf("Failed to send the packet.\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 124 | } |
SolderSplashLabs | 0:0bce3a738bcb | 125 | else |
SolderSplashLabs | 0:0bce3a738bcb | 126 | { |
SolderSplashLabs | 0:0bce3a738bcb | 127 | // Message sent, recv reply |
SolderSplashLabs | 0:0bce3a738bcb | 128 | pc.printf("UDP Socket Sent : %s \r\n", hello); |
SolderSplashLabs | 0:0bce3a738bcb | 129 | n = socket.receiveFrom( inEndpoint, tmpBuffer, sizeof(tmpBuffer) ); |
SolderSplashLabs | 0:0bce3a738bcb | 130 | if ( n < 0 ) |
SolderSplashLabs | 0:0bce3a738bcb | 131 | { |
SolderSplashLabs | 0:0bce3a738bcb | 132 | pc.printf("Failed to recv the UDP packet.\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 133 | } |
SolderSplashLabs | 0:0bce3a738bcb | 134 | else |
SolderSplashLabs | 0:0bce3a738bcb | 135 | { |
SolderSplashLabs | 0:0bce3a738bcb | 136 | tmpBuffer[n] = '\0'; |
SolderSplashLabs | 0:0bce3a738bcb | 137 | pc.printf("UDP Socket Recv'd : %s \r\n", tmpBuffer); |
SolderSplashLabs | 0:0bce3a738bcb | 138 | } |
SolderSplashLabs | 0:0bce3a738bcb | 139 | } |
SolderSplashLabs | 0:0bce3a738bcb | 140 | } |
SolderSplashLabs | 0:0bce3a738bcb | 141 | |
SolderSplashLabs | 0:0bce3a738bcb | 142 | // Should we stop? |
SolderSplashLabs | 0:0bce3a738bcb | 143 | if ( pc.readable() ) |
SolderSplashLabs | 0:0bce3a738bcb | 144 | { |
SolderSplashLabs | 0:0bce3a738bcb | 145 | pc.getc(); |
SolderSplashLabs | 0:0bce3a738bcb | 146 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 147 | } |
SolderSplashLabs | 0:0bce3a738bcb | 148 | } |
SolderSplashLabs | 0:0bce3a738bcb | 149 | |
SolderSplashLabs | 0:0bce3a738bcb | 150 | if ( wifi.is_connected() ) |
SolderSplashLabs | 0:0bce3a738bcb | 151 | { |
SolderSplashLabs | 0:0bce3a738bcb | 152 | socket.close(); |
SolderSplashLabs | 0:0bce3a738bcb | 153 | } |
SolderSplashLabs | 0:0bce3a738bcb | 154 | } |
SolderSplashLabs | 0:0bce3a738bcb | 155 | else |
SolderSplashLabs | 0:0bce3a738bcb | 156 | { |
SolderSplashLabs | 0:0bce3a738bcb | 157 | // Failed to bind to the socket |
SolderSplashLabs | 0:0bce3a738bcb | 158 | } |
SolderSplashLabs | 0:0bce3a738bcb | 159 | } |
SolderSplashLabs | 0:0bce3a738bcb | 160 | |
SolderSplashLabs | 0:0bce3a738bcb | 161 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 162 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 163 | @brief Listen on a UDP port for messages |
SolderSplashLabs | 0:0bce3a738bcb | 164 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 165 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 166 | void UdpServerTest ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 167 | { |
SolderSplashLabs | 0:0bce3a738bcb | 168 | UDPSocket socket; |
SolderSplashLabs | 0:0bce3a738bcb | 169 | Endpoint client; |
SolderSplashLabs | 0:0bce3a738bcb | 170 | int n = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 171 | |
SolderSplashLabs | 0:0bce3a738bcb | 172 | if (0 == socket.bind(ECHO_SERVER_PORT_UDP) ) |
SolderSplashLabs | 0:0bce3a738bcb | 173 | { |
SolderSplashLabs | 0:0bce3a738bcb | 174 | pc.printf("\r\n!! Press any key to stop listening !!\r\n\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 175 | |
SolderSplashLabs | 0:0bce3a738bcb | 176 | while (true) |
SolderSplashLabs | 0:0bce3a738bcb | 177 | { |
SolderSplashLabs | 0:0bce3a738bcb | 178 | pc.printf("Waiting for packet...\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 179 | n = socket.receiveFrom(client, tmpBuffer, sizeof(tmpBuffer)); |
SolderSplashLabs | 0:0bce3a738bcb | 180 | |
SolderSplashLabs | 0:0bce3a738bcb | 181 | pc.printf("Received packet from: %s\n", client.get_address()); |
SolderSplashLabs | 0:0bce3a738bcb | 182 | socket.sendTo(client, tmpBuffer, n); |
SolderSplashLabs | 0:0bce3a738bcb | 183 | |
SolderSplashLabs | 0:0bce3a738bcb | 184 | // Should we stop? |
SolderSplashLabs | 0:0bce3a738bcb | 185 | if ( pc.readable() ) |
SolderSplashLabs | 0:0bce3a738bcb | 186 | { |
SolderSplashLabs | 0:0bce3a738bcb | 187 | pc.getc(); |
SolderSplashLabs | 0:0bce3a738bcb | 188 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 189 | } |
SolderSplashLabs | 0:0bce3a738bcb | 190 | } |
SolderSplashLabs | 0:0bce3a738bcb | 191 | } |
SolderSplashLabs | 0:0bce3a738bcb | 192 | } |
SolderSplashLabs | 0:0bce3a738bcb | 193 | |
SolderSplashLabs | 0:0bce3a738bcb | 194 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 195 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 196 | @brief Print menu header |
SolderSplashLabs | 0:0bce3a738bcb | 197 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 198 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 199 | void Menu_PrintHeader ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 200 | { |
SolderSplashLabs | 0:0bce3a738bcb | 201 | if (( wifi.is_enabled() ) && ( wifi.is_dhcp_configured() )) |
SolderSplashLabs | 0:0bce3a738bcb | 202 | { |
SolderSplashLabs | 0:0bce3a738bcb | 203 | wifi.get_ip_config(&ipinfo); |
SolderSplashLabs | 0:0bce3a738bcb | 204 | } |
SolderSplashLabs | 0:0bce3a738bcb | 205 | |
SolderSplashLabs | 0:0bce3a738bcb | 206 | pc.printf("\r\n"); |
markirwin | 6:65fb503512ad | 207 | pc.printf("+---------IRWIN1----------------------------+\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 208 | pc.printf("| WiFi DipCortex / CC3000 Kitchen Sink |\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 209 | pc.printf("+-------------------------------------------+\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 210 | if (! wifi.is_enabled() ) |
SolderSplashLabs | 0:0bce3a738bcb | 211 | { |
SolderSplashLabs | 0:0bce3a738bcb | 212 | pc.printf("| CC3000 Disabled |\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 213 | } |
SolderSplashLabs | 0:0bce3a738bcb | 214 | else if ( wifi.is_dhcp_configured() ) |
SolderSplashLabs | 0:0bce3a738bcb | 215 | { |
SolderSplashLabs | 0:0bce3a738bcb | 216 | pc.printf("| SSID : %-33s|\r\n", ipinfo.uaSSID); |
SolderSplashLabs | 0:0bce3a738bcb | 217 | pc.printf("| IP : %-35s|\r\n", wifi.getIPAddress()); |
SolderSplashLabs | 0:0bce3a738bcb | 218 | } |
SolderSplashLabs | 0:0bce3a738bcb | 219 | else if ( wifi.is_connected() ) |
SolderSplashLabs | 0:0bce3a738bcb | 220 | { |
SolderSplashLabs | 0:0bce3a738bcb | 221 | pc.printf("| Connecting, waiting for DHCP |\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 222 | } |
SolderSplashLabs | 0:0bce3a738bcb | 223 | else |
SolderSplashLabs | 0:0bce3a738bcb | 224 | { |
SolderSplashLabs | 0:0bce3a738bcb | 225 | pc.printf("| Not Connected |\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 226 | } |
SolderSplashLabs | 0:0bce3a738bcb | 227 | pc.printf("+-------------------------------------------+\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 228 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 229 | } |
SolderSplashLabs | 0:0bce3a738bcb | 230 | |
SolderSplashLabs | 0:0bce3a738bcb | 231 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 232 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 233 | @brief Control the wifi connection |
SolderSplashLabs | 0:0bce3a738bcb | 234 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 235 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 236 | char WaitForSerialCommand ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 237 | { |
SolderSplashLabs | 0:0bce3a738bcb | 238 | char charIn = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 239 | char prevCharIn; |
SolderSplashLabs | 0:0bce3a738bcb | 240 | |
SolderSplashLabs | 0:0bce3a738bcb | 241 | pc.printf("Enter command character : "); |
SolderSplashLabs | 0:0bce3a738bcb | 242 | |
SolderSplashLabs | 0:0bce3a738bcb | 243 | while (1) |
SolderSplashLabs | 0:0bce3a738bcb | 244 | { |
SolderSplashLabs | 0:0bce3a738bcb | 245 | prevCharIn = charIn; |
SolderSplashLabs | 0:0bce3a738bcb | 246 | charIn = pc.getc(); |
SolderSplashLabs | 0:0bce3a738bcb | 247 | |
SolderSplashLabs | 0:0bce3a738bcb | 248 | pc.printf("%c", charIn); |
SolderSplashLabs | 0:0bce3a738bcb | 249 | if ((charIn == '\n') || (charIn == '\r')) |
SolderSplashLabs | 0:0bce3a738bcb | 250 | { |
SolderSplashLabs | 0:0bce3a738bcb | 251 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 252 | } |
SolderSplashLabs | 0:0bce3a738bcb | 253 | } |
SolderSplashLabs | 0:0bce3a738bcb | 254 | |
SolderSplashLabs | 0:0bce3a738bcb | 255 | return ( prevCharIn ); |
SolderSplashLabs | 0:0bce3a738bcb | 256 | } |
SolderSplashLabs | 0:0bce3a738bcb | 257 | |
SolderSplashLabs | 0:0bce3a738bcb | 258 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 259 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 260 | @brief Configure the module for smart connect mode allow configuration over the air |
SolderSplashLabs | 0:0bce3a738bcb | 261 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 262 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 263 | void SmartConfig ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 264 | { |
SolderSplashLabs | 2:8f5776c287c5 | 265 | pc.printf("\r\nStarting Smart config, waiting for message from smartphone app ....\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 266 | // We dont want to auto reconnect to an access point |
SolderSplashLabs | 0:0bce3a738bcb | 267 | wifi._wlan.ioctl_set_connection_policy(0, 0, 0); |
SolderSplashLabs | 0:0bce3a738bcb | 268 | |
SolderSplashLabs | 0:0bce3a738bcb | 269 | // start smart config will disconnect, set the prefix |
SolderSplashLabs | 0:0bce3a738bcb | 270 | // wait for a message via a SmartConfig app, store it to the profile list |
SolderSplashLabs | 0:0bce3a738bcb | 271 | // finally it will reenable auto connection, triggering the module to connect to the new access point |
SolderSplashLabs | 0:0bce3a738bcb | 272 | wifi.start_smart_config(0); |
SolderSplashLabs | 0:0bce3a738bcb | 273 | } |
SolderSplashLabs | 0:0bce3a738bcb | 274 | |
SolderSplashLabs | 0:0bce3a738bcb | 275 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 276 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 277 | @brief Print cc3000 information |
SolderSplashLabs | 0:0bce3a738bcb | 278 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 279 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 280 | void print_cc3000_info() { |
SolderSplashLabs | 0:0bce3a738bcb | 281 | uint8_t myMAC[8]; |
SolderSplashLabs | 0:0bce3a738bcb | 282 | uint8_t buffer[2]; |
SolderSplashLabs | 0:0bce3a738bcb | 283 | int32_t status = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 284 | tNetappIpconfigRetArgs ipinfo2; |
SolderSplashLabs | 0:0bce3a738bcb | 285 | tUserFS cc_user_info; |
SolderSplashLabs | 0:0bce3a738bcb | 286 | const char * WIFI_STATUS[] = {"Disconnected", "Scanning", "Connecting", "Connected"}; |
SolderSplashLabs | 0:0bce3a738bcb | 287 | |
SolderSplashLabs | 0:0bce3a738bcb | 288 | wifi.get_user_file_info((uint8_t *)&cc_user_info, sizeof(cc_user_info)); |
SolderSplashLabs | 0:0bce3a738bcb | 289 | wifi.get_mac_address(myMAC); |
SolderSplashLabs | 0:0bce3a738bcb | 290 | pc.printf(" MAC address : %02x:%02x:%02x:%02x:%02x:%02x\r\n", myMAC[0], myMAC[1], myMAC[2], myMAC[3], myMAC[4], myMAC[5]); |
SolderSplashLabs | 0:0bce3a738bcb | 291 | |
SolderSplashLabs | 0:0bce3a738bcb | 292 | if (! wifi._nvmem.read_sp_version( (unsigned char*)&buffer ) ) |
SolderSplashLabs | 0:0bce3a738bcb | 293 | { |
SolderSplashLabs | 0:0bce3a738bcb | 294 | pc.printf(" CC3000 Firmware Version : %u.%u \r\n", buffer[0], buffer[1]); |
SolderSplashLabs | 0:0bce3a738bcb | 295 | } |
SolderSplashLabs | 0:0bce3a738bcb | 296 | else |
SolderSplashLabs | 0:0bce3a738bcb | 297 | { |
SolderSplashLabs | 0:0bce3a738bcb | 298 | pc.printf(" CC3000 Read nvmem failed!"); |
SolderSplashLabs | 0:0bce3a738bcb | 299 | } |
SolderSplashLabs | 0:0bce3a738bcb | 300 | |
SolderSplashLabs | 0:0bce3a738bcb | 301 | status = wifi._wlan.ioctl_statusget(); |
SolderSplashLabs | 0:0bce3a738bcb | 302 | if (( status > -1 ) && ( status < 4 )) |
SolderSplashLabs | 0:0bce3a738bcb | 303 | { |
SolderSplashLabs | 0:0bce3a738bcb | 304 | pc.printf(" Wifi Status : %s\r\n", WIFI_STATUS[status]); |
SolderSplashLabs | 0:0bce3a738bcb | 305 | } |
SolderSplashLabs | 0:0bce3a738bcb | 306 | else |
SolderSplashLabs | 0:0bce3a738bcb | 307 | { |
SolderSplashLabs | 0:0bce3a738bcb | 308 | pc.printf(" Wifi Status : %d\r\n", status); |
SolderSplashLabs | 0:0bce3a738bcb | 309 | } |
SolderSplashLabs | 0:0bce3a738bcb | 310 | |
SolderSplashLabs | 0:0bce3a738bcb | 311 | if ( wifi.is_dhcp_configured() ) |
SolderSplashLabs | 0:0bce3a738bcb | 312 | { |
SolderSplashLabs | 0:0bce3a738bcb | 313 | wifi.get_ip_config(&ipinfo2); |
SolderSplashLabs | 0:0bce3a738bcb | 314 | pc.printf(" Connected to : %s \r\n", ipinfo2.uaSSID); |
SolderSplashLabs | 0:0bce3a738bcb | 315 | pc.printf(" IP : %d.%d.%d.%d \r\n", ipinfo2.aucIP[3], ipinfo2.aucIP[2], ipinfo2.aucIP[1], ipinfo2.aucIP[0]); |
SolderSplashLabs | 0:0bce3a738bcb | 316 | pc.printf(" Gateway : %d.%d.%d.%d \r\n", ipinfo2.aucDefaultGateway[3], ipinfo2.aucDefaultGateway[2], ipinfo2.aucDefaultGateway[1], ipinfo2.aucDefaultGateway[0]); |
SolderSplashLabs | 0:0bce3a738bcb | 317 | pc.printf(" Subnet : %d.%d.%d.%d \r\n", ipinfo2.aucSubnetMask[3], ipinfo2.aucSubnetMask[2], ipinfo2.aucSubnetMask[1], ipinfo2.aucSubnetMask[0]); |
SolderSplashLabs | 0:0bce3a738bcb | 318 | pc.printf(" DNS : %d.%d.%d.%d \r\n", ipinfo2.aucDNSServer[3], ipinfo2.aucDNSServer[2], ipinfo2.aucDNSServer[1], ipinfo2.aucDNSServer[0]); |
SolderSplashLabs | 0:0bce3a738bcb | 319 | |
SolderSplashLabs | 0:0bce3a738bcb | 320 | pc.printf(" Cached IP : %s \r\n", wifi.getIPAddress()); |
SolderSplashLabs | 0:0bce3a738bcb | 321 | pc.printf(" Cached Gateway : %s \r\n", wifi.getGateway()); |
SolderSplashLabs | 0:0bce3a738bcb | 322 | pc.printf(" Cached Subnet : %s \r\n", wifi.getNetworkMask()); |
SolderSplashLabs | 0:0bce3a738bcb | 323 | |
SolderSplashLabs | 0:0bce3a738bcb | 324 | } |
SolderSplashLabs | 0:0bce3a738bcb | 325 | else |
SolderSplashLabs | 0:0bce3a738bcb | 326 | { |
SolderSplashLabs | 0:0bce3a738bcb | 327 | pc.printf(" Not connected \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 328 | } |
SolderSplashLabs | 0:0bce3a738bcb | 329 | } |
SolderSplashLabs | 0:0bce3a738bcb | 330 | |
SolderSplashLabs | 0:0bce3a738bcb | 331 | |
SolderSplashLabs | 0:0bce3a738bcb | 332 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 333 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 334 | @brief Control the wifi connection |
SolderSplashLabs | 0:0bce3a738bcb | 335 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 336 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 337 | void Menu_ConnectionControl ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 338 | { |
SolderSplashLabs | 0:0bce3a738bcb | 339 | uint32_t ip = 0; |
SolderSplashLabs | 0:0bce3a738bcb | 340 | Menu_PrintHeader(); |
SolderSplashLabs | 0:0bce3a738bcb | 341 | pc.printf(" 1 - Enable auto connect to any previous access point\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 342 | pc.printf(" 2 - Disable auto connect \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 343 | pc.printf(" 3 - Connect to %s \r\n", SSID); |
SolderSplashLabs | 0:0bce3a738bcb | 344 | pc.printf(" 4 - Disconnect \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 345 | pc.printf(" 5 - Start SmartConfig \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 346 | pc.printf(" 6 - Erase profiles \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 347 | pc.printf(" 7 - Get Status \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 348 | pc.printf(" x - Top Menu \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 349 | |
SolderSplashLabs | 0:0bce3a738bcb | 350 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 351 | |
SolderSplashLabs | 0:0bce3a738bcb | 352 | switch(WaitForSerialCommand()) |
SolderSplashLabs | 0:0bce3a738bcb | 353 | { |
SolderSplashLabs | 0:0bce3a738bcb | 354 | case '1': |
SolderSplashLabs | 0:0bce3a738bcb | 355 | wifi._wlan.ioctl_set_connection_policy(0, 0, 1); |
SolderSplashLabs | 0:0bce3a738bcb | 356 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 357 | |
SolderSplashLabs | 0:0bce3a738bcb | 358 | case '2': |
SolderSplashLabs | 0:0bce3a738bcb | 359 | wifi._wlan.ioctl_set_connection_policy(0, 0, 0); |
SolderSplashLabs | 0:0bce3a738bcb | 360 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 361 | |
SolderSplashLabs | 0:0bce3a738bcb | 362 | case '3': |
SolderSplashLabs | 0:0bce3a738bcb | 363 | |
SolderSplashLabs | 0:0bce3a738bcb | 364 | //wifi.start(0); |
SolderSplashLabs | 0:0bce3a738bcb | 365 | |
SolderSplashLabs | 0:0bce3a738bcb | 366 | // Enable DHCP |
SolderSplashLabs | 0:0bce3a738bcb | 367 | wifi._netapp.dhcp(&ip, &ip, &ip, &ip); |
SolderSplashLabs | 0:0bce3a738bcb | 368 | |
SolderSplashLabs | 0:0bce3a738bcb | 369 | if ( AP_SECURITY == NONE ) |
SolderSplashLabs | 0:0bce3a738bcb | 370 | { |
SolderSplashLabs | 0:0bce3a738bcb | 371 | wifi.connect_non_blocking((uint8_t *)SSID, 0, AP_SECURITY); |
SolderSplashLabs | 0:0bce3a738bcb | 372 | } |
SolderSplashLabs | 0:0bce3a738bcb | 373 | else |
SolderSplashLabs | 0:0bce3a738bcb | 374 | { |
SolderSplashLabs | 0:0bce3a738bcb | 375 | pc.printf("\r\n Connecting to : %s key : %s", SSID, AP_KEY ); |
SolderSplashLabs | 0:0bce3a738bcb | 376 | wifi.connect_non_blocking((uint8_t *)SSID, (uint8_t *)AP_KEY, AP_SECURITY); |
SolderSplashLabs | 0:0bce3a738bcb | 377 | |
SolderSplashLabs | 0:0bce3a738bcb | 378 | } |
SolderSplashLabs | 0:0bce3a738bcb | 379 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 380 | |
SolderSplashLabs | 0:0bce3a738bcb | 381 | case '4' : |
SolderSplashLabs | 0:0bce3a738bcb | 382 | // Stop the module re-connecting |
SolderSplashLabs | 0:0bce3a738bcb | 383 | wifi._wlan.ioctl_set_connection_policy(0, 0, 0); |
SolderSplashLabs | 0:0bce3a738bcb | 384 | // Then disconnect |
SolderSplashLabs | 0:0bce3a738bcb | 385 | wifi.disconnect(); |
SolderSplashLabs | 0:0bce3a738bcb | 386 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 387 | |
SolderSplashLabs | 0:0bce3a738bcb | 388 | case '5' : |
SolderSplashLabs | 0:0bce3a738bcb | 389 | SmartConfig(); |
SolderSplashLabs | 0:0bce3a738bcb | 390 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 391 | |
SolderSplashLabs | 0:0bce3a738bcb | 392 | case '6' : |
SolderSplashLabs | 0:0bce3a738bcb | 393 | wifi._wlan.ioctl_del_profile(255); |
SolderSplashLabs | 0:0bce3a738bcb | 394 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 395 | |
SolderSplashLabs | 0:0bce3a738bcb | 396 | case '7' : |
SolderSplashLabs | 0:0bce3a738bcb | 397 | print_cc3000_info(); |
SolderSplashLabs | 0:0bce3a738bcb | 398 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 399 | |
SolderSplashLabs | 0:0bce3a738bcb | 400 | case '8': |
SolderSplashLabs | 0:0bce3a738bcb | 401 | //wifi._spi.manualIrqCheck(); |
SolderSplashLabs | 0:0bce3a738bcb | 402 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 403 | |
SolderSplashLabs | 0:0bce3a738bcb | 404 | case 'x': |
SolderSplashLabs | 0:0bce3a738bcb | 405 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 406 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 407 | } |
SolderSplashLabs | 0:0bce3a738bcb | 408 | } |
SolderSplashLabs | 0:0bce3a738bcb | 409 | |
SolderSplashLabs | 0:0bce3a738bcb | 410 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 411 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 412 | @brief |
SolderSplashLabs | 0:0bce3a738bcb | 413 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 414 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 415 | void Menu_UdpControl ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 416 | { |
SolderSplashLabs | 0:0bce3a738bcb | 417 | Menu_PrintHeader(); |
SolderSplashLabs | 0:0bce3a738bcb | 418 | |
SolderSplashLabs | 0:0bce3a738bcb | 419 | pc.printf(" 1 - UDP Client, Connect to %s:%d\r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT_UDP); |
SolderSplashLabs | 0:0bce3a738bcb | 420 | pc.printf(" 2 - UDP Server \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 421 | pc.printf(" 3 - NTP Client \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 422 | pc.printf(" x - Exit to top menu \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 423 | |
SolderSplashLabs | 0:0bce3a738bcb | 424 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 425 | |
SolderSplashLabs | 0:0bce3a738bcb | 426 | switch(WaitForSerialCommand()) |
SolderSplashLabs | 0:0bce3a738bcb | 427 | { |
SolderSplashLabs | 0:0bce3a738bcb | 428 | case '1': |
SolderSplashLabs | 0:0bce3a738bcb | 429 | UdpClientTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 430 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 431 | case '2': |
SolderSplashLabs | 0:0bce3a738bcb | 432 | UdpServerTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 433 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 434 | case '3': |
SolderSplashLabs | 0:0bce3a738bcb | 435 | NtpTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 436 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 437 | case '0': |
SolderSplashLabs | 0:0bce3a738bcb | 438 | case 'x': |
SolderSplashLabs | 0:0bce3a738bcb | 439 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 440 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 441 | } |
SolderSplashLabs | 0:0bce3a738bcb | 442 | } |
SolderSplashLabs | 0:0bce3a738bcb | 443 | |
SolderSplashLabs | 0:0bce3a738bcb | 444 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 445 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 446 | @brief |
SolderSplashLabs | 0:0bce3a738bcb | 447 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 448 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 449 | void Menu_TcpControl ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 450 | { |
SolderSplashLabs | 0:0bce3a738bcb | 451 | Menu_PrintHeader(); |
SolderSplashLabs | 0:0bce3a738bcb | 452 | |
SolderSplashLabs | 0:0bce3a738bcb | 453 | pc.printf(" 1 - TCP Client, Connect to %s:%d\r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT_TCP); |
SolderSplashLabs | 0:0bce3a738bcb | 454 | pc.printf(" 2 - TCP Server, listen on %d.%d.%d.%d:%d\r\n", ipinfo.aucIP[3], ipinfo.aucIP[2], ipinfo.aucIP[1], ipinfo.aucIP[0], ECHO_SERVER_PORT_TCP); |
SolderSplashLabs | 0:0bce3a738bcb | 455 | pc.printf(" 3 - Web Socket Write \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 456 | pc.printf(" 4 - Web Socket Read \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 457 | pc.printf(" 5 - HTTP Client \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 458 | pc.printf(" 6 - Xively Post ADC's \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 459 | pc.printf(" x - Exit to top menu "); |
SolderSplashLabs | 0:0bce3a738bcb | 460 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 461 | |
SolderSplashLabs | 0:0bce3a738bcb | 462 | switch(WaitForSerialCommand()) |
SolderSplashLabs | 0:0bce3a738bcb | 463 | { |
SolderSplashLabs | 0:0bce3a738bcb | 464 | case '1': |
SolderSplashLabs | 0:0bce3a738bcb | 465 | TcpClientTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 466 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 467 | case '2': |
SolderSplashLabs | 0:0bce3a738bcb | 468 | TcpServerTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 469 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 470 | case '3': |
SolderSplashLabs | 0:0bce3a738bcb | 471 | WebSocketTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 472 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 473 | case '4': |
SolderSplashLabs | 2:8f5776c287c5 | 474 | WebSocketReadTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 475 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 476 | case '5': |
SolderSplashLabs | 0:0bce3a738bcb | 477 | HttpClientTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 478 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 479 | case '6': |
SolderSplashLabs | 0:0bce3a738bcb | 480 | XivelySimpleTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 481 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 482 | case '0': |
SolderSplashLabs | 0:0bce3a738bcb | 483 | case 'x': |
SolderSplashLabs | 0:0bce3a738bcb | 484 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 485 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 486 | } |
SolderSplashLabs | 0:0bce3a738bcb | 487 | } |
SolderSplashLabs | 0:0bce3a738bcb | 488 | |
SolderSplashLabs | 0:0bce3a738bcb | 489 | |
SolderSplashLabs | 0:0bce3a738bcb | 490 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 491 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 492 | @brief Display a menu to the user |
SolderSplashLabs | 0:0bce3a738bcb | 493 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 494 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 495 | void Menu_Top ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 496 | { |
SolderSplashLabs | 0:0bce3a738bcb | 497 | Menu_PrintHeader(); |
SolderSplashLabs | 0:0bce3a738bcb | 498 | |
SolderSplashLabs | 0:0bce3a738bcb | 499 | pc.printf(" 1 - Connection control menu \r\n" ); |
SolderSplashLabs | 0:0bce3a738bcb | 500 | pc.printf(" 2 - TCP test menu \r\n" ); |
SolderSplashLabs | 0:0bce3a738bcb | 501 | pc.printf(" 3 - UDP test menu \r\n" ); |
SolderSplashLabs | 0:0bce3a738bcb | 502 | pc.printf(" 4 - Connection status \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 503 | pc.printf(" 5 - Ping - %s \r\n", HostToPing); |
SolderSplashLabs | 0:0bce3a738bcb | 504 | pc.printf(" x - Top Menu \r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 505 | |
SolderSplashLabs | 0:0bce3a738bcb | 506 | pc.printf("\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 507 | |
SolderSplashLabs | 0:0bce3a738bcb | 508 | switch(WaitForSerialCommand()) |
SolderSplashLabs | 0:0bce3a738bcb | 509 | { |
SolderSplashLabs | 0:0bce3a738bcb | 510 | case '1': |
SolderSplashLabs | 0:0bce3a738bcb | 511 | currentMenu = MENU_CONNECTION; |
SolderSplashLabs | 0:0bce3a738bcb | 512 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 513 | case '2': |
SolderSplashLabs | 0:0bce3a738bcb | 514 | currentMenu = MENU_TCP; |
SolderSplashLabs | 0:0bce3a738bcb | 515 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 516 | case '3': |
SolderSplashLabs | 0:0bce3a738bcb | 517 | currentMenu = MENU_UDP; |
SolderSplashLabs | 0:0bce3a738bcb | 518 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 519 | case '4': |
SolderSplashLabs | 0:0bce3a738bcb | 520 | print_cc3000_info(); |
SolderSplashLabs | 0:0bce3a738bcb | 521 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 522 | case '5': |
SolderSplashLabs | 0:0bce3a738bcb | 523 | PingTest(); |
SolderSplashLabs | 0:0bce3a738bcb | 524 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 525 | case 'x': |
SolderSplashLabs | 0:0bce3a738bcb | 526 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 527 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 528 | } |
SolderSplashLabs | 0:0bce3a738bcb | 529 | } |
SolderSplashLabs | 0:0bce3a738bcb | 530 | |
SolderSplashLabs | 0:0bce3a738bcb | 531 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 532 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 533 | @brief Pick which menu to display |
SolderSplashLabs | 0:0bce3a738bcb | 534 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 535 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 536 | void MenuSwitch ( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 537 | { |
SolderSplashLabs | 0:0bce3a738bcb | 538 | bool connected = false; |
SolderSplashLabs | 0:0bce3a738bcb | 539 | |
SolderSplashLabs | 0:0bce3a738bcb | 540 | if ( wifi.is_dhcp_configured() ) |
SolderSplashLabs | 0:0bce3a738bcb | 541 | { |
SolderSplashLabs | 0:0bce3a738bcb | 542 | connected = true; |
SolderSplashLabs | 0:0bce3a738bcb | 543 | } |
SolderSplashLabs | 0:0bce3a738bcb | 544 | |
SolderSplashLabs | 0:0bce3a738bcb | 545 | switch ( currentMenu ) |
SolderSplashLabs | 0:0bce3a738bcb | 546 | { |
SolderSplashLabs | 0:0bce3a738bcb | 547 | case MENU_TOP : |
SolderSplashLabs | 0:0bce3a738bcb | 548 | Menu_Top(); |
SolderSplashLabs | 0:0bce3a738bcb | 549 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 550 | |
SolderSplashLabs | 0:0bce3a738bcb | 551 | case MENU_CONNECTION : |
SolderSplashLabs | 0:0bce3a738bcb | 552 | Menu_ConnectionControl(); |
SolderSplashLabs | 0:0bce3a738bcb | 553 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 554 | |
SolderSplashLabs | 0:0bce3a738bcb | 555 | case MENU_TCP : |
SolderSplashLabs | 0:0bce3a738bcb | 556 | if (connected) |
SolderSplashLabs | 0:0bce3a738bcb | 557 | { |
SolderSplashLabs | 0:0bce3a738bcb | 558 | Menu_TcpControl(); |
SolderSplashLabs | 0:0bce3a738bcb | 559 | } |
SolderSplashLabs | 0:0bce3a738bcb | 560 | else |
SolderSplashLabs | 0:0bce3a738bcb | 561 | { |
SolderSplashLabs | 0:0bce3a738bcb | 562 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 563 | } |
SolderSplashLabs | 0:0bce3a738bcb | 564 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 565 | |
SolderSplashLabs | 0:0bce3a738bcb | 566 | case MENU_UDP : |
SolderSplashLabs | 0:0bce3a738bcb | 567 | if (connected) |
SolderSplashLabs | 0:0bce3a738bcb | 568 | { |
SolderSplashLabs | 0:0bce3a738bcb | 569 | Menu_UdpControl(); |
SolderSplashLabs | 0:0bce3a738bcb | 570 | } |
SolderSplashLabs | 0:0bce3a738bcb | 571 | else |
SolderSplashLabs | 0:0bce3a738bcb | 572 | { |
SolderSplashLabs | 0:0bce3a738bcb | 573 | currentMenu = MENU_TOP; |
SolderSplashLabs | 0:0bce3a738bcb | 574 | } |
SolderSplashLabs | 0:0bce3a738bcb | 575 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 576 | |
SolderSplashLabs | 0:0bce3a738bcb | 577 | default : |
SolderSplashLabs | 0:0bce3a738bcb | 578 | pc.printf("Unknown command\r\n"); |
SolderSplashLabs | 0:0bce3a738bcb | 579 | break; |
SolderSplashLabs | 0:0bce3a738bcb | 580 | } |
SolderSplashLabs | 0:0bce3a738bcb | 581 | } |
SolderSplashLabs | 0:0bce3a738bcb | 582 | |
SolderSplashLabs | 0:0bce3a738bcb | 583 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 584 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 585 | @brief Init |
SolderSplashLabs | 0:0bce3a738bcb | 586 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 587 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 588 | void init() |
SolderSplashLabs | 0:0bce3a738bcb | 589 | { |
SolderSplashLabs | 0:0bce3a738bcb | 590 | NVIC_SetPriority(SSP1_IRQn, 0x0); |
SolderSplashLabs | 0:0bce3a738bcb | 591 | NVIC_SetPriority(PIN_INT0_IRQn, 0x1); |
SolderSplashLabs | 0:0bce3a738bcb | 592 | |
SolderSplashLabs | 0:0bce3a738bcb | 593 | // SysTick set to lower priority than Wi-Fi SPI bus interrupt |
SolderSplashLabs | 0:0bce3a738bcb | 594 | NVIC_SetPriority(SysTick_IRQn, 0x2); |
SolderSplashLabs | 3:15828ac052f1 | 595 | |
SolderSplashLabs | 3:15828ac052f1 | 596 | |
SolderSplashLabs | 3:15828ac052f1 | 597 | // Enable RAM1 |
SolderSplashLabs | 3:15828ac052f1 | 598 | LPC_SYSCON->SYSAHBCLKCTRL |= (0x1 << 26); |
SolderSplashLabs | 0:0bce3a738bcb | 599 | } |
SolderSplashLabs | 0:0bce3a738bcb | 600 | |
SolderSplashLabs | 0:0bce3a738bcb | 601 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 602 | /*! |
SolderSplashLabs | 0:0bce3a738bcb | 603 | @brief main loop |
SolderSplashLabs | 0:0bce3a738bcb | 604 | */ |
SolderSplashLabs | 0:0bce3a738bcb | 605 | // ------------------------------------------------------------------------------------------------------------ |
SolderSplashLabs | 0:0bce3a738bcb | 606 | int main( void ) |
SolderSplashLabs | 0:0bce3a738bcb | 607 | { |
SolderSplashLabs | 0:0bce3a738bcb | 608 | // Initalise the WiFi Module |
SolderSplashLabs | 0:0bce3a738bcb | 609 | init(); |
SolderSplashLabs | 0:0bce3a738bcb | 610 | |
SolderSplashLabs | 0:0bce3a738bcb | 611 | uart.baud(SERIAL_BAUD_RATE); |
SolderSplashLabs | 0:0bce3a738bcb | 612 | |
SolderSplashLabs | 0:0bce3a738bcb | 613 | wait(1); |
SolderSplashLabs | 0:0bce3a738bcb | 614 | wifi.start(0); |
SolderSplashLabs | 0:0bce3a738bcb | 615 | |
SolderSplashLabs | 0:0bce3a738bcb | 616 | wait_ms(750); |
SolderSplashLabs | 0:0bce3a738bcb | 617 | |
SolderSplashLabs | 0:0bce3a738bcb | 618 | while (1) |
SolderSplashLabs | 0:0bce3a738bcb | 619 | { |
SolderSplashLabs | 0:0bce3a738bcb | 620 | MenuSwitch(); |
SolderSplashLabs | 0:0bce3a738bcb | 621 | } |
SolderSplashLabs | 0:0bce3a738bcb | 622 | } |