Skip to content
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

Add command Ping (#7176) #8119

Merged
merged 2 commits into from
Apr 10, 2020
Merged

Add command Ping (#7176) #8119

merged 2 commits into from
Apr 10, 2020

Conversation

s-hadinger
Copy link
Collaborator

Description:

Add Ping<x> <addr> where <x> is the number of packets to send (at 1 second interval) and <addr> the address either as domain name or IPv4 address.

The answer is asynchronous when all packets have been sent and responses handled (success or time-outs).

As ICMP ping code from Arduino takes more than 2KB of Flash, Ping will most certainly not be included by default. You will need to self compile and set #define USE_PING

Ex:

Ping4 192.168.1.203
20:43:59 CMD: Ping4 192.168.1.203
20:43:59 RSL: stat/tasmota_xxx/RESULT = {"Ping":"Done"}
20:44:04 RSL: tele/tasmota_xxx/RESULT = {"Ping":{"192.168.1.203":{"Reachable":true,"Success":4,"Timeout":0,"MinTime":59,"MaxTime":167,"AvgTime":116}}}

Ping4 templates.blakadder.com
20:45:36 CMD: Ping4 templates.blakadder.com
20:45:36 RSL: stat/tasmota_xxx/RESULT = {"Ping":"Done"}
20:45:40 RSL: tele/tasmota_xxx/RESULT = {"Ping":{"185.199.110.153":{"Reachable":true,"Success":4,"Timeout":0,"MinTime":15,"MaxTime":591,"AvgTime":182}}}

Related issue (if applicable): fixes #7176

Checklist:

  • The pull request is done against the latest dev branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR.
  • The code change is tested and works on core Tasmota_core_stage
  • The code change pass travis tests. Your PR cannot be merged unless tests pass
  • I accept the CLA.

@MarkCiliaVincenti
Copy link

Many thanks for this! I'm just a bit confused on what I need to do to create a .bin file that includes the sensors and ping. Or maybe it could be included in the sensors bin considering it is intended to be used as a presence sensor?

@ascillato
Copy link
Contributor

Please, address this to the Tasmota Support Chat. The chat is a better and more dynamic channel for helping you. Github issues are meant for Tasmota Software Bug Reporting.

Please check the Contributing Guideline and Policy and the Support Guide.

Thanks.


Support Information

See Wiki for more information.
See FAQ for common questions/answers and links if none of your question is in the list
See Chat for more user experience.
See Community for forum.
See Code of Conduct

@s-hadinger s-hadinger deleted the ping branch April 11, 2020 08:26
@s-hadinger
Copy link
Collaborator Author

We need Theo's approval to include in the tasmota-sensors distribution.

@arendst what's your opinion?

@arendst
Copy link
Owner

arendst commented Apr 11, 2020

Wouldn't grow too large? With the current, not code size optimized sensor influx it starts to reach the max size very soon.

@MarkCiliaVincenti
Copy link

Can we have option to set the timeout and the buffer size please @s-hadinger? I'm trying this and I'm able to successfully ping all devices on Ethernet, but most devices on WiFi are timing out. I'd like to be able to configure the timeout especially.

@MarkCiliaVincenti
Copy link

I made a few tests and the results are very strange to me. Some devices are being marked as reachable while others are not. From my laptop I can ping all of them. And it's not a timeout issue; I connected my laptop with Ethernet and I still can't ping it, but I CAN ping a WiFi device. Also, I'm getting unreachable when trying to get it to ping itself. I can ping the Sonoff from my laptop, but it can't ping itself?

@MarkCiliaVincenti
Copy link

Apologies, some of the strange results have to do with issues I was having with my main router. Yet, the problem with being unable to ping oneself and to set a timeout still persist.

Also, may I please suggest a change in the JSON formatting which would make it easier to deserialize to a class instance?

Can:
{"Ping":{"192.168.0.1":{"Reachable":true,"Success":6,"Timeout":0,"MinTime":3,"MaxTime":7,"AvgTime":4}}}

Change to:
{"Ping":{"Address":"192.168.0.1"."Reachable":true,"Success":6,"Timeout":0,"MinTime":3,"MaxTime":7,"AvgTime":4}}

@s-hadinger
Copy link
Collaborator Author

s-hadinger commented Apr 11, 2020

Indeed a Tasmota device cannot ping itself, I'm not sure why but it's maybe because when it's sending an ICMP packet, it can't receive it at the same time.

I don't know why some of your device are not reachable, maybe an ARP issue at router or AP level. Can you see with WireShark what is happening at wifi level? Also see #8092

The JSON format is aligned with sensors and zigbee. Actually it has some benefits to have a distinct json tree structure per device, for ex when using AWS IoT and device shadows.

@s-hadinger
Copy link
Collaborator Author

s-hadinger commented Apr 12, 2020

I confirm there is a problem when I try to ping multiple devices at the same time. Most packets end up with time-outs. Either they are not sent at all, or the responses are ignored. I will need to look deeper.

Advice: send pings once at a time.

Edit: I tied to increase time-out to 2 seconds and it won't change anything.

Actually I'm considering now forcing pings one at a time, and refuse to send more ping if one ping in on-going. Actually it simplifies code to do so. What do you think? @MarkCiliaVincenti

@s-hadinger
Copy link
Collaborator Author

More tests, they show without any doubt that the ping feature in LWIP2 is no re-entrant. It will only accept pings one at a time, and ignore previous responses. That's why the first 3 pings succeed only once and the last one succeeds on all 4 packets.

Backlog Ping4 192.168.1.203; Ping4 192.168.1.205; Ping4 192.168.1.207; Ping4 192.168.1.208

10:29:28 CMD: Backlog Ping4 192.168.1.203; Ping4 192.168.1.205; Ping4 192.168.1.207; Ping4 192.168.1.208
10:29:28 MQT: stat/tasmota/Zigbee_home/RESULT = {"Ping":"Done"}
10:29:28 MQT: stat/tasmota/Zigbee_home/RESULT = {"Ping":"Done"}
10:29:28 MQT: stat/tasmota/Zigbee_home/RESULT = {"Ping":"Done"}
10:29:29 MQT: stat/tasmota/Zigbee_home/RESULT = {"Ping":"Done"}
10:29:32 MQT: tele/tasmota/Zigbee_home/RESULT = {"Ping":{"192.168.1.203":{"Reachable":true,"Success":1,"Timeout":3,"MinTime":129,"MaxTime":129,"AvgTime":129}}}
10:29:32 MQT: tele/tasmota/Zigbee_home/RESULT = {"Ping":{"192.168.1.205":{"Reachable":true,"Success":1,"Timeout":3,"MinTime":142,"MaxTime":142,"AvgTime":142}}}
10:29:32 MQT: tele/tasmota/Zigbee_home/RESULT = {"Ping":{"192.168.1.207":{"Reachable":true,"Success":1,"Timeout":3,"MinTime":137,"MaxTime":137,"AvgTime":137}}}
10:29:33 MQT: tele/tasmota/Zigbee_home/RESULT = {"Ping":{"192.168.1.208":{"Reachable":true,"Success":4,"Timeout":0,"MinTime":4,"MaxTime":899,"AvgTime":1465}}}

There also seem to be a bug in AvgTime calulation: "MinTime":4,"MaxTime":899,"AvgTime":1465

@MarkCiliaVincenti
Copy link

MarkCiliaVincenti commented Apr 12, 2020

To be honest, I'm only interested in the value of 'Reachable'. In fact, ideally for me it would stop pinging upon the first successful response, so a more timely result is achieved. But I understand others may want to use the response times.

That said, I'm working with this feature now :)

@s-hadinger
Copy link
Collaborator Author

I understand, but with the current Ping api from LWIP2, you can't stop pings once they started.

I will change the code to make sure 2 pings don't collide.

@s-hadinger
Copy link
Collaborator Author

@MarkCiliaVincenti I revamped the Ping engine and simplified it. Now you can send multiple pings at the same time.

Also I implemented Ping0 to test reachability only. It will stop once it receives a response, and will try 4 times. See #8193

@MarkCiliaVincenti
Copy link

You're the king @s-hadinger! Cheers for this!

@mrneutron42
Copy link

mrneutron42 commented Feb 7, 2022

It's been 2 years since the last post here.
I wonder if there are now any downloadable Tasmota firmware files that have the ping command included?
I've tried the ping4 8.8.8.8 command in the console of the regular and sensors version of tasmota 10.1.0 and both come back with:
"{"Command":"Unknown"}"

@barbudor
Copy link
Contributor

barbudor commented Feb 7, 2022

@mrneutron42
Documention is clear about that:
image

If you want it you need to compile your own build

Or use tasmota-platinum from the unoffical builds

@mrneutron42
Copy link

Yes, I saw the custom-compile note in the first post of this thread.
I've not yet done a custom-compile of tasmota.

I did not know about the tasmota platinum builds.
Thanks for the link to those.
I'll give them a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature Request. Ping command
6 participants