Austin Blackstone / Mbed 2 deprecated murataDemo

Dependencies:   SNICInterface mbed-rtos mbed

Fork of SNIC-xively-jumpstart-demo by muRata

Committer:
mbedAustin
Date:
Wed Apr 01 23:05:11 2015 +0000
Revision:
29:9f08c7152c7a
Parent:
28:174412ff9671
Child:
30:de5a32932408
got some initial stuff working

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 21:25b85cbbdd82 1 /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License
kishino 23:39cf9f03b076 2 * muRata, SWITCH SCIENCE Wi-FI module TypeYD SNIC-UART.
kishino 21:25b85cbbdd82 3 *
kishino 21:25b85cbbdd82 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
kishino 21:25b85cbbdd82 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
kishino 21:25b85cbbdd82 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
kishino 21:25b85cbbdd82 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
kishino 21:25b85cbbdd82 8 * furnished to do so, subject to the following conditions:
kishino 21:25b85cbbdd82 9 *
kishino 21:25b85cbbdd82 10 * The above copyright notice and this permission notice shall be included in all copies or
kishino 21:25b85cbbdd82 11 * substantial portions of the Software.
kishino 21:25b85cbbdd82 12 *
kishino 21:25b85cbbdd82 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
kishino 21:25b85cbbdd82 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
kishino 21:25b85cbbdd82 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kishino 21:25b85cbbdd82 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kishino 21:25b85cbbdd82 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kishino 21:25b85cbbdd82 18 */
xively 0:efdea27c3b81 19 #include "mbed.h"
kishino 14:6d58d3855feb 20 #include "SNIC_WifiInterface.h"
xively 7:0eff5db44b8b 21
mbedAustin 28:174412ff9671 22 Serial pc(USBTX, USBRX);
xively 7:0eff5db44b8b 23
errordeveloper 10:86ffba646df1 24
mbedAustin 29:9f08c7152c7a 25 #define WIFI_SSID "demossid"
mbedAustin 29:9f08c7152c7a 26 #define WIFI_SECURITY_TYPE e_SEC_OPEN
mbedAustin 28:174412ff9671 27 #define WIFI_SECUTIRY_KEY "WPA2_PASSPHRASE"
mbedAustin 28:174412ff9671 28 #define WIFI_SECUTIRY_KEY_LEN 15
errordeveloper 11:bdf601a405fc 29
mbedAustin 29:9f08c7152c7a 30 //#define WIFI_SSID "AP_SSID"
mbedAustin 29:9f08c7152c7a 31 //#define WIFI_SECURITY_TYPE e_SEC_WPA2_AES
mbedAustin 29:9f08c7152c7a 32 //#define WIFI_SECUTIRY_KEY "WPA2_PASSPHRASE"
mbedAustin 29:9f08c7152c7a 33 //#define WIFI_SECUTIRY_KEY_LEN 15
mbedAustin 29:9f08c7152c7a 34
mbedAustin 29:9f08c7152c7a 35
mbedAustin 28:174412ff9671 36 C_SNIC_WifiInterface wifi( D1, D0, NC, NC, D3 );
kishino 17:0bf3c49a83d5 37
mbedAustin 28:174412ff9671 38 int main()
mbedAustin 28:174412ff9671 39 {
mbedAustin 28:174412ff9671 40 // for built in debug printouts
mbedAustin 29:9f08c7152c7a 41 // pc.baud( 115200 );
mbedAustin 29:9f08c7152c7a 42
mbedAustin 29:9f08c7152c7a 43 int check = 0;
mbedAustin 28:174412ff9671 44
kishino 14:6d58d3855feb 45 // Initialize Wi-Fi interface
mbedAustin 29:9f08c7152c7a 46 check = wifi.init();
mbedAustin 29:9f08c7152c7a 47 if( check != 0 ) {
mbedAustin 28:174412ff9671 48 printf( "Wifi could not be initialized, halting.\r\n" );
kishino 14:6d58d3855feb 49 return -1;
mbedAustin 29:9f08c7152c7a 50 } else {
mbedAustin 28:174412ff9671 51 printf("wifi initialized successfully!\r\n");
mbedAustin 28:174412ff9671 52 }
kishino 19:4e2900daad59 53 wait(0.5);
mbedAustin 29:9f08c7152c7a 54
mbedAustin 28:174412ff9671 55 // good form to make sure you are disconnected from all AP's
mbedAustin 29:9f08c7152c7a 56 check = wifi.disconnect();
mbedAustin 29:9f08c7152c7a 57 if( check != 0 ) {
mbedAustin 28:174412ff9671 58 printf( "disconnect failed\r\n" );
mbedAustin 28:174412ff9671 59 return -1;
mbedAustin 29:9f08c7152c7a 60 } else {
mbedAustin 28:174412ff9671 61 printf("disconnection successful!\r\n");
mbedAustin 29:9f08c7152c7a 62 }
mbedAustin 28:174412ff9671 63 wait(0.3);
mbedAustin 29:9f08c7152c7a 64
mbedAustin 28:174412ff9671 65 // Connect AP
mbedAustin 29:9f08c7152c7a 66 check = wifi.connect( WIFI_SSID
mbedAustin 29:9f08c7152c7a 67 , strlen(WIFI_SSID)
mbedAustin 29:9f08c7152c7a 68 , WIFI_SECURITY_TYPE
mbedAustin 29:9f08c7152c7a 69 , WIFI_SECUTIRY_KEY
mbedAustin 29:9f08c7152c7a 70 , WIFI_SECUTIRY_KEY_LEN );
mbedAustin 29:9f08c7152c7a 71 if( check != 0) {
mbedAustin 29:9f08c7152c7a 72 printf("Connect Failed\r\n");
mbedAustin 29:9f08c7152c7a 73 } else {
mbedAustin 29:9f08c7152c7a 74 printf("connected successfully!\r\n");
mbedAustin 29:9f08c7152c7a 75 }
kishino 14:6d58d3855feb 76 wait(0.5);
kishino 14:6d58d3855feb 77
mbedAustin 29:9f08c7152c7a 78 // Get DHCP IP
mbedAustin 29:9f08c7152c7a 79 check = wifi.setIPConfig( true ); // get IP as DHCP IP
mbedAustin 29:9f08c7152c7a 80 if(check != 0) {
mbedAustin 29:9f08c7152c7a 81 printf("SetIPConfig failed \r\n");
mbedAustin 29:9f08c7152c7a 82 } else {
mbedAustin 29:9f08c7152c7a 83 printf("SetIPConfig successful \r\n");
mbedAustin 29:9f08c7152c7a 84 }
mbedAustin 29:9f08c7152c7a 85
mbedAustin 29:9f08c7152c7a 86 // Get RSSI
mbedAustin 29:9f08c7152c7a 87 signed char temp = 0;
mbedAustin 29:9f08c7152c7a 88 check = wifi.getRssi(&temp);
mbedAustin 29:9f08c7152c7a 89 if(check != 0){
mbedAustin 29:9f08c7152c7a 90 printf("getRssi failed. \r\n");
mbedAustin 29:9f08c7152c7a 91 }else{
mbedAustin 29:9f08c7152c7a 92 printf("getRssi success: %d \r\n",temp);
mbedAustin 29:9f08c7152c7a 93 }
mbedAustin 29:9f08c7152c7a 94
mbedAustin 29:9f08c7152c7a 95 // if(check != 0){
mbedAustin 29:9f08c7152c7a 96 // printf(" \r\n");
mbedAustin 29:9f08c7152c7a 97 // }else{
mbedAustin 29:9f08c7152c7a 98 // printf(" \r\n");
mbedAustin 29:9f08c7152c7a 99 // }
mbedAustin 28:174412ff9671 100
mbedAustin 28:174412ff9671 101 wait( 1.0 );
Ilya Dmitrichenko 6:9e4f4a8c1829 102 }