SNIC UART Interface library: Serial to Wi-Fi library for Murata TypeYD Wi-Fi module. For more information about TypeYD: http://www.murata.co.jp/products/microwave/module/lbwb1zzydz/index.html

Dependents:   SNIC-xively-jumpstart-demo SNIC-FluentLogger-example TCPEchoServer murataDemo ... more

Fork of YDwifiInterface by Takao Kishino

Committer:
MACRUM
Date:
Tue Mar 31 03:16:46 2015 +0000
Revision:
53:b53ccb9989c4
Parent:
51:69a9cf901d54
Added default constructor and create() method

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kishino 39:a1233ca02edf 1 /* Copyright (C) 2014 Murata Manufacturing Co.,Ltd., MIT License
kishino 39:a1233ca02edf 2 * muRata, SWITCH SCIENCE Wi-FI module TypeYD-SNIC UART.
kishino 14:54378c96d285 3 *
kishino 39:a1233ca02edf 4 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
kishino 39:a1233ca02edf 5 * and associated documentation files (the "Software"), to deal in the Software without restriction,
kishino 39:a1233ca02edf 6 * including without limitation the rights to use, copy, modify, merge, publish, distribute,
kishino 39:a1233ca02edf 7 * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
kishino 39:a1233ca02edf 8 * furnished to do so, subject to the following conditions:
kishino 14:54378c96d285 9 *
kishino 39:a1233ca02edf 10 * The above copyright notice and this permission notice shall be included in all copies or
kishino 39:a1233ca02edf 11 * substantial portions of the Software.
kishino 14:54378c96d285 12 *
kishino 39:a1233ca02edf 13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
kishino 39:a1233ca02edf 14 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
kishino 39:a1233ca02edf 15 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
kishino 39:a1233ca02edf 16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
kishino 39:a1233ca02edf 17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
kishino 39:a1233ca02edf 18 */
kishino 12:0254eaccfda2 19 #ifndef _SNIC_WIFIINTERFACE_H_
kishino 12:0254eaccfda2 20 #define _SNIC_WIFIINTERFACE_H_
kishino 12:0254eaccfda2 21
kishino 12:0254eaccfda2 22 #include "SNIC_Core.h"
kishino 25:67183ed15708 23 #include "MurataObject.h"
kishino 12:0254eaccfda2 24
kishino 23:4ff2231ff9ba 25 /** Wi-Fi status used by getWifiStatus(). */
kishino 12:0254eaccfda2 26 typedef struct
kishino 12:0254eaccfda2 27 {
kishino 12:0254eaccfda2 28 /** status */
kishino 12:0254eaccfda2 29 E_WIFI_STATUS status;
kishino 12:0254eaccfda2 30 /** Mac address */
kishino 12:0254eaccfda2 31 char mac_address[BSSID_MAC_LENTH];
kishino 12:0254eaccfda2 32 /** SSID */
kishino 12:0254eaccfda2 33 char ssid[SSID_MAX_LENGTH+1];
kishino 12:0254eaccfda2 34 }tagWIFI_STATUS_T;
kishino 12:0254eaccfda2 35
kishino 23:4ff2231ff9ba 36 /** Interface class for using SNIC UART.
kishino 12:0254eaccfda2 37 */
kishino 25:67183ed15708 38 class C_SNIC_WifiInterface : public C_MurataObject {
kishino 31:15c22824cc46 39
kishino 12:0254eaccfda2 40 public:
MACRUM 53:b53ccb9989c4 41 /** Default constructor
MACRUM 53:b53ccb9989c4 42 */
MACRUM 53:b53ccb9989c4 43 C_SNIC_WifiInterface() {};
MACRUM 53:b53ccb9989c4 44
kishino 12:0254eaccfda2 45 /** Constructor
kishino 12:0254eaccfda2 46 @param tx mbed pin to use for tx line of Serial interface
kishino 12:0254eaccfda2 47 @param rx mbed pin to use for rx line of Serial interface
kishino 12:0254eaccfda2 48 @param cts mbed pin to use for cts line of Serial interface
kishino 12:0254eaccfda2 49 @param rts mbed pin to use for rts line of Serial interface
kishino 12:0254eaccfda2 50 @param reset reset pin of the wifi module
kishino 12:0254eaccfda2 51 @param alarm alarm pin of the wifi module (default: NC)
kishino 43:d80bbb12ffe6 52 @param baud baud rate of Serial interface (default: 115200)
kishino 12:0254eaccfda2 53 */
kishino 12:0254eaccfda2 54 C_SNIC_WifiInterface(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 115200);
kishino 26:f2e1030964e4 55 virtual ~C_SNIC_WifiInterface();
kishino 12:0254eaccfda2 56
MACRUM 53:b53ccb9989c4 57 /** Create instance.
MACRUM 53:b53ccb9989c4 58 */
MACRUM 53:b53ccb9989c4 59 void create(PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 115200);
MACRUM 53:b53ccb9989c4 60
MACRUM 53:b53ccb9989c4 61 /** Initialize the interface.
kishino 12:0254eaccfda2 62 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 63 */
kishino 12:0254eaccfda2 64 int init();
kishino 12:0254eaccfda2 65
kishino 12:0254eaccfda2 66 /** Get Firmware version string.
kishino 12:0254eaccfda2 67 @param version_p Pointer of FW version string.(null terminated)[output]
kishino 12:0254eaccfda2 68 @return 0:success/other:fail
kishino 12:0254eaccfda2 69 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 70 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 71 */
kishino 12:0254eaccfda2 72 int getFWVersion( unsigned char *version_p );
kishino 12:0254eaccfda2 73
kishino 12:0254eaccfda2 74 /** Connect to AP
kishino 12:0254eaccfda2 75 @param ssid_p Wi-Fi SSID(null terminated)
kishino 12:0254eaccfda2 76 @param ssid_len Wi-Fi SSID length
kishino 12:0254eaccfda2 77 @param sec_type Wi-Fi security type.
kishino 12:0254eaccfda2 78 @param sec_key_len Wi-Fi passphrase or security key length
kishino 12:0254eaccfda2 79 @param sec_key_p Wi-Fi passphrase or security key
kishino 12:0254eaccfda2 80 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 81 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 82 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 83 */
kishino 12:0254eaccfda2 84 int connect(const char *ssid_p, unsigned char ssid_len, E_SECURITY sec_type, const char *sec_key_p, unsigned char sec_key_len);
kishino 12:0254eaccfda2 85
kishino 12:0254eaccfda2 86 /** Disconnect from AP
kishino 12:0254eaccfda2 87 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 88 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 89 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 90 */
kishino 12:0254eaccfda2 91 int disconnect();
kishino 12:0254eaccfda2 92
kishino 12:0254eaccfda2 93 /** Scan AP
kishino 12:0254eaccfda2 94 @param ssid_p Wi-Fi SSID(null terminated)
kishino 12:0254eaccfda2 95 If do not specify SSID, set to NULL.
kishino 12:0254eaccfda2 96 @param bssid_p Wi-Fi BSSID(null terminated)
kishino 12:0254eaccfda2 97 If do not specify SSID, set to NULL.
kishino 12:0254eaccfda2 98 @param result_handler_p Pointer of scan result callback function.
kishino 12:0254eaccfda2 99 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 100 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 101 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 102 Scan results will be notified by asynchronous callback function.
kishino 43:d80bbb12ffe6 103 If there is no continuity data, scan_result will be set NULL..
kishino 12:0254eaccfda2 104 */
kishino 12:0254eaccfda2 105 int scan( const char *ssid_p, unsigned char *bssid_p
kishino 12:0254eaccfda2 106 ,void (*result_handler_p)(tagSCAN_RESULT_T *scan_result) );
kishino 12:0254eaccfda2 107
kishino 12:0254eaccfda2 108 /** Wi-Fi Turn on
kishino 12:0254eaccfda2 109 @param country_p Pointer of country code.
kishino 12:0254eaccfda2 110 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 111 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 112 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 113 */
kishino 12:0254eaccfda2 114 int wifi_on( const char *country_p );
kishino 12:0254eaccfda2 115
kishino 12:0254eaccfda2 116 /** Wi-Fi Turn off
kishino 12:0254eaccfda2 117 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 118 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 119 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 120 */
kishino 12:0254eaccfda2 121 int wifi_off();
kishino 12:0254eaccfda2 122
kishino 12:0254eaccfda2 123 /** Get Wi-Fi RSSI
kishino 12:0254eaccfda2 124 @param rssi_p Pointer of RSSI.[output]
kishino 12:0254eaccfda2 125 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 126 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 127 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 128 */
kishino 12:0254eaccfda2 129 int getRssi( signed char *rssi_p );
kishino 12:0254eaccfda2 130
kishino 12:0254eaccfda2 131 /** Get Wi-Fi status
kishino 12:0254eaccfda2 132 @param status_p Pointer of status structure.[output]
kishino 12:0254eaccfda2 133 @return 0 on success, a negative number on failure
kishino 12:0254eaccfda2 134 @note This function is blocked until a returns.
kishino 12:0254eaccfda2 135 When you use it by UI thread, be careful.
kishino 12:0254eaccfda2 136 */
kishino 12:0254eaccfda2 137 int getWifiStatus( tagWIFI_STATUS_T *status_p);
kishino 12:0254eaccfda2 138
kishino 31:15c22824cc46 139 /** Set IP configuration
kishino 31:15c22824cc46 140 @param is_DHCP true:DHCP false:static IP.
kishino 31:15c22824cc46 141 @param ip_p Pointer of strings of IP address.(null terminate).
kishino 31:15c22824cc46 142 @param mask_p Pointer of strings of Netmask.(null terminate).
kishino 31:15c22824cc46 143 @param gateway_p Pointer of strings of gateway address.(null terminate).
kishino 31:15c22824cc46 144 @return 0 on success, a negative number on failure
kishino 31:15c22824cc46 145 @note This function is blocked until a returns.
kishino 31:15c22824cc46 146 When you use it by UI thread, be careful.
kishino 31:15c22824cc46 147 */
kishino 31:15c22824cc46 148 int setIPConfig( bool is_DHCP, const char *ip_p=NULL, const char *mask_p=NULL, const char *gateway_p=NULL );
kishino 12:0254eaccfda2 149
MACRUM 51:69a9cf901d54 150 /** Get the IP address of your SNIC interface
MACRUM 51:69a9cf901d54 151 * \return a pointer to a string containing the IP address
MACRUM 51:69a9cf901d54 152 */
MACRUM 51:69a9cf901d54 153 static char* getIPAddress();
MACRUM 51:69a9cf901d54 154
kishino 12:0254eaccfda2 155 private:
kishino 12:0254eaccfda2 156 PinName mUART_tx;
kishino 12:0254eaccfda2 157 PinName mUART_rx;
kishino 12:0254eaccfda2 158 PinName mUART_cts;
kishino 12:0254eaccfda2 159 PinName mUART_rts;
kishino 12:0254eaccfda2 160 int mUART_baud;
kishino 12:0254eaccfda2 161 PinName mModuleReset;
kishino 12:0254eaccfda2 162 };
kishino 12:0254eaccfda2 163 #endif /* _YD_WIFIINTERFACE_H_ */