For example, instrumenting this method which writes data:
""" Write bytes to the serial port while performing SLIP escaping """
def write(self, packet):
buf = '\xc0' \
+ (packet.replace('\xdb','\xdb\xdd').replace('\xc0','\xdb\xdc')) \
+ '\xc0'
### ADD LOGGING OF BUF HERE
self._port.write(buf)
to log what buf actually consists of.
And this one which receives data:
""" Receive a response to a command """
def receive_response(self):
# Read header of response and parse
if self._port.read(1) != '\xc0':
raise FatalError('Invalid head of packet')
hdr = self.read(8)
(resp, op_ret, len_ret, val) = struct.unpack('<BBHI', hdr)
if resp != 0x01:
raise FatalError('Invalid response 0x%02x" to command' % resp)
# The variable-length body
body = self.read(len_ret)
# Terminating byte
if self._port.read(1) != chr(0xc0):
raise FatalError('Invalid end of packet')
### LOG RECEIVED DATA HERE
return op_ret, val, body
Oh, and esptool.py's github repo has some documentation on the serial protocol.
esp8266 otb-iot documentation - https://otb-iot.readthedocs.io/
esp8266 related blog - http://www.packom.net/