Mbed OS Reference
Loading...
Searching...
No Matches
ESP32Interface.h
1/* ESP32 implementation of NetworkInterfaceAPI
2 * Copyright (c) 2017 Renesas Electronics Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ESP32_INTERFACE_H
18#define ESP32_INTERFACE_H
19
20#include "ESP32Stack.h"
21
22/** ESP32Interface class
23 * Implementation of the NetworkStack for the ESP32
24 */
25class ESP32Interface : public ESP32Stack, public WiFiInterface {
26public:
27 /** ESP32Interface lifetime
28 * Configuration defined in mbed_lib.json
29 */
31
32 /** ESP32Interface lifetime
33 * @param en EN pin (If not used this pin, please set "NC")
34 * @param io0 IO0 pin (If not used this pin, please set "NC")
35 * @param tx TX pin
36 * @param rx RX pin
37 * @param debug Enable debugging
38 * @param rts RTS pin
39 * @param cts CTS pin
40 * @param baudrate The baudrate of the serial port (default = 230400).
41 */
42 ESP32Interface(PinName en, PinName io0, PinName tx, PinName rx, bool debug = false,
43 PinName rts = NC, PinName cts = NC, int baudrate = 230400);
44
45 /**
46 * @brief ESP32Interface default destructor
47 */
48 ~ESP32Interface() override;
49
50 /** ESP32Interface lifetime
51 * @param tx TX pin
52 * @param rx RX pin
53 * @param debug Enable debugging
54 */
55 ESP32Interface(PinName tx, PinName rx, bool debug = false);
56
58 const SocketAddress &ip_address, const SocketAddress &netmask,
59 const SocketAddress &gateway) override;
60
61 nsapi_error_t set_dhcp(bool dhcp) override;
62
63 int connect() override;
64
65 int connect(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE,
66 uint8_t channel = 0) override;
67
68 int set_credentials(const char *ssid, const char *pass, nsapi_security_t security = NSAPI_SECURITY_NONE) override;
69
70 int set_channel(uint8_t channel) override;
71
72 int disconnect() override;
73
75
76 const char *get_mac_address() override;
77
79
81
82 int8_t get_rssi() override;
83
84 int scan(WiFiAccessPoint *res, unsigned count) override;
85
87
89
90 void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb) override;
91
92 nsapi_connection_status_t get_connection_status() const override;
93
94 NetworkStack *get_stack() override
95 {
96 return this;
97 }
98
99private:
100
101 // HW reset pin
102 class ResetPin {
103 public:
104 ResetPin(PinName rst_pin);
105 void rst_assert();
106 void rst_deassert();
107 bool is_connected();
108 private:
109 mbed::DigitalOut _rst_pin;
110 } _rst_pin;
111
112 int _initialized;
113 bool _dhcp;
114 char _ap_ssid[33]; /* 32 is what 802.11 defines as longest possible name; +1 for the \0 */
115 char _ap_pass[64]; /* The longest allowed passphrase */
116 nsapi_security_t _ap_sec;
117 SocketAddress _ip_address;
118 SocketAddress _netmask;
119 SocketAddress _gateway;
120 nsapi_connection_status_t _connection_status;
121 mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
122
123 void set_connection_status(nsapi_connection_status_t connection_status);
124 void wifi_status_cb(int8_t wifi_status);
125 nsapi_error_t _init(void);
126 nsapi_error_t _reset(void);
127};
128
129#endif
ESP32Interface class Implementation of the NetworkStack for the ESP32.
const char * get_mac_address() override
Get the local MAC address.
nsapi_connection_status_t get_connection_status() const override
Get the connection status.
nsapi_error_t get_ip_address(SocketAddress *sockAddr) override
Get the local IP address.
nsapi_error_t get_gateway(SocketAddress *sockAddr) override
Get the local gateway.
ESP32Interface()
ESP32Interface lifetime Configuration defined in mbed_lib.json.
int set_credentials(const char *ssid, const char *pass, nsapi_security_t security=NSAPI_SECURITY_NONE) override
Set the Wi-Fi network credentials.
nsapi_error_t get_netmask(SocketAddress *sockAddr) override
Get the local network mask.
int connect(const char *ssid, const char *pass, nsapi_security_t security=NSAPI_SECURITY_NONE, uint8_t channel=0) override
Attempt to connect to a Wi-Fi network.
int8_t get_rssi() override
Get the current radio signal strength for active connection.
nsapi_error_t set_dhcp(bool dhcp) override
Enable or disable DHCP on connecting the network.
int connect() override
Attempt to connect to a Wi-Fi network.
ESP32Interface(PinName en, PinName io0, PinName tx, PinName rx, bool debug=false, PinName rts=NC, PinName cts=NC, int baudrate=230400)
ESP32Interface lifetime.
void attach(mbed::Callback< void(nsapi_event_t, intptr_t)> status_cb) override
Register callback for status reporting.
~ESP32Interface() override
ESP32Interface default destructor.
nsapi_error_t set_network(const SocketAddress &ip_address, const SocketAddress &netmask, const SocketAddress &gateway) override
Configure this network interface to use a static IP address.
ESP32Interface(PinName tx, PinName rx, bool debug=false)
ESP32Interface lifetime.
int disconnect() override
Stop the interface.
int set_channel(uint8_t channel) override
Set the Wi-Fi network channel.
ESP32Stack class Implementation of the NetworkStack for the ESP32.
Definition ESP32Stack.h:31
virtual nsapi_error_t add_dns_server(const SocketAddress &address, const char *interface_name)
Add a domain name server to list of servers to query.
virtual nsapi_error_t gethostbyname(const char *host, SocketAddress *address, nsapi_version_t version=NSAPI_UNSPEC, const char *interface_name=NULL)
Translate a hostname to an IP address with specific version using network interface name.
NetworkStack class.
Representation of an IP (v4 or v6) address and port pair.
WiFiAccessPoint class.
Common interface between Wi-Fi devices.
Callback class based on template specialization.
Definition Callback.h:53
A digital output, used for setting the state of a pin.
Definition DigitalOut.h:55
enum nsapi_security nsapi_security_t
Enum of encryption types.
signed int nsapi_error_t
Type used to represent error codes.
@ NSAPI_SECURITY_NONE