@@ -22,6 +22,7 @@ class ESP_SPIcontrol:
22
22
REQ_HOST_BY_NAME_CMD = const (0x34 )
23
23
GET_HOST_BY_NAME_CMD = const (0x35 )
24
24
START_SCAN_NETWORKS = const (0x36 )
25
+ PING_CMD = const (0x3E )
25
26
26
27
GET_FW_VERSION_CMD = const (0x37 )
27
28
@@ -54,7 +55,6 @@ def __init__(self, spi, cs_pin, ready_pin, reset_pin, gpio0_pin, *, debug=False)
54
55
self ._reset .direction = Direction .OUTPUT
55
56
self ._gpio0 .direction = Direction .OUTPUT
56
57
57
- print ("Nina reset" )
58
58
self ._gpio0 .value = True # not bootload mode
59
59
self ._cs .value = True
60
60
self ._reset .value = False
@@ -278,9 +278,17 @@ def pretty_ip(self, ip):
278
278
def get_host_by_name (self , hostname ):
279
279
if isinstance (hostname , str ):
280
280
hostname = bytes (hostname , 'utf-8' )
281
- self ._debug = True
282
281
resp = self .send_command_get_response (REQ_HOST_BY_NAME_CMD , [hostname ])
283
282
if resp [0 ][0 ] != 1 :
284
283
raise RuntimeError ("Failed to request hostname" )
285
284
resp = self .send_command_get_response (GET_HOST_BY_NAME_CMD )
286
285
return resp [0 ]
286
+
287
+ def ping (self , dest , ttl = 250 ):
288
+ self ._debug = True
289
+ if isinstance (dest , str ): # convert to IP address
290
+ dest = self .get_host_by_name (dest )
291
+ # ttl must be between 0 and 255
292
+ ttl = max (0 , min (ttl , 255 ))
293
+ resp = self .send_command_get_response (PING_CMD , [dest , [ttl ]])
294
+ return struct .unpack ('<H' , resp [0 ])[0 ]
0 commit comments