ESP8266.ping does not work as expected

Posted on
  • Hi All,
    I'm simply trying to send a ping request to my router with ESP8266.ping function, my callback gets called but the result is always negative as if my router is not alive but it is. I have the latest nodeMCU board with espruino 1v85. Any idea?

    The code I'm running :

    var ESP8266=require("ESP8266");
    
    ESP8266.ping("192.168.1.1", function(e){
    
      console.log(e);
    
    });
    

    and the result :

    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0, 
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    
  • Have you connect to wifi first? What ip address did you get?

  • yes I'm connected to wifi see the require("Wifi").getIP() result below. I'm able to ping to my board from my PC but not the other way around.

    { "ip": "192.168.1.29", "netmask": "255.255.255.0", "gw": "192.168.1.1", "mac": "5c:cf:7f:80:0c:86"
     }
    
  • I'm using 1v85.tve_master_124390c Copyright 2016 G.Williams with the 1.5.4 SDK, on a NodeMCU board.

    I'm getting the same behaviour.

    I wonder if this is related to the router model?

  • running on ESP8266-12E
    mem:{"free":1557,"usage":143,"total":170­0,"history":22}
    version:1v85.MaBe_master_d1aeb8f
    git_commit:d1aeb8f9f8f692e1c987597624137­b546173c08d

    tested with .1 (router) and .52 (mac book) - so this works fine for my configuration

    
    >var ESP8266=require("ESP8266");
    =function () { [native code] }
    >
    =undefined
    >var Wifi = require("Wifi")
    =function () { [native code] }
    >Wifi.getIP();
    ={
      "ip": "192.168.194.64",
      "netmask": "255.255.255.0",
      "gw": "192.168.194.1",
      "mac": "5c:cf:7f:05:c1:00"
     }
    >
    =undefined
    >ESP8266.setLog(2);
    =undefined
    >ESP8266.ping("192.168.194.1", function(e){ console.log(e);});
    =undefined
    >456182> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 6,
      "seqNo": 56, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >457274> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 57, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >458425> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 58, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >459499> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 59, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >460602> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 4,
      "seqNo": 60, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >461723> ping 5, timeout 0, total payload 160 bytes, 5547 ms
    
    ESP8266.ping("192.168.194.52", function(e){ console.log(e);});
    =undefined
    >750842> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2,
      "seqNo": 61, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >751924> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 62, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >753100> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 63, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >754175> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 64, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >755300> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2,
      "seqNo": 65, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >756423> ping 5, timeout 0, total payload 160 bytes, 5582 ms
     
    
  • The following is my output. It still does not work despite the fact that I'm connected to different router right now. Obviously there is bug somewhere, which is very discouraging

    >var ESP8266=require("ESP8266");
    =function () { [native code] }
    >var Wifi = require("Wifi")
    =function () { [native code] }
    >Wifi.getIP();
    ={
      "ip": "192.168.2.203",
      "netmask": "255.255.255.0",
      "gw": "192.168.2.1",
      "mac": "5c:cf:7f:80:0c:86"
     }
    >ESP8266.setLog(2);
    =undefined
    > 60000> Thu Jan 01 00:01:00 1970, heap: 10600
    ESP8266.ping("192.168.2.1", function(e){ console.log(e);});
    =undefined
    >111956> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0,
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    >113081> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0,
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    >114256> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0,
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    >115406> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0,
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    >116531> Received a ping response!
    116532> ping 5, timeout 5, total payload 0 bytes, 5703 ms 
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 0,
      "seqNo": 0, "timeoutCount": 0, "bytes": 0, "error": -1 }
    >120000> Thu Jan 01 00:02:00 1970, heap: 10600
    
  • additionally

    >require("ESP8266").getState();
    ={
      "sdkVersion": "1.5.0",
      "cpuFrequency": 160, "freeHeap": 8968, "maxCon": 10,
      "flashMap": "4MB:512/512",
      "flashKB": 4096,
      "flashChip": "0xe0 0x4016"
     }
    > 
    
  • also works for me with sdk 1.5.4

    >require("ESP8266").getState();
    ={
      "sdkVersion": "1.5.4(baaeaebb)",
      "cpuFrequency": 160, "freeHeap": 9144, "maxCon": 10,
      "flashMap": "4MB:512/512",
      "flashKB": 4096,
      "flashChip": "0xe0 0x4016"
     }
    >var ESP8266=require("ESP8266");
    =function () { [native code] }
    >var Wifi = require("Wifi")
    =function () { [native code] }
    >Wifi.getIP();
    ={
      "ip": "192.168.194.64",
      "netmask": "255.255.255.0",
      "gw": "192.168.194.1",
      "mac": "5c:cf:7f:05:c1:00"
     }
    >ESP8266.setLog(2);
    =undefined
    >ESP8266.ping("192.168.2.1", function(e){ console.log(e);});
    =undefined
    >140681> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 5,
      "seqNo": 1, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >141775> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 2,
      "seqNo": 2, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >142824> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 3, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >144024> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 4, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >145149> Received a ping response!
    { "totalCount": 0, "totalBytes": 0, "totalTime": 0, "respTime": 1,
      "seqNo": 5, "timeoutCount": 0, "bytes": 32, "error": 0 }
    >146322> ping 5, timeout 0, total payload 160 bytes, 5646 ms
    
    
  • ESP on 192.168.194.65, Macbook on 192.168.194.52

    ESP pings Macbook and Macbook captures packages with tcpdump

    tcpdump -s 1550 -w x.pcap -v host 192.168.194.64
    tcpdump: data link type PKTAP
    tcpdump: listening on pktap, link-type PKTAP (Packet Tap), capture size 1550 bytes
    10 packets captured
    87 packets received by filter
    0 packets dropped by kernel

    tcpdump -XX -nnr x.pcap | grep ICMP
    reading from PCAP-NG file x.pcap
    17:13:10.851201 IP 192.168.194.64 > 0.0.0.0: ICMP echo request, id 44975, seq 11, length 40
    17:13:10.851227 IP 192.168.194.52 > 192.168.194.64: ICMP echo reply, id 44975, seq 11, length 40
    17:13:11.772757 IP 192.168.194.64 > 0.0.0.0: ICMP echo request, id 44975, seq 12, length 40
    17:13:11.772777 IP 192.168.194.52 > 192.168.194.64: ICMP echo reply, id 44975, seq 12, length 40
    17:13:13.001780 IP 192.168.194.64 > 0.0.0.0: ICMP echo request, id 44975, seq 13, length 40
    17:13:13.001813 IP 192.168.194.52 > 192.168.194.64: ICMP echo reply, id 44975, seq 13, length 40
    17:13:13.933726 IP 192.168.194.64 > 0.0.0.0: ICMP echo request, id 44975, seq 14, length 40
    17:13:13.933756 IP 192.168.194.52 > 192.168.194.64: ICMP echo reply, id 44975, seq 14, length 40
    17:13:15.107559 IP 192.168.194.64 > 0.0.0.0: ICMP echo request, id 44975, seq 15, length 40
    17:13:15.107585 IP 192.168.194.52 > 192.168.194.64: ICMP echo reply, id 44975, seq 15, length 40

    funny .....

  • Yup, there's a clear bug where the ping always goes to 0.0.0.0. Some devices evidently respond to that.

  • @tve take it and let you get payed for your great work on Esprunino for ESPs at Bug Bounty

    
    >require("ESP8266").getState()
    ={
      "sdkVersion": "1.5.4(baaeaebb)",
      "cpuFrequency": 160, "freeHeap": 8960, "maxCon": 10,
      "flashMap": "4MB:512/512",
      "flashKB": 4096,
      "flashChip": "0xe0 0x4016"
     }
    
    >ESP8266.ping("192.168.194.52");
     23417> >> ping ip: 192.168.194.52 : 14
    =undefined
    > 23423> Received a ping response!
     24523> Received a ping response!
     25623> Received a ping response!
     26723> Received a ping response!
     27773> Received a ping response!
     28922> ping 5, timeout 0, total payload 160 bytes, 5504 ms
    
  • The bug is in the esp8266 espruino code...

  • hmm - I will start searching now - good exercise for me ;-)

  • comment this line and you get this:

    tcpdump -XX -nnr x.pcap | grep ICMP
    reading from PCAP-NG file x.pcap
    21:00:53.676020 IP 192.168.194.64 > 192.168.194.52: ICMP echo request, id 44975, seq 1, length 40
    21:00:53.676059 IP 192.168.194.52 > 192.168.194.64: ICMP echo reply, id 44975, seq 1, length 40
    21:00:54.791637 IP 192.168.194.64 > 192.168.194.52: ICMP echo request, id 44975, seq 2, length 40
    21:00:54.791662 IP 192.168.194.52 > 192.168.194.64: ICMP echo reply, id 44975, seq 2, length 40

    @tve please check

  • @MaBe - the BugBounty link doesn't work. URL comes out hopelessly mangled.

  • @DrAzzy - updated the link

    but as tve mentioned:

    The bug is in the esp8266 espruino code...

  • created pull request #874

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

ESP8266.ping does not work as expected

Posted by Avatar for Filip @Filip

Actions