mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-25 15:27:17 +00:00
move response for unresolved ip into poll
This commit is contained in:
parent
dd624c3ce6
commit
2e1ac3581f
@ -246,14 +246,13 @@ extern "C" {
|
|||||||
int32_t t_ping_start(const char *hostname, uint32_t count) {
|
int32_t t_ping_start(const char *hostname, uint32_t count) {
|
||||||
IPAddress ipfull;
|
IPAddress ipfull;
|
||||||
if (!WiFi.hostByName(hostname, ipfull)) {
|
if (!WiFi.hostByName(hostname, ipfull)) {
|
||||||
return -2;
|
ipfull = 0xFFFFFFFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t ip = ipfull;
|
uint32_t ip = ipfull;
|
||||||
if (0xFFFFFFFF == ip) { return -2; } // invalid address
|
|
||||||
|
|
||||||
// check if pings are already ongoing for this IP
|
// check if pings are already ongoing for this IP
|
||||||
if (t_ping_find(ip)) {
|
if (0xFFFFFFFF != ip && t_ping_find(ip)) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -271,6 +270,12 @@ extern "C" {
|
|||||||
ping->next = ping_head;
|
ping->next = ping_head;
|
||||||
ping_head = ping; // insert at head
|
ping_head = ping; // insert at head
|
||||||
|
|
||||||
|
if (0xFFFFFFFF == ip) { // If invalid address, set as completed
|
||||||
|
ping->done = true;
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// send
|
||||||
t_ping_register_pcb();
|
t_ping_register_pcb();
|
||||||
t_ping_send(t_ping_pcb, ping);
|
t_ping_send(t_ping_pcb, ping);
|
||||||
|
|
||||||
@ -293,6 +298,15 @@ void PingResponsePoll(void) {
|
|||||||
uint32_t success = ping->success_count;
|
uint32_t success = ping->success_count;
|
||||||
uint32_t ip = ping->ip;
|
uint32_t ip = ping->ip;
|
||||||
|
|
||||||
|
if (0xFFFFFFFF == ip) {
|
||||||
|
Response_P(PSTR("{\"" D_JSON_PING "\":{\"%s\":{"
|
||||||
|
"\"Reachable\":false"
|
||||||
|
",\"IP\":\"\""
|
||||||
|
",\"Success\":false"
|
||||||
|
"}}}"),
|
||||||
|
ping->hostname.c_str()
|
||||||
|
);
|
||||||
|
} else {
|
||||||
Response_P(PSTR("{\"" D_JSON_PING "\":{\"%s\":{"
|
Response_P(PSTR("{\"" D_JSON_PING "\":{\"%s\":{"
|
||||||
"\"Reachable\":%s"
|
"\"Reachable\":%s"
|
||||||
",\"IP\":\"%d.%d.%d.%d\""
|
",\"IP\":\"%d.%d.%d.%d\""
|
||||||
@ -311,6 +325,7 @@ void PingResponsePoll(void) {
|
|||||||
ping->max_time,
|
ping->max_time,
|
||||||
success ? ping->sum_time / success : 0
|
success ? ping->sum_time / success : 0
|
||||||
);
|
);
|
||||||
|
}
|
||||||
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_PING));
|
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_PING));
|
||||||
|
|
||||||
// remove from linked list
|
// remove from linked list
|
||||||
@ -342,6 +357,7 @@ void CmndPing(void) {
|
|||||||
} else if (-1 == res) {
|
} else if (-1 == res) {
|
||||||
ResponseCmndChar_P(PSTR("Ping already ongoing for this IP"));
|
ResponseCmndChar_P(PSTR("Ping already ongoing for this IP"));
|
||||||
} else {
|
} else {
|
||||||
|
/*
|
||||||
Response_P(PSTR("{\"" D_JSON_PING "\":{\"%s\":{"
|
Response_P(PSTR("{\"" D_JSON_PING "\":{\"%s\":{"
|
||||||
"\"Reachable\":false"
|
"\"Reachable\":false"
|
||||||
",\"IP\":\"\""
|
",\"IP\":\"\""
|
||||||
@ -350,6 +366,7 @@ void CmndPing(void) {
|
|||||||
XdrvMailbox.data
|
XdrvMailbox.data
|
||||||
);
|
);
|
||||||
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_PING));
|
MqttPublishPrefixTopicRulesProcess_P(RESULT_OR_TELE, PSTR(D_JSON_PING));
|
||||||
|
*/
|
||||||
ResponseCmndChar_P(PSTR("Unable to resolve IP address"));
|
ResponseCmndChar_P(PSTR("Unable to resolve IP address"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user