|
1 |
| -#pragma once |
| 1 | +#ifndef C_ARDUINO_WIFI_H |
| 2 | +#define C_ARDUINO_WIFI_H |
2 | 3 |
|
3 | 4 | #include "CNetIf.h"
|
4 | 5 |
|
5 |
| -#include "WiFiClient.h" |
6 |
| -#include "WiFiServer.h" |
7 |
| -#include "WiFiUdp.h" |
8 |
| - |
9 | 6 | #define WIFI_FIRMWARE_LATEST_VERSION "1.5.0"
|
10 | 7 |
|
11 |
| -// TODO Instantiate the drivers for wifi with default configuration parameters |
| 8 | +class CWifi { |
| 9 | +private: |
| 10 | + void _config(IPAddress local_ip, IPAddress gateway, IPAddress subnet); |
| 11 | + unsigned long _timeout; |
| 12 | + bool _useStaticIp = false; |
| 13 | + CNetIf *ni; |
| 14 | + |
| 15 | +public: |
| 16 | + CWifi(); |
| 17 | + |
| 18 | + /* |
| 19 | + * Get firmware version |
| 20 | + */ |
| 21 | + static const char* firmwareVersion(); |
| 22 | + |
| 23 | + |
| 24 | + /* |
| 25 | + * Start WiFi connection for OPEN networks |
| 26 | + * param ssid: Pointer to the SSID string. |
| 27 | + */ |
| 28 | + int begin(const char* ssid); |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + /* Start WiFi connection with passphrase |
| 33 | + * the most secure supported mode will be automatically selected |
| 34 | + * |
| 35 | + * param ssid: Pointer to the SSID string. |
| 36 | + * param passphrase: Passphrase. Valid characters in a passphrase |
| 37 | + * must be between ASCII 32-126 (decimal). |
| 38 | + */ |
| 39 | + int begin(const char* ssid, const char *passphrase); |
| 40 | + |
| 41 | + /* connect as Access Point with a standard passphrase */ |
| 42 | + uint8_t beginAP(const char *ssid); |
| 43 | + uint8_t beginAP(const char *ssid, uint8_t channel); |
| 44 | + uint8_t beginAP(const char *ssid, const char* passphrase); |
| 45 | + uint8_t beginAP(const char *ssid, const char* passphrase, uint8_t channel); |
| 46 | + |
| 47 | + /* Change IP configuration settings disabling the DHCP client |
| 48 | + * |
| 49 | + * param local_ip: Static IP configuration |
| 50 | + */ |
| 51 | + void config(IPAddress local_ip); |
| 52 | + |
| 53 | + /* Change IP configuration settings disabling the DHCP client |
| 54 | + * |
| 55 | + * param local_ip: Static IP configuration |
| 56 | + * param dns_server: IP configuration for DNS server 1 |
| 57 | + */ |
| 58 | + void config(IPAddress local_ip, IPAddress dns_server); |
| 59 | + |
| 60 | + /* Change IP configuration settings disabling the DHCP client |
| 61 | + * |
| 62 | + * param local_ip: Static IP configuration |
| 63 | + * param dns_server: IP configuration for DNS server 1 |
| 64 | + * param gateway : Static gateway configuration |
| 65 | + */ |
| 66 | + void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway); |
| 67 | + |
| 68 | + /* Change IP configuration settings disabling the DHCP client |
| 69 | + * |
| 70 | + * param local_ip: Static IP configuration |
| 71 | + * param dns_server: IP configuration for DNS server 1 |
| 72 | + * param gateway: Static gateway configuration |
| 73 | + * param subnet: Static Subnet mask |
| 74 | + */ |
| 75 | + void config(IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet); |
| 76 | + |
| 77 | + /* Change DNS IP configuration |
| 78 | + * |
| 79 | + * param dns_server1: IP configuration for DNS server 1 |
| 80 | + */ |
| 81 | + void setDNS(IPAddress dns_server1); |
| 82 | + |
| 83 | + /* Change DNS IP configuration |
| 84 | + * |
| 85 | + * param dns_server1: IP configuration for DNS server 1 |
| 86 | + * param dns_server2: IP configuration for DNS server 2 |
| 87 | + * |
| 88 | + */ |
| 89 | + void setDNS(IPAddress dns_server1, IPAddress dns_server2); |
| 90 | + |
| 91 | + |
| 92 | + /* Set the hostname used for DHCP requests |
| 93 | + * |
| 94 | + * param name: hostname to set |
| 95 | + * |
| 96 | + */ |
| 97 | + void setHostname(const char* name); |
| 98 | + |
| 99 | + /* |
| 100 | + * Disconnect from the network |
| 101 | + * |
| 102 | + * return: one value of wl_status_t enum |
| 103 | + */ |
| 104 | + int disconnect(void); |
| 105 | + |
| 106 | + void end(void); |
| 107 | + |
| 108 | + /* |
| 109 | + * Get the interface MAC address. |
| 110 | + * |
| 111 | + * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH |
| 112 | + * |
| 113 | + * the value returned by this function is meaningfull only if called |
| 114 | + * afert a begin (both begin or beginAP) or a ScanNetwork function |
| 115 | + * otherwise an empty mac address is returned |
| 116 | + */ |
| 117 | + uint8_t* macAddress(uint8_t* mac); |
| 118 | + |
| 119 | + /* |
| 120 | + * Get the interface IP address. |
| 121 | + * |
| 122 | + * return: IP address value |
| 123 | + */ |
| 124 | + IPAddress localIP(); |
| 125 | + |
| 126 | + /* |
| 127 | + * Get the interface subnet mask address. |
| 128 | + * |
| 129 | + * return: subnet mask address value |
| 130 | + */ |
| 131 | + IPAddress subnetMask(); |
| 132 | + |
| 133 | + /* |
| 134 | + * Get the gateway IP address. |
| 135 | + * |
| 136 | + * return: gateway IP address value |
| 137 | + */ |
| 138 | + IPAddress gatewayIP(); |
| 139 | + |
| 140 | + /* |
| 141 | + * Get the DNS server IP address. |
| 142 | + * |
| 143 | + * return: DNS server IP address value |
| 144 | + */ |
| 145 | + IPAddress dnsIP(int n = 0); |
12 | 146 |
|
13 |
| -// Instantiate a global variable from CWifiStation calling it WiFi |
| 147 | + /* |
| 148 | + * Return the current SSID associated with the network |
| 149 | + * |
| 150 | + * return: ssid string |
| 151 | + */ |
| 152 | + const char* SSID(); |
| 153 | + |
| 154 | + /* |
| 155 | + * Return the current BSSID associated with the network. |
| 156 | + * It is the MAC address of the Access Point |
| 157 | + * |
| 158 | + * return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH |
| 159 | + */ |
| 160 | + uint8_t* BSSID(uint8_t* bssid); |
| 161 | + |
| 162 | + /* |
| 163 | + * Return the current RSSI/Received Signal Strength in dBm) |
| 164 | + * associated with the network |
| 165 | + * |
| 166 | + * return: signed value |
| 167 | + */ |
| 168 | + int32_t RSSI(); |
| 169 | + |
| 170 | + /* |
| 171 | + * Return the Encryption Type associated with the network |
| 172 | + * |
| 173 | + * return: one value of wl_enc_type enum |
| 174 | + */ |
| 175 | + uint8_t encryptionType(); |
| 176 | + |
| 177 | + /* |
| 178 | + * Start scan WiFi networks available |
| 179 | + * |
| 180 | + * return: Number of discovered networks |
| 181 | + */ |
| 182 | + int8_t scanNetworks(); |
| 183 | + |
| 184 | + /* |
| 185 | + * Return the SSID discovered during the network scan. |
| 186 | + * |
| 187 | + * param networkItem: specify from which network item want to get the information |
| 188 | + * |
| 189 | + * return: SSID string of the specified item on the networks scanned list |
| 190 | + */ |
| 191 | + const char* SSID(uint8_t networkItem); |
| 192 | + |
| 193 | + /* |
| 194 | + * Return the encryption type of the networks discovered during the scanNetworks |
| 195 | + * |
| 196 | + * param networkItem: specify from which network item want to get the information |
| 197 | + * |
| 198 | + * return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list |
| 199 | +
|
| 200 | + enum wl_enc_type : |
| 201 | + ENC_TYPE_WEP, |
| 202 | + ENC_TYPE_WPA, |
| 203 | + ENC_TYPE_WPA2, |
| 204 | + ENC_TYPE_WPA2_ENTERPRISE, |
| 205 | + ENC_TYPE_WPA3, |
| 206 | + ENC_TYPE_NONE, |
| 207 | + ENC_TYPE_AUTO, |
| 208 | +
|
| 209 | + ENC_TYPE_UNKNOWN = 255 |
| 210 | + |
| 211 | + */ |
| 212 | + uint8_t encryptionType(uint8_t networkItem); |
| 213 | + |
| 214 | + uint8_t* BSSID(uint8_t networkItem, uint8_t* bssid); |
| 215 | + uint8_t channel(uint8_t networkItem); |
| 216 | + |
| 217 | + /* |
| 218 | + * Return the RSSI of the networks discovered during the scanNetworks |
| 219 | + * |
| 220 | + * param networkItem: specify from which network item want to get the information |
| 221 | + * |
| 222 | + * return: signed value of RSSI of the specified item on the networks scanned list |
| 223 | + */ |
| 224 | + int32_t RSSI(uint8_t networkItem); |
| 225 | + |
| 226 | + /* |
| 227 | + * Return Connection status. |
| 228 | + * |
| 229 | + * return: one of the value defined in wl_status_t |
| 230 | + */ |
| 231 | + uint8_t status(); |
| 232 | + |
| 233 | + /* |
| 234 | + * Return The deauthentication reason code. |
| 235 | + * |
| 236 | + * return: the deauthentication reason code |
| 237 | + */ |
| 238 | + uint8_t reasonCode(); |
| 239 | + |
| 240 | + /* |
| 241 | + * Resolve the given hostname to an IP address. |
| 242 | + * param aHostname: Name to be resolved |
| 243 | + * param aResult: IPAddress structure to store the returned IP address |
| 244 | + * result: 1 if aIPAddrString was successfully converted to an IP address, |
| 245 | + * else error code |
| 246 | + */ |
| 247 | + int hostByName(const char* aHostname, IPAddress& aResult); |
| 248 | + |
| 249 | + unsigned long getTime(); |
| 250 | + |
| 251 | + void lowPowerMode(); |
| 252 | + void noLowPowerMode(); |
| 253 | + |
| 254 | + |
| 255 | + |
| 256 | + void setTimeout(unsigned long timeout); |
| 257 | + |
| 258 | + |
| 259 | +}; |
| 260 | + |
| 261 | +extern CWifi WiFi; |
| 262 | + |
| 263 | +#include "WiFiClient.h" |
| 264 | +#include "WiFiServer.h" |
| 265 | +#include "WiFiUdp.h" |
14 | 266 |
|
| 267 | +#endif |
0 commit comments