Skip to content

Commit ddd26eb

Browse files
authored
Merge pull request #161 from anecdata/getRemoteData
New function get_remote_data() to expose NINA getRemoteData()
2 parents b11cf2a + 5c58a8d commit ddd26eb

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

adafruit_esp32spi/adafruit_esp32spi.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import struct
3030
import time
3131
from micropython import const
32-
from digitalio import Direction
3332
from adafruit_bus_device.spi_device import SPIDevice
33+
from digitalio import Direction
3434

3535
__version__ = "0.0.0-auto.0"
3636
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI.git"
@@ -70,6 +70,7 @@
7070
_START_SCAN_NETWORKS = const(0x36)
7171
_GET_FW_VERSION_CMD = const(0x37)
7272
_SEND_UDP_DATA_CMD = const(0x39)
73+
_GET_REMOTE_DATA_CMD = const(0x3A)
7374
_GET_TIME = const(0x3B)
7475
_GET_IDX_BSSID_CMD = const(0x3C)
7576
_GET_IDX_CHAN_CMD = const(0x3D)
@@ -127,6 +128,8 @@
127128
ADC_ATTEN_DB_6 = const(2)
128129
ADC_ATTEN_DB_11 = const(3)
129130

131+
# pylint: disable=too-many-lines
132+
130133

131134
class ESP_SPIcontrol: # pylint: disable=too-many-public-methods, too-many-instance-attributes
132135
"""A class that will talk to an ESP32 module programmed with special firmware
@@ -847,6 +850,14 @@ def server_state(self, socket_num):
847850
resp = self._send_command_get_response(_GET_STATE_TCP_CMD, self._socknum_ll)
848851
return resp[0][0]
849852

853+
def get_remote_data(self, socket_num):
854+
"""Get the IP address and port of the remote host"""
855+
self._socknum_ll[0][0] = socket_num
856+
resp = self._send_command_get_response(
857+
_GET_REMOTE_DATA_CMD, self._socknum_ll, reply_params=2
858+
)
859+
return {"ip_addr": resp[0], "port": struct.unpack("<H", resp[1])[0]}
860+
850861
def set_esp_debug(self, enabled):
851862
"""Enable/disable debug mode on the ESP32. Debug messages will be
852863
written to the ESP32's UART."""

0 commit comments

Comments
 (0)