-
Notifications
You must be signed in to change notification settings - Fork 74
Adding to the functionality of the ESP32 library in order to provide … #69
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2990061
f577e93
eb80804
32fb05f
5b88086
ad976f4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,7 @@ | |
_GET_HOST_BY_NAME_CMD = const(0x35) | ||
_START_SCAN_NETWORKS = const(0x36) | ||
_GET_FW_VERSION_CMD = const(0x37) | ||
_GET_REMOTE_DATA_CMD = const(0x3A) | ||
_GET_TIME = const(0x3B) | ||
_PING_CMD = const(0x3E) | ||
|
||
|
@@ -768,3 +769,12 @@ def get_time(self): | |
resp = self._send_command_get_response(_GET_TIME) | ||
return struct.unpack('<i', resp[0]) | ||
raise RuntimeError("Must be connected to WiFi before obtaining NTP.") | ||
|
||
def get_remote_data(self, socket_num): | ||
""" | ||
Method to obtain remote IP | ||
""" | ||
self._socknum_ll[0][0] = socket_num | ||
resp = self._send_command_get_response(_GET_REMOTE_DATA_CMD, | ||
self._socknum_ll, reply_params=2) | ||
return resp[0] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the instead of just returning the IP, I would return both. something like
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. File "/lib/adafruit_esp32spi/adafruit_esp32spi.py", line 550, in pretty_ip There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So by changing the return type an dictionary object means that when you call this method you will need to do an additional step to get the ip whenever you call this method. Dictionary objects have a method on it called Example:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,6 +102,7 @@ def update_poll(self): | |
result = self.application(environ, self._start_response) | ||
self.finish_response(result) | ||
|
||
|
||
def finish_response(self, result): | ||
""" | ||
Called after the application callbile returns result data to respond with. | ||
|
@@ -216,3 +217,11 @@ def _get_environ(self, client): | |
env[key] = value | ||
|
||
return env | ||
|
||
def check_remote_ip(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would move this to the then every socket instance could get the remote_ip by doing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. agreed! socket would be the correct home for this method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we move the remote ip fetching to a property on it would look something like
The environment object gets passed to the application on every single incoming request, so all your request handlers would just automatically get the remote IP and can use it for processing if they need it. |
||
""" | ||
Functionality to control what IP is connecting to the server. | ||
""" | ||
sock_num = self._client_sock.socknum | ||
remote_ip = _the_interface.get_remote_data(sock_num) | ||
return _the_interface.pretty_ip(remote_ip) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please document the argument,
socket_num
, using a docstring (see here :https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/blob/master/adafruit_esp32spi/adafruit_esp32spi.py#L514)