uPing - Ping library for MicroPython

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: uPing - Ping library for MicroPython

Post by Roberthh » Fri Nov 15, 2019 7:04 am

Please update your firmware to the daily build. Then, SOCK_RAW should be working.

uxhamby
Posts: 34
Joined: Thu Nov 14, 2019 9:47 pm

Re: uPing - Ping library for MicroPython

Post by uxhamby » Mon Nov 18, 2019 10:17 pm

Please update your firmware to the daily build. Then, SOCK_RAW should be working.
Nice! Thanks.

User avatar
ebolisa
Posts: 55
Joined: Thu Feb 21, 2019 11:43 am
Location: Madrid, Spain

Re: uPing - Ping library for MicroPython

Post by ebolisa » Fri Sep 10, 2021 5:43 am

It fails on nano rp2040 connect with:

Code: Select all

network config: ('192.168.1.230', '255.255.255.0', '192.168.1.1', '192.168.1.1')

Traceback (most recent call last):
  File "<stdin>", line 126, in <module>
  File "<stdin>", line 66, in ping
OSError: [Errno 128] ENOTCONN

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: uPing - Ping library for MicroPython

Post by Roberthh » Fri Sep 10, 2021 6:26 pm

Did you connect to your AP before calling uping()?
Does the nano connect respond to ping?
Is uping the only code that fails?
And does it fail on every address?
Does the following small udptest code work? The connected server returns a message with an aphorism.

Code: Select all

import socket
UDP_IP = "68.228.188.226"
UDP_PORT = 17
MESSAGE = b' '
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.settimeout(5)
def run():
    print(s.sendto(MESSAGE, (UDP_IP, UDP_PORT)))

    data, address = s.recvfrom(1024)
    print(data.decode())

run()

User avatar
Wind-stormger
Posts: 17
Joined: Fri Nov 05, 2021 6:59 am

Re: uPing - Ping library for MicroPython

Post by Wind-stormger » Thu May 12, 2022 6:24 am

When uping today on an esp32s2 with the latest nightly build firmware:

Code: Select all

>>> import uping
>>> uping.ping(host='192.168.11.143', count=50, timeout=5000, interval=10, quiet=False, size=64)
PING 192.168.11.143 (192.168.11.143): 64 data bytes
50 packets transmitted, 0 packets received
(50, 0)
0 packets received

——————————————————————————

I may have found that the reason is the problem of the IP device. Restart it to solve the problem.
Last edited by Wind-stormger on Thu May 12, 2022 7:41 am, edited 1 time in total.

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: uPing - Ping library for MicroPython

Post by Roberthh » Thu May 12, 2022 7:09 am

Just look into the python code of uping,py. This is straight code, where the print() statement definitely do not depend on a version.

User avatar
Wind-stormger
Posts: 17
Joined: Fri Nov 05, 2021 6:59 am

Re: uPing - Ping library for MicroPython

Post by Wind-stormger » Thu May 12, 2022 8:32 am

Roberthh wrote:
Thu May 12, 2022 7:09 am
Just look into the python code of uping,py. This is straight code, where the print() statement definitely do not depend on a version.
Thanks.

By the way,recently merged features are helpful in improving wifi stability. https://github.com/micropython/micropython/pull/8518

Code: Select all

import network
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.config(txpower=8.5)  #set to 8.5dBm
print(sta_if.config("txpower"))  # txpower=8.5dBm
Reducing power helps improve stability,especially some boards that use PCB onboard antennas.

fishjoe
Posts: 7
Joined: Wed Aug 24, 2022 9:25 am
Location: Chrischurch

Re: uPing - Ping library for MicroPython

Post by fishjoe » Sat Oct 15, 2022 4:56 am

Is this the correct way to catch the result???

Code: Select all

results = []
for result in uping.ping('google.com'):
	results.append(result)
if results[1] != 0:
	print(f"\n\nUping successfull, returned {results[1]} of {results[0]} packets sent.") # or do_something()
else:
	print(f"\n\nUping UNSUCCESSFULL, cannot reach target.") # or do_something()

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: uPing - Ping library for MicroPython

Post by Roberthh » Sat Oct 15, 2022 6:35 am

Hardly. The returned value is a tuple. So not need to append. You can directly index into it.

Code: Select all

result = uping.ping('google.com', quiet=True)
if result[1] != 0:
	print(f"\n\nUping successfull, returned {result[1]} of {result[0]} packets sent.") # or do_something()
else:
	print(f"\n\nUping UNSUCCESSFULL, cannot reach target.") # or do_something()
I added the quiet=True argument to suppress the interim debug messages.

fishjoe
Posts: 7
Joined: Wed Aug 24, 2022 9:25 am
Location: Chrischurch

Re: uPing - Ping library for MicroPython

Post by fishjoe » Sat Oct 15, 2022 11:53 pm

This is why this forum is helpful. Many thanks.

Post Reply