2017-09-27 17:59:49 -04:00
|
|
|
/*
|
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2017 "Eric Poulsen" <eric@zyxod.com>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
#ifndef MICROPY_INCLUDED_ESP32_MODNETWORK_H
|
|
|
|
#define MICROPY_INCLUDED_ESP32_MODNETWORK_H
|
|
|
|
|
2023-05-08 19:52:54 -04:00
|
|
|
#include "esp_netif.h"
|
2021-09-21 10:35:46 -04:00
|
|
|
|
2022-05-30 01:16:51 -04:00
|
|
|
enum { PHY_LAN8710, PHY_LAN8720, PHY_IP101, PHY_RTL8201, PHY_DP83848, PHY_KSZ8041, PHY_KSZ8081, PHY_KSZ8851SNL = 100, PHY_DM9051, PHY_W5500 };
|
2023-01-13 00:04:07 -05:00
|
|
|
#define IS_SPI_PHY(NUM) (NUM >= 100)
|
2021-04-18 15:38:36 -04:00
|
|
|
enum { ETH_INITIALIZED, ETH_STARTED, ETH_STOPPED, ETH_CONNECTED, ETH_DISCONNECTED, ETH_GOT_IP };
|
2017-09-27 17:59:49 -04:00
|
|
|
|
2021-09-21 10:35:46 -04:00
|
|
|
// Cases similar to ESP8266 user_interface.h
|
|
|
|
// Error cases are referenced from wifi_err_reason_t in ESP-IDF
|
|
|
|
enum {
|
|
|
|
STAT_IDLE = 1000,
|
|
|
|
STAT_CONNECTING = 1001,
|
|
|
|
STAT_GOT_IP = 1010,
|
|
|
|
};
|
|
|
|
|
2023-05-08 19:52:54 -04:00
|
|
|
typedef struct _base_if_obj_t {
|
2021-09-21 10:35:46 -04:00
|
|
|
mp_obj_base_t base;
|
2023-05-08 19:52:54 -04:00
|
|
|
esp_interface_t if_id;
|
|
|
|
esp_netif_t *netif;
|
2023-06-30 23:54:44 -04:00
|
|
|
volatile bool active;
|
2023-05-08 19:52:54 -04:00
|
|
|
} base_if_obj_t;
|
2021-09-21 10:35:46 -04:00
|
|
|
|
2023-05-10 21:51:02 -04:00
|
|
|
extern const mp_obj_type_t esp_network_wlan_type;
|
|
|
|
|
2023-01-31 22:20:45 -05:00
|
|
|
MP_DECLARE_CONST_FUN_OBJ_0(esp_network_initialize_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_get_wlan_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_KW(esp_network_get_lan_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_1(esp_network_ppp_make_new_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_ifconfig_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_KW(esp_network_config_obj);
|
|
|
|
MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(esp_network_phy_mode_obj);
|
2017-09-27 17:59:49 -04:00
|
|
|
|
2021-09-21 10:35:46 -04:00
|
|
|
NORETURN void esp_exceptions_helper(esp_err_t e);
|
|
|
|
|
|
|
|
static inline void esp_exceptions(esp_err_t e) {
|
|
|
|
if (e != ESP_OK) {
|
|
|
|
esp_exceptions_helper(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-18 00:49:57 -04:00
|
|
|
void socket_events_deinit(void);
|
esp32,esp8266: Add support for the Espressif ESP-NOW protocol.
ESP-NOW is a proprietary wireless communication protocol which supports
connectionless communication between ESP32 and ESP8266 devices, using
vendor specific WiFi frames. This commit adds support for this protocol
through a new `espnow` module.
This commit builds on original work done by @nickzoic, @shawwwn and with
contributions from @zoland. Features include:
- Use of (extended) ring buffers in py/ringbuf.[ch] for robust IO.
- Signal strength (RSSI) monitoring.
- Core support in `_espnow` C module, extended by `espnow.py` module.
- Asyncio support via `aioespnow.py` module (separate to this commit).
- Docs provided at `docs/library/espnow.rst`.
Methods available in espnow.ESPNow class are:
- active(True/False)
- config(): set rx buffer size, read timeout and tx rate
- recv()/irecv()/recvinto() to read incoming messages from peers
- send() to send messages to peer devices
- any() to test if a message is ready to read
- irq() to set callback for received messages
- stats() returns transfer stats:
(tx_pkts, tx_pkt_responses, tx_failures, rx_pkts, lost_rx_pkts)
- add_peer(mac, ...) registers a peer before sending messages
- get_peer(mac) returns peer info: (mac, lmk, channel, ifidx, encrypt)
- mod_peer(mac, ...) changes peer info parameters
- get_peers() returns all peer info tuples
- peers_table supports RSSI signal monitoring for received messages:
{peer1: [rssi, time_ms], peer2: [rssi, time_ms], ...}
ESP8266 is a pared down version of the ESP32 ESPNow support due to code
size restrictions and differences in the low-level API. See docs for
details.
Also included is a test suite in tests/multi_espnow. This tests basic
espnow data transfer, multiple transfers, various message sizes, encrypted
messages (pmk and lmk), and asyncio support.
Initial work is from https://github.com/micropython/micropython/pull/4115.
Initial import of code is from:
https://github.com/nickzoic/micropython/tree/espnow-4115.
2020-09-24 01:37:04 -04:00
|
|
|
void esp_initialise_wifi(void);
|
2018-04-27 09:53:45 -04:00
|
|
|
|
2017-09-27 17:59:49 -04:00
|
|
|
#endif
|