From 87095f617e7c93d624105e26f2742543a272b35d Mon Sep 17 00:00:00 2001 From: mytechnotalent Date: Wed, 21 Aug 2019 07:03:15 -0400 Subject: [PATCH 1/5] Fixed MAC reverse byte order issue within the ESP32SPI library as it was originally echoing the MAC address in reverse byte order. Added portable MAC function call within WSGISERVER.PY example to properly echo MAC address when running example. --- adafruit_esp32spi/adafruit_esp32spi.py | 6 ++++-- examples/server/esp32spi_wsgiserver.py | 4 +++- 2 files changed, 7 insertions(+), 3 deletions(-) mode change 100644 => 100755 adafruit_esp32spi/adafruit_esp32spi.py mode change 100644 => 100755 examples/server/esp32spi_wsgiserver.py diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py old mode 100644 new mode 100755 index 3e16df0..c5ac732 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -337,7 +337,9 @@ def MAC_address(self): # pylint: disable=invalid-name if self._debug: print("MAC address") resp = self._send_command_get_response(_GET_MACADDR_CMD, [b'\xFF']) - return resp[0] + new_resp = bytearray(resp[0]) + new_resp = reversed(new_resp) + return new_resp def start_scan_networks(self): """Begin a scan of visible access points. Follow up with a call @@ -759,4 +761,4 @@ def set_analog_write(self, pin, analog_value): resp = self._send_command_get_response(_SET_ANALOG_WRITE_CMD, ((pin,), (value,))) if resp[0][0] != 1: - raise RuntimeError("Failed to write to pin") + raise RuntimeError("Failed to write to pin") \ No newline at end of file diff --git a/examples/server/esp32spi_wsgiserver.py b/examples/server/esp32spi_wsgiserver.py old mode 100644 new mode 100755 index a247c77..2e2e842 --- a/examples/server/esp32spi_wsgiserver.py +++ b/examples/server/esp32spi_wsgiserver.py @@ -39,6 +39,8 @@ spi = busio.SPI(board.SCK, board.MOSI, board.MISO) esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) # pylint: disable=line-too-long +print("MAC addr:", [hex(i) for i in esp.MAC_address]) + """Use below for Most Boards""" status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards """Uncomment below for ItsyBitsy M4""" @@ -212,4 +214,4 @@ def led_color(environ): # pylint: disable=unused-argument except (ValueError, RuntimeError) as e: print("Failed to update server, restarting ESP32\n", e) wifi.reset() - continue + continue \ No newline at end of file From ec97d6b0680976429351fd3377ec520d1d913555 Mon Sep 17 00:00:00 2001 From: mytechnotalent Date: Wed, 21 Aug 2019 07:30:07 -0400 Subject: [PATCH 2/5] Fixedblank line issus at EOF so Travis can run. --- adafruit_esp32spi/adafruit_esp32spi.py | 3 ++- examples/server/esp32spi_wsgiserver.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py index c5ac732..6841e91 100755 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -761,4 +761,5 @@ def set_analog_write(self, pin, analog_value): resp = self._send_command_get_response(_SET_ANALOG_WRITE_CMD, ((pin,), (value,))) if resp[0][0] != 1: - raise RuntimeError("Failed to write to pin") \ No newline at end of file + raise RuntimeError("Failed to write to pin") + \ No newline at end of file diff --git a/examples/server/esp32spi_wsgiserver.py b/examples/server/esp32spi_wsgiserver.py index 2e2e842..fb1cd06 100755 --- a/examples/server/esp32spi_wsgiserver.py +++ b/examples/server/esp32spi_wsgiserver.py @@ -214,4 +214,5 @@ def led_color(environ): # pylint: disable=unused-argument except (ValueError, RuntimeError) as e: print("Failed to update server, restarting ESP32\n", e) wifi.reset() - continue \ No newline at end of file + continue + \ No newline at end of file From 3fd6a12118a512624126d223cac86fa5084a625e Mon Sep 17 00:00:00 2001 From: mytechnotalent Date: Thu, 22 Aug 2019 04:46:51 -0400 Subject: [PATCH 3/5] Fixed MAC reverse byte order by adding new function to the ESP32SPI library calling the actual MAC address and providing a usage of the function in the webserver code within WSGISERVER. --- adafruit_esp32spi/adafruit_esp32spi.py | 11 +++++++++-- examples/server/esp32spi_wsgiserver.py | 4 ++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py index 6841e91..c5c86e8 100755 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -333,6 +333,14 @@ def firmware_version(self): @property def MAC_address(self): # pylint: disable=invalid-name + """A bytearray containing the MAC address of the ESP32""" + if self._debug: + print("MAC address") + resp = self._send_command_get_response(_GET_MACADDR_CMD, [b'\xFF']) + return resp[0] + + @property + def MAC_address_actual(self): # pylint: disable=invalid-name """A bytearray containing the MAC address of the ESP32""" if self._debug: print("MAC address") @@ -761,5 +769,4 @@ def set_analog_write(self, pin, analog_value): resp = self._send_command_get_response(_SET_ANALOG_WRITE_CMD, ((pin,), (value,))) if resp[0][0] != 1: - raise RuntimeError("Failed to write to pin") - \ No newline at end of file + raise RuntimeError("Failed to write to pin") \ No newline at end of file diff --git a/examples/server/esp32spi_wsgiserver.py b/examples/server/esp32spi_wsgiserver.py index fb1cd06..e055ba3 100755 --- a/examples/server/esp32spi_wsgiserver.py +++ b/examples/server/esp32spi_wsgiserver.py @@ -40,6 +40,7 @@ esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset) # pylint: disable=line-too-long print("MAC addr:", [hex(i) for i in esp.MAC_address]) +print("MAC addr actual:", [hex(i) for i in esp.MAC_address_actual]) """Use below for Most Boards""" status_light = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2) # Uncomment for Most Boards @@ -214,5 +215,4 @@ def led_color(environ): # pylint: disable=unused-argument except (ValueError, RuntimeError) as e: print("Failed to update server, restarting ESP32\n", e) wifi.reset() - continue - \ No newline at end of file + continue \ No newline at end of file From da9f67fef2d31edcaa38aba6426519fd835db679 Mon Sep 17 00:00:00 2001 From: mytechnotalent Date: Thu, 22 Aug 2019 04:49:36 -0400 Subject: [PATCH 4/5] Fixed MAC reverse byte order by adding new function to the ESP32SPI library calling the actual MAC address and providing a usage of the function in the webserver code within WSGISERVER. This time with line breaks at end to not break Travis. --- adafruit_esp32spi/adafruit_esp32spi.py | 3 ++- examples/server/esp32spi_wsgiserver.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py index c5c86e8..35fcf27 100755 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -769,4 +769,5 @@ def set_analog_write(self, pin, analog_value): resp = self._send_command_get_response(_SET_ANALOG_WRITE_CMD, ((pin,), (value,))) if resp[0][0] != 1: - raise RuntimeError("Failed to write to pin") \ No newline at end of file + raise RuntimeError("Failed to write to pin") + \ No newline at end of file diff --git a/examples/server/esp32spi_wsgiserver.py b/examples/server/esp32spi_wsgiserver.py index e055ba3..0f7fcdb 100755 --- a/examples/server/esp32spi_wsgiserver.py +++ b/examples/server/esp32spi_wsgiserver.py @@ -215,4 +215,5 @@ def led_color(environ): # pylint: disable=unused-argument except (ValueError, RuntimeError) as e: print("Failed to update server, restarting ESP32\n", e) wifi.reset() - continue \ No newline at end of file + continue + \ No newline at end of file From 00b6b952d4b4784dc4b1ded7cf013a1e8b99423e Mon Sep 17 00:00:00 2001 From: mytechnotalent Date: Thu, 22 Aug 2019 04:56:09 -0400 Subject: [PATCH 5/5] Updated comment for new function. --- adafruit_esp32spi/adafruit_esp32spi.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adafruit_esp32spi/adafruit_esp32spi.py b/adafruit_esp32spi/adafruit_esp32spi.py index 35fcf27..4d0d389 100755 --- a/adafruit_esp32spi/adafruit_esp32spi.py +++ b/adafruit_esp32spi/adafruit_esp32spi.py @@ -341,7 +341,7 @@ def MAC_address(self): # pylint: disable=invalid-name @property def MAC_address_actual(self): # pylint: disable=invalid-name - """A bytearray containing the MAC address of the ESP32""" + """A bytearray containing the actual MAC address of the ESP32""" if self._debug: print("MAC address") resp = self._send_command_get_response(_GET_MACADDR_CMD, [b'\xFF']) @@ -770,4 +770,3 @@ def set_analog_write(self, pin, analog_value): ((pin,), (value,))) if resp[0][0] != 1: raise RuntimeError("Failed to write to pin") - \ No newline at end of file