NNN50 WIFI_API library
Dependents: NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more
This is mbed compatible EthernetInterface lib exclude for Delta DFCM-NNN50 platform.
Additional information and examples can be found in mbed Handbook
WIFIDevice.h@32:8298a2fb074f, 2017-09-04 (annotated)
- Committer:
- tsungta
- Date:
- Mon Sep 04 05:40:11 2017 +0000
- Revision:
- 32:8298a2fb074f
- Parent:
- 31:f7c71d050c36
56:f4cc53f; Add getRSSI() to readout RSSI while connected with AP router; Add SSL support refer to TCPSocketConnection.connect()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tsungta | 0:06fccc63b33d | 1 | #ifndef WIFIDEVICE_H_ |
tsungta | 0:06fccc63b33d | 2 | #define WIFIDEVICE_H_ |
tsungta | 0:06fccc63b33d | 3 | |
tsungta | 0:06fccc63b33d | 4 | /** Interface using WI-FI to connect to Ethernet |
tsungta | 0:06fccc63b33d | 5 | * |
tsungta | 0:06fccc63b33d | 6 | */ |
tsungta | 0:06fccc63b33d | 7 | |
tsungta | 31:f7c71d050c36 | 8 | //#include "mbed.h" |
tsungta | 31:f7c71d050c36 | 9 | #include <stdio.h> |
tsungta | 31:f7c71d050c36 | 10 | #include "nrf_delay.h" |
tsungta | 31:f7c71d050c36 | 11 | |
tsungta | 31:f7c71d050c36 | 12 | #include "drivers/Ticker.h" |
tsungta | 31:f7c71d050c36 | 13 | #include "drivers/InterruptIn.h" |
tsungta | 31:f7c71d050c36 | 14 | using namespace mbed; |
tsungta | 31:f7c71d050c36 | 15 | |
tsungta | 0:06fccc63b33d | 16 | #include "EthernetInterface.h" |
tsungta | 0:06fccc63b33d | 17 | |
tsungta | 0:06fccc63b33d | 18 | class WIFIDevice { |
tsungta | 0:06fccc63b33d | 19 | public: |
tsungta | 0:06fccc63b33d | 20 | |
tsungta | 0:06fccc63b33d | 21 | /** Set WIFI in sleep mode. |
tsungta | 0:06fccc63b33d | 22 | * Disable WIFI and set into sleep mode to conserve energy (no WIFI function is available at this point). |
tsungta | 0:06fccc63b33d | 23 | * \return 0 on success, a negative number on failure |
tsungta | 0:06fccc63b33d | 24 | */ |
tsungta | 0:06fccc63b33d | 25 | int sleep(void); |
tsungta | 0:06fccc63b33d | 26 | |
tsungta | 0:06fccc63b33d | 27 | /** Check if the device is connected to Access Point |
tsungta | 0:06fccc63b33d | 28 | * \return 1 if connected, 0 otherwise. |
tsungta | 0:06fccc63b33d | 29 | */ |
tsungta | 0:06fccc63b33d | 30 | int is_AP_connected(void); |
tsungta | 0:06fccc63b33d | 31 | |
tsungta | 0:06fccc63b33d | 32 | /** Perform WIFI scan. |
tsungta | 0:06fccc63b33d | 33 | * Scan for available access point on all channels. |
tsungta | 0:06fccc63b33d | 34 | * \return number of scanned WIFI access point |
tsungta | 0:06fccc63b33d | 35 | */ |
tsungta | 0:06fccc63b33d | 36 | int apScan(void (*eventCallback)(tstrM2mWifiscanResult result)); |
tsungta | 0:06fccc63b33d | 37 | |
tsungta | 0:06fccc63b33d | 38 | /** Set network connection in priority. |
tsungta | 0:06fccc63b33d | 39 | * Set SSID, password and priority to connect. |
tsungta | 0:06fccc63b33d | 40 | * \param secType type of securith support in STA mode, support |
tsungta | 0:06fccc63b33d | 41 | M2M_WIFI_SEC_OPEN < Open security > |
tsungta | 0:06fccc63b33d | 42 | M2M_WIFI_SEC_WPA_PSK < Wi-Fi network is secured with WPA/WPA2 personal(PSK) > |
tsungta | 0:06fccc63b33d | 43 | M2M_WIFI_SEC_WEP < Security type WEP (40 or 104) OPEN OR SHARED > |
tsungta | 0:06fccc63b33d | 44 | M2M_WIFI_SEC_802_1X < Wi-Fi network is secured with WPA/WPA2 Enterprise.IEEE802.1x user-name/password authentication > |
tsungta | 0:06fccc63b33d | 45 | * \param SSID name of access point to connect |
tsungta | 9:32d6cd2f8456 | 46 | * \param PW password of the given SSID |
tsungta | 9:32d6cd2f8456 | 47 | * \param wepIndex WEP Index of PW when using M2M_WIFI_SEC_WEP (set between 1 to 4) |
tsungta | 0:06fccc63b33d | 48 | */ |
tsungta | 9:32d6cd2f8456 | 49 | void setNetwork(uint8_t secType, char* SSID, char* PW, uint8_t wepIndex = 1); |
tsungta | 0:06fccc63b33d | 50 | |
tsungta | 9:32d6cd2f8456 | 51 | /** Set WPA/WPA2 Enterprise.IEEE802.1x user-name/password authentication. |
tsungta | 9:32d6cd2f8456 | 52 | * \param USER user-name of IEEE802.1x authentication |
tsungta | 9:32d6cd2f8456 | 53 | * \param PW password of IEEE802.1x authentication |
tsungta | 9:32d6cd2f8456 | 54 | */ |
tsungta | 9:32d6cd2f8456 | 55 | void setLogin(char* USER, char* PW); |
tsungta | 9:32d6cd2f8456 | 56 | |
tsungta | 9:32d6cd2f8456 | 57 | /** Trigger Wi-Fi Protected Setup (WPS). |
tsungta | 9:32d6cd2f8456 | 58 | * WPS activation and scan for fixed 120 seconds (support WPA/WPA2 key only). |
tsungta | 9:32d6cd2f8456 | 59 | * \return 0 on success (AP connected), a negative number on failure (timeout) |
tsungta | 9:32d6cd2f8456 | 60 | */ |
tsungta | 9:32d6cd2f8456 | 61 | int triggerWPS(); |
tsungta | 9:32d6cd2f8456 | 62 | |
tsungta | 1:be6abb24f013 | 63 | /** Enable Access Point in given configuration. |
tsungta | 0:06fccc63b33d | 64 | * Set SSID, password, security type and channel in AP mode. |
tsungta | 0:06fccc63b33d | 65 | * \param SSID name of access point in AP mode |
tsungta | 0:06fccc63b33d | 66 | * \param PW password of the given SSID |
tsungta | 1:be6abb24f013 | 67 | * \param AP_ip the IP address of AP |
tsungta | 1:be6abb24f013 | 68 | * \param security tyoe of security in AP mode (default: (M2M_WIFI_SEC_WEP)), support |
tsungta | 1:be6abb24f013 | 69 | M2M_WIFI_SEC_OPEN < Open security > |
tsungta | 1:be6abb24f013 | 70 | M2M_WIFI_SEC_WEP < Security type WEP with 10 hexadecimal digits > |
tsungta | 0:06fccc63b33d | 71 | * \param channel range from 1 to 14 (default: (1)) |
tsungta | 1:be6abb24f013 | 72 | * \return 0 on success, a negative number on failure |
tsungta | 0:06fccc63b33d | 73 | */ |
tsungta | 25:2008b3bae5ca | 74 | int enableAccessPoint(char* SSID, char* PW, char* AP_ip = "192.168.1.1", uint8_t secType=M2M_WIFI_SEC_WEP, uint8_t channel=1); |
tsungta | 0:06fccc63b33d | 75 | |
tsungta | 27:617c6acde338 | 76 | /** Set TX power level, must be called after the EthernetInterface initialization and before any connection request and can't be changed in runtime. |
tsungta | 27:617c6acde338 | 77 | * \param power_level can be configurable as following |
tsungta | 27:617c6acde338 | 78 | TX_PWR_HIGH < High power level > |
tsungta | 27:617c6acde338 | 79 | TX_PWR_MED < Med power level > |
tsungta | 27:617c6acde338 | 80 | TX_PWR_LOW < Low power level > |
tsungta | 27:617c6acde338 | 81 | * \return 0 on success, a negative number on failure |
tsungta | 27:617c6acde338 | 82 | */ |
tsungta | 27:617c6acde338 | 83 | int setTXPower(uint8_t power_level); |
tsungta | 27:617c6acde338 | 84 | |
tsungta | 27:617c6acde338 | 85 | /** Set the PPA (Pre-Power Amplifier) gain, must be called after the EthernetInterface initialization |
tsungta | 27:617c6acde338 | 86 | * \param gain_dB is only configable among 3, 6, 9 dB, default is 9 dB |
tsungta | 27:617c6acde338 | 87 | * \return 0 on success, a negative number on failure |
tsungta | 27:617c6acde338 | 88 | */ |
tsungta | 27:617c6acde338 | 89 | int setPPAGain(uint8_t gain_dB); |
tsungta | 27:617c6acde338 | 90 | |
tsungta | 31:f7c71d050c36 | 91 | /** get the current RSSI from the connected AP |
tsungta | 31:f7c71d050c36 | 92 | * \return a negative RSSI value in dBm |
tsungta | 31:f7c71d050c36 | 93 | */ |
tsungta | 31:f7c71d050c36 | 94 | int getRSSI(void); |
tsungta | 31:f7c71d050c36 | 95 | |
tsungta | 0:06fccc63b33d | 96 | /** Erase a 4KB sector of embeeded flash. |
tsungta | 0:06fccc63b33d | 97 | * Flash memory will be erased in groups of 4KB sector. |
tsungta | 0:06fccc63b33d | 98 | * \param address range from 0x00 to 0x3F000 (must be a multiple of 0x1000). |
tsungta | 0:06fccc63b33d | 99 | * \return 0 on success, a negative number on failure |
tsungta | 0:06fccc63b33d | 100 | */ |
tsungta | 0:06fccc63b33d | 101 | //int storage_erase4KB(uint32_t address); |
tsungta | 0:06fccc63b33d | 102 | |
tsungta | 0:06fccc63b33d | 103 | /** Write data into embeeded flash. |
tsungta | 0:06fccc63b33d | 104 | * Write one (multiple) byte(s) of data into flash, must perform erase before the flash memory area can be overwrite. |
tsungta | 0:06fccc63b33d | 105 | * \param address flash memory address to be written, range from 0x00 to 0x3FFFF. |
tsungta | 0:06fccc63b33d | 106 | * \param data pointer to the buffer containing data to be written. |
tsungta | 0:06fccc63b33d | 107 | * \param len length of the data to be written to flash. |
tsungta | 0:06fccc63b33d | 108 | * \return 0 on success, a negative number on failure |
tsungta | 0:06fccc63b33d | 109 | */ |
tsungta | 0:06fccc63b33d | 110 | //int storage_write(uint32_t address, uint8_t *data, uint16_t len); |
tsungta | 0:06fccc63b33d | 111 | |
tsungta | 0:06fccc63b33d | 112 | /** Read data from embeeded flash. |
tsungta | 0:06fccc63b33d | 113 | * Read one (multiple) byte(s) of data from flash. |
tsungta | 0:06fccc63b33d | 114 | * \param address flash memory address to be read, range from 0x00 to 0x3FFFF. |
tsungta | 0:06fccc63b33d | 115 | * \param data pointer to the buffer containing data to be read. |
tsungta | 0:06fccc63b33d | 116 | * \param len length of the data to be read from flash. |
tsungta | 0:06fccc63b33d | 117 | * \return 0 on success, a negative number on failure |
tsungta | 0:06fccc63b33d | 118 | */ |
tsungta | 0:06fccc63b33d | 119 | //int storage_read(uint32_t address, uint8_t *data, uint16_t len); |
tsungta | 0:06fccc63b33d | 120 | |
tsungta | 0:06fccc63b33d | 121 | }; |
tsungta | 0:06fccc63b33d | 122 | |
tsungta | 0:06fccc63b33d | 123 | int enableCoexistance(); |
tsungta | 25:2008b3bae5ca | 124 | void RF_Switch_WIFI_lock(void); |
tsungta | 25:2008b3bae5ca | 125 | void RF_Switch_WIFI_unlock(void); |
tsungta | 29:86b2de427eab | 126 | #define WIFI_WINDOW_US 600 //min is 300 |
tsungta | 29:86b2de427eab | 127 | #define BLE_WINDOW_US 600 //min is 300 |
tsungta | 0:06fccc63b33d | 128 | |
tsungta | 0:06fccc63b33d | 129 | #endif /* WIFIDEVICE_H_ */ |
tsungta | 27:617c6acde338 | 130 |