Fix hangup on no internet
This commit is contained in:
4
lib/ESP32Ping/.gitignore
vendored
Normal file
4
lib/ESP32Ping/.gitignore
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.pioenvs
|
||||||
|
.piolibdeps
|
||||||
|
.idea
|
||||||
|
CMakeListsPrivate.txt
|
||||||
115
lib/ESP32Ping/ESP32Ping.cpp
Normal file
115
lib/ESP32Ping/ESP32Ping.cpp
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
ESP32Ping - Ping library for ESP32
|
||||||
|
Copyright (c) 2018 Marian Craciunescu. All rights reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
#include "ESP32Ping.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern "C" void esp_schedule(void) {};
|
||||||
|
extern "C" void esp_yield(void) {};
|
||||||
|
|
||||||
|
PingClass::PingClass() {}
|
||||||
|
|
||||||
|
bool PingClass::ping(IPAddress dest, byte count) {
|
||||||
|
_expected_count = count;
|
||||||
|
_errors = 0;
|
||||||
|
_success = 0;
|
||||||
|
|
||||||
|
_avg_time = 0;
|
||||||
|
|
||||||
|
memset(&_options, 0, sizeof(struct ping_option));
|
||||||
|
|
||||||
|
// Repeat count (how many time send a ping message to destination)
|
||||||
|
_options.count = count;
|
||||||
|
// Time interval between two ping (seconds??)
|
||||||
|
_options.coarse_time = 1;
|
||||||
|
// Destination machine
|
||||||
|
_options.ip = dest;
|
||||||
|
|
||||||
|
// Callbacks
|
||||||
|
_options.recv_function = reinterpret_cast<ping_recv_function>(&PingClass::_ping_recv_cb);
|
||||||
|
_options.sent_function = NULL; //reinterpret_cast<ping_sent_function>(&_ping_sent_cb);
|
||||||
|
|
||||||
|
|
||||||
|
// Suspend till the process end
|
||||||
|
esp_yield(); // ????????? Where should this be placed?
|
||||||
|
|
||||||
|
// Let's go!
|
||||||
|
ping_start(&_options); // Here we do all the work
|
||||||
|
|
||||||
|
// Returns true if at least 1 ping had a pong response
|
||||||
|
return (_success > 0); //_success variable is changed by the callback function
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PingClass::ping(const char *host, byte count) {
|
||||||
|
IPAddress remote_addr;
|
||||||
|
|
||||||
|
if (Network.hostByName(host, remote_addr))
|
||||||
|
return ping(remote_addr, count);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
float PingClass::averageTime() {
|
||||||
|
return _avg_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PingClass::_ping_recv_cb(void *opt, void *resp) {
|
||||||
|
// Cast the parameters to get some usable info
|
||||||
|
ping_resp *ping_resp = reinterpret_cast<struct ping_resp *>(resp);
|
||||||
|
//ping_option* ping_opt = reinterpret_cast<struct ping_option*>(opt);
|
||||||
|
|
||||||
|
// Error or success?
|
||||||
|
_errors = ping_resp->timeout_count;
|
||||||
|
_success = ping_resp->total_count - ping_resp->timeout_count;
|
||||||
|
_avg_time = ping_resp->resp_time;
|
||||||
|
|
||||||
|
|
||||||
|
// Some debug info
|
||||||
|
DEBUG_PING(
|
||||||
|
"DEBUG: ping reply\n"
|
||||||
|
"\ttotal_count = %d \n"
|
||||||
|
"\tresp_time = %f ms\n"
|
||||||
|
"\tseqno = %d \n"
|
||||||
|
"\ttimeout_count = %d \n"
|
||||||
|
"\tbytes = %d \n"
|
||||||
|
"\ttotal_bytes = %d \n"
|
||||||
|
"\ttotal_time = %f s\n"
|
||||||
|
"\tping_err = %d \n",
|
||||||
|
ping_resp->total_count, ping_resp->resp_time, ping_resp->seqno,
|
||||||
|
ping_resp->timeout_count, ping_resp->bytes, ping_resp->total_bytes,
|
||||||
|
ping_resp->total_time, ping_resp->ping_err
|
||||||
|
);
|
||||||
|
|
||||||
|
// Is it time to end?
|
||||||
|
DEBUG_PING("Avg resp time %f ms\n", _avg_time);
|
||||||
|
|
||||||
|
// Done, return to main functiom
|
||||||
|
esp_schedule();
|
||||||
|
|
||||||
|
// just a check ...
|
||||||
|
if (_success + _errors != _expected_count) {
|
||||||
|
DEBUG_PING("Something went wrong: _success=%d and _errors=%d do not sum up to _expected_count=%d\n",_success, _errors, _expected_count );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
byte PingClass::_expected_count = 0;
|
||||||
|
byte PingClass::_errors = 0;
|
||||||
|
byte PingClass::_success = 0;
|
||||||
|
float PingClass::_avg_time = 0;
|
||||||
|
|
||||||
|
PingClass Ping;
|
||||||
72
lib/ESP32Ping/ESP32Ping.h
Normal file
72
lib/ESP32Ping/ESP32Ping.h
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
/*
|
||||||
|
ESP32Ping - Ping library for ESP32
|
||||||
|
Copyright (c) 2018 Marian Craciunescu. All rights reserved.
|
||||||
|
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef ESP32PING_H
|
||||||
|
#define ESP32PING_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <Network.h>
|
||||||
|
|
||||||
|
//extern "C" {
|
||||||
|
#include <ping.h>
|
||||||
|
//}
|
||||||
|
|
||||||
|
#ifdef ENABLE_DEBUG_PING
|
||||||
|
#define DEBUG_PING(...) Serial.printf(__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define DEBUG_PING(...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void esp_schedule(void);
|
||||||
|
void esp_yield(void);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} // extern "C"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
class PingClass {
|
||||||
|
public:
|
||||||
|
PingClass();
|
||||||
|
|
||||||
|
bool ping(IPAddress dest, byte count = 5);
|
||||||
|
|
||||||
|
bool ping(const char *host, byte count = 5);
|
||||||
|
|
||||||
|
float averageTime();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
static void _ping_sent_cb(void *opt, void *pdata);
|
||||||
|
|
||||||
|
static void _ping_recv_cb(void *opt, void *pdata);
|
||||||
|
|
||||||
|
IPAddress _dest;
|
||||||
|
ping_option _options;
|
||||||
|
|
||||||
|
static byte _expected_count, _errors, _success;
|
||||||
|
static float _avg_time;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
extern PingClass Ping;
|
||||||
|
|
||||||
|
#endif
|
||||||
456
lib/ESP32Ping/LICENSE
Normal file
456
lib/ESP32Ping/LICENSE
Normal file
@@ -0,0 +1,456 @@
|
|||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
Version 2.1, February 1999
|
||||||
|
|
||||||
|
Copyright (C) 1991, 1999 Free Software Foundation, Inc.
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
|
[This is the first released version of the Lesser GPL. It also counts
|
||||||
|
as the successor of the GNU Library Public License, version 2, hence
|
||||||
|
the version number 2.1.]
|
||||||
|
|
||||||
|
Preamble
|
||||||
|
|
||||||
|
The licenses for most software are designed to take away your
|
||||||
|
freedom to share and change it. By contrast, the GNU General Public
|
||||||
|
Licenses are intended to guarantee your freedom to share and change
|
||||||
|
free software--to make sure the software is free for all its users.
|
||||||
|
|
||||||
|
This license, the Lesser General Public License, applies to some
|
||||||
|
specially designated software packages--typically libraries--of the
|
||||||
|
Free Software Foundation and other authors who decide to use it. You
|
||||||
|
can use it too, but we suggest you first think carefully about whether
|
||||||
|
this license or the ordinary General Public License is the better
|
||||||
|
strategy to use in any particular case, based on the explanations below.
|
||||||
|
|
||||||
|
When we speak of free software, we are referring to freedom of use,
|
||||||
|
not price. Our General Public Licenses are designed to make sure that
|
||||||
|
you have the freedom to distribute copies of free software (and charge
|
||||||
|
for this service if you wish); that you receive source code or can get
|
||||||
|
it if you want it; that you can change the software and use pieces of
|
||||||
|
it in new free programs; and that you are informed that you can do
|
||||||
|
these things.
|
||||||
|
|
||||||
|
To protect your rights, we need to make restrictions that forbid
|
||||||
|
distributors to deny you these rights or to ask you to surrender these
|
||||||
|
rights. These restrictions translate to certain responsibilities for
|
||||||
|
you if you distribute copies of the library or if you modify it.
|
||||||
|
|
||||||
|
For example, if you distribute copies of the library, whether gratis
|
||||||
|
or for a fee, you must give the recipients all the rights that we gave
|
||||||
|
you. You must make sure that they, too, receive or can get the source
|
||||||
|
code. If you link other code with the library, you must provide
|
||||||
|
complete object files to the recipients, so that they can relink them
|
||||||
|
with the library after making changes to the library and recompiling
|
||||||
|
it. And you must show them these terms so they know their rights.
|
||||||
|
|
||||||
|
We protect your rights with a two-step method: (1) we copyright the
|
||||||
|
library, and (2) we offer you this license, which gives you legal
|
||||||
|
permission to copy, distribute and/or modify the library.
|
||||||
|
|
||||||
|
To protect each distributor, we want to make it very clear that
|
||||||
|
there is no warranty for the free library. Also, if the library is
|
||||||
|
modified by someone else and passed on, the recipients should know
|
||||||
|
that what they have is not the original version, so that the original
|
||||||
|
author's reputation will not be affected by problems that might be
|
||||||
|
introduced by others.
|
||||||
|
|
||||||
|
Finally, software patents pose a constant threat to the existence of
|
||||||
|
any free program. We wish to make sure that a company cannot
|
||||||
|
effectively restrict the users of a free program by obtaining a
|
||||||
|
restrictive license from a patent holder. Therefore, we insist that
|
||||||
|
any patent license obtained for a version of the library must be
|
||||||
|
consistent with the full freedom of use specified in this license.
|
||||||
|
|
||||||
|
Most GNU software, including some libraries, is covered by the
|
||||||
|
ordinary GNU General Public License. This license, the GNU Lesser
|
||||||
|
General Public License, applies to certain designated libraries, and
|
||||||
|
is quite different from the ordinary General Public License. We use
|
||||||
|
this license for certain libraries in order to permit linking those
|
||||||
|
libraries into non-free programs.
|
||||||
|
|
||||||
|
When a program is linked with a library, whether statically or using
|
||||||
|
a shared library, the combination of the two is legally speaking a
|
||||||
|
combined work, a derivative of the original library. The ordinary
|
||||||
|
General Public License therefore permits such linking only if the
|
||||||
|
entire combination fits its criteria of freedom. The Lesser General
|
||||||
|
Public License permits more lax criteria for linking other code with
|
||||||
|
the library.
|
||||||
|
|
||||||
|
We call this license the "Lesser" General Public License because it
|
||||||
|
does Less to protect the user's freedom than the ordinary General
|
||||||
|
Public License. It also provides other free software developers Less
|
||||||
|
of an advantage over competing non-free programs. These disadvantages
|
||||||
|
are the reason we use the ordinary General Public License for many
|
||||||
|
libraries. However, the Lesser license provides advantages in certain
|
||||||
|
special circumstances.
|
||||||
|
|
||||||
|
For example, on rare occasions, there may be a special need to
|
||||||
|
encourage the widest possible use of a certain library, so that it becomes
|
||||||
|
a de-facto standard. To achieve this, non-free programs must be
|
||||||
|
allowed to use the library. A more frequent case is that a free
|
||||||
|
library does the same job as widely used non-free libraries. In this
|
||||||
|
case, there is little to gain by limiting the free library to free
|
||||||
|
software only, so we use the Lesser General Public License.
|
||||||
|
|
||||||
|
In other cases, permission to use a particular library in non-free
|
||||||
|
programs enables a greater number of people to use a large body of
|
||||||
|
free software. For example, permission to use the GNU C Library in
|
||||||
|
non-free programs enables many more people to use the whole GNU
|
||||||
|
operating system, as well as its variant, the GNU/Linux operating
|
||||||
|
system.
|
||||||
|
|
||||||
|
Although the Lesser General Public License is Less protective of the
|
||||||
|
users' freedom, it does ensure that the user of a program that is
|
||||||
|
linked with the Library has the freedom and the wherewithal to run
|
||||||
|
that program using a modified version of the Library.
|
||||||
|
|
||||||
|
The precise terms and conditions for copying, distribution and
|
||||||
|
modification follow. Pay close attention to the difference between a
|
||||||
|
"work based on the library" and a "work that uses the library". The
|
||||||
|
former contains code derived from the library, whereas the latter must
|
||||||
|
be combined with the library in order to run.
|
||||||
|
|
||||||
|
GNU LESSER GENERAL PUBLIC LICENSE
|
||||||
|
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||||
|
|
||||||
|
0. This License Agreement applies to any software library or other
|
||||||
|
program which contains a notice placed by the copyright holder or
|
||||||
|
other authorized party saying it may be distributed under the terms of
|
||||||
|
this Lesser General Public License (also called "this License").
|
||||||
|
Each licensee is addressed as "you".
|
||||||
|
|
||||||
|
A "library" means a collection of software functions and/or data
|
||||||
|
prepared so as to be conveniently linked with application programs
|
||||||
|
(which use some of those functions and data) to form executables.
|
||||||
|
|
||||||
|
The "Library", below, refers to any such software library or work
|
||||||
|
which has been distributed under these terms. A "work based on the
|
||||||
|
Library" means either the Library or any derivative work under
|
||||||
|
copyright law: that is to say, a work containing the Library or a
|
||||||
|
portion of it, either verbatim or with modifications and/or translated
|
||||||
|
straightforwardly into another language. (Hereinafter, translation is
|
||||||
|
included without limitation in the term "modification".)
|
||||||
|
|
||||||
|
"Source code" for a work means the preferred form of the work for
|
||||||
|
making modifications to it. For a library, complete source code means
|
||||||
|
all the source code for all modules it contains, plus any associated
|
||||||
|
interface definition files, plus the scripts used to control compilation
|
||||||
|
and installation of the library.
|
||||||
|
|
||||||
|
Activities other than copying, distribution and modification are not
|
||||||
|
covered by this License; they are outside its scope. The act of
|
||||||
|
running a program using the Library is not restricted, and output from
|
||||||
|
such a program is covered only if its contents constitute a work based
|
||||||
|
on the Library (independent of the use of the Library in a tool for
|
||||||
|
writing it). Whether that is true depends on what the Library does
|
||||||
|
and what the program that uses the Library does.
|
||||||
|
|
||||||
|
1. You may copy and distribute verbatim copies of the Library's
|
||||||
|
complete source code as you receive it, in any medium, provided that
|
||||||
|
you conspicuously and appropriately publish on each copy an
|
||||||
|
appropriate copyright notice and disclaimer of warranty; keep intact
|
||||||
|
all the notices that refer to this License and to the absence of any
|
||||||
|
warranty; and distribute a copy of this License along with the
|
||||||
|
Library.
|
||||||
|
|
||||||
|
You may charge a fee for the physical act of transferring a copy,
|
||||||
|
and you may at your option offer warranty protection in exchange for a
|
||||||
|
fee.
|
||||||
|
|
||||||
|
2. You may modify your copy or copies of the Library or any portion
|
||||||
|
of it, thus forming a work based on the Library, and copy and
|
||||||
|
distribute such modifications or work under the terms of Section 1
|
||||||
|
above, provided that you also meet all of these conditions:
|
||||||
|
|
||||||
|
a) The modified work must itself be a software library.
|
||||||
|
|
||||||
|
b) You must cause the files modified to carry prominent notices
|
||||||
|
stating that you changed the files and the date of any change.
|
||||||
|
|
||||||
|
c) You must cause the whole of the work to be licensed at no
|
||||||
|
charge to all third parties under the terms of this License.
|
||||||
|
|
||||||
|
d) If a facility in the modified Library refers to a function or a
|
||||||
|
table of data to be supplied by an application program that uses
|
||||||
|
the facility, other than as an argument passed when the facility
|
||||||
|
is invoked, then you must make a good faith effort to ensure that,
|
||||||
|
in the event an application does not supply such function or
|
||||||
|
table, the facility still operates, and performs whatever part of
|
||||||
|
its purpose remains meaningful.
|
||||||
|
|
||||||
|
(For example, a function in a library to compute square roots has
|
||||||
|
a purpose that is entirely well-defined independent of the
|
||||||
|
application. Therefore, Subsection 2d requires that any
|
||||||
|
application-supplied function or table used by this function must
|
||||||
|
be optional: if the application does not supply it, the square
|
||||||
|
root function must still compute square roots.)
|
||||||
|
|
||||||
|
These requirements apply to the modified work as a whole. If
|
||||||
|
identifiable sections of that work are not derived from the Library,
|
||||||
|
and can be reasonably considered independent and separate works in
|
||||||
|
themselves, then this License, and its terms, do not apply to those
|
||||||
|
sections when you distribute them as separate works. But when you
|
||||||
|
distribute the same sections as part of a whole which is a work based
|
||||||
|
on the Library, the distribution of the whole must be on the terms of
|
||||||
|
this License, whose permissions for other licensees extend to the
|
||||||
|
entire whole, and thus to each and every part regardless of who wrote
|
||||||
|
it.
|
||||||
|
|
||||||
|
Thus, it is not the intent of this section to claim rights or contest
|
||||||
|
your rights to work written entirely by you; rather, the intent is to
|
||||||
|
exercise the right to control the distribution of derivative or
|
||||||
|
collective works based on the Library.
|
||||||
|
|
||||||
|
In addition, mere aggregation of another work not based on the Library
|
||||||
|
with the Library (or with a work based on the Library) on a volume of
|
||||||
|
a storage or distribution medium does not bring the other work under
|
||||||
|
the scope of this License.
|
||||||
|
|
||||||
|
3. You may opt to apply the terms of the ordinary GNU General Public
|
||||||
|
License instead of this License to a given copy of the Library. To do
|
||||||
|
this, you must alter all the notices that refer to this License, so
|
||||||
|
that they refer to the ordinary GNU General Public License, version 2,
|
||||||
|
instead of to this License. (If a newer version than version 2 of the
|
||||||
|
ordinary GNU General Public License has appeared, then you can specify
|
||||||
|
that version instead if you wish.) Do not make any other change in
|
||||||
|
these notices.
|
||||||
|
|
||||||
|
Once this change is made in a given copy, it is irreversible for
|
||||||
|
that copy, so the ordinary GNU General Public License applies to all
|
||||||
|
subsequent copies and derivative works made from that copy.
|
||||||
|
|
||||||
|
This option is useful when you wish to copy part of the code of
|
||||||
|
the Library into a program that is not a library.
|
||||||
|
|
||||||
|
4. You may copy and distribute the Library (or a portion or
|
||||||
|
derivative of it, under Section 2) in object code or executable form
|
||||||
|
under the terms of Sections 1 and 2 above provided that you accompany
|
||||||
|
it with the complete corresponding machine-readable source code, which
|
||||||
|
must be distributed under the terms of Sections 1 and 2 above on a
|
||||||
|
medium customarily used for software interchange.
|
||||||
|
|
||||||
|
If distribution of object code is made by offering access to copy
|
||||||
|
from a designated place, then offering equivalent access to copy the
|
||||||
|
source code from the same place satisfies the requirement to
|
||||||
|
distribute the source code, even though third parties are not
|
||||||
|
compelled to copy the source along with the object code.
|
||||||
|
|
||||||
|
5. A program that contains no derivative of any portion of the
|
||||||
|
Library, but is designed to work with the Library by being compiled or
|
||||||
|
linked with it, is called a "work that uses the Library". Such a
|
||||||
|
work, in isolation, is not a derivative work of the Library, and
|
||||||
|
therefore falls outside the scope of this License.
|
||||||
|
|
||||||
|
However, linking a "work that uses the Library" with the Library
|
||||||
|
creates an executable that is a derivative of the Library (because it
|
||||||
|
contains portions of the Library), rather than a "work that uses the
|
||||||
|
library". The executable is therefore covered by this License.
|
||||||
|
Section 6 states terms for distribution of such executables.
|
||||||
|
|
||||||
|
When a "work that uses the Library" uses material from a header file
|
||||||
|
that is part of the Library, the object code for the work may be a
|
||||||
|
derivative work of the Library even though the source code is not.
|
||||||
|
Whether this is true is especially significant if the work can be
|
||||||
|
linked without the Library, or if the work is itself a library. The
|
||||||
|
threshold for this to be true is not precisely defined by law.
|
||||||
|
|
||||||
|
If such an object file uses only numerical parameters, data
|
||||||
|
structure layouts and accessors, and small macros and small inline
|
||||||
|
functions (ten lines or less in length), then the use of the object
|
||||||
|
file is unrestricted, regardless of whether it is legally a derivative
|
||||||
|
work. (Executables containing this object code plus portions of the
|
||||||
|
Library will still fall under Section 6.)
|
||||||
|
|
||||||
|
Otherwise, if the work is a derivative of the Library, you may
|
||||||
|
distribute the object code for the work under the terms of Section 6.
|
||||||
|
Any executables containing that work also fall under Section 6,
|
||||||
|
whether or not they are linked directly with the Library itself.
|
||||||
|
|
||||||
|
6. As an exception to the Sections above, you may also combine or
|
||||||
|
link a "work that uses the Library" with the Library to produce a
|
||||||
|
work containing portions of the Library, and distribute that work
|
||||||
|
under terms of your choice, provided that the terms permit
|
||||||
|
modification of the work for the customer's own use and reverse
|
||||||
|
engineering for debugging such modifications.
|
||||||
|
|
||||||
|
You must give prominent notice with each copy of the work that the
|
||||||
|
Library is used in it and that the Library and its use are covered by
|
||||||
|
this License. You must supply a copy of this License. If the work
|
||||||
|
during execution displays copyright notices, you must include the
|
||||||
|
copyright notice for the Library among them, as well as a reference
|
||||||
|
directing the user to the copy of this License. Also, you must do one
|
||||||
|
of these things:
|
||||||
|
|
||||||
|
a) Accompany the work with the complete corresponding
|
||||||
|
machine-readable source code for the Library including whatever
|
||||||
|
changes were used in the work (which must be distributed under
|
||||||
|
Sections 1 and 2 above); and, if the work is an executable linked
|
||||||
|
with the Library, with the complete machine-readable "work that
|
||||||
|
uses the Library", as object code and/or source code, so that the
|
||||||
|
user can modify the Library and then relink to produce a modified
|
||||||
|
executable containing the modified Library. (It is understood
|
||||||
|
that the user who changes the contents of definitions files in the
|
||||||
|
Library will not necessarily be able to recompile the application
|
||||||
|
to use the modified definitions.)
|
||||||
|
|
||||||
|
b) Use a suitable shared library mechanism for linking with the
|
||||||
|
Library. A suitable mechanism is one that (1) uses at run time a
|
||||||
|
copy of the library already present on the user's computer system,
|
||||||
|
rather than copying library functions into the executable, and (2)
|
||||||
|
will operate properly with a modified version of the library, if
|
||||||
|
the user installs one, as long as the modified version is
|
||||||
|
interface-compatible with the version that the work was made with.
|
||||||
|
|
||||||
|
c) Accompany the work with a written offer, valid for at
|
||||||
|
least three years, to give the same user the materials
|
||||||
|
specified in Subsection 6a, above, for a charge no more
|
||||||
|
than the cost of performing this distribution.
|
||||||
|
|
||||||
|
d) If distribution of the work is made by offering access to copy
|
||||||
|
from a designated place, offer equivalent access to copy the above
|
||||||
|
specified materials from the same place.
|
||||||
|
|
||||||
|
e) Verify that the user has already received a copy of these
|
||||||
|
materials or that you have already sent this user a copy.
|
||||||
|
|
||||||
|
For an executable, the required form of the "work that uses the
|
||||||
|
Library" must include any data and utility programs needed for
|
||||||
|
reproducing the executable from it. However, as a special exception,
|
||||||
|
the materials to be distributed need not include anything that is
|
||||||
|
normally distributed (in either source or binary form) with the major
|
||||||
|
components (compiler, kernel, and so on) of the operating system on
|
||||||
|
which the executable runs, unless that component itself accompanies
|
||||||
|
the executable.
|
||||||
|
|
||||||
|
It may happen that this requirement contradicts the license
|
||||||
|
restrictions of other proprietary libraries that do not normally
|
||||||
|
accompany the operating system. Such a contradiction means you cannot
|
||||||
|
use both them and the Library together in an executable that you
|
||||||
|
distribute.
|
||||||
|
|
||||||
|
7. You may place library facilities that are a work based on the
|
||||||
|
Library side-by-side in a single library together with other library
|
||||||
|
facilities not covered by this License, and distribute such a combined
|
||||||
|
library, provided that the separate distribution of the work based on
|
||||||
|
the Library and of the other library facilities is otherwise
|
||||||
|
permitted, and provided that you do these two things:
|
||||||
|
|
||||||
|
a) Accompany the combined library with a copy of the same work
|
||||||
|
based on the Library, uncombined with any other library
|
||||||
|
facilities. This must be distributed under the terms of the
|
||||||
|
Sections above.
|
||||||
|
|
||||||
|
b) Give prominent notice with the combined library of the fact
|
||||||
|
that part of it is a work based on the Library, and explaining
|
||||||
|
where to find the accompanying uncombined form of the same work.
|
||||||
|
|
||||||
|
8. You may not copy, modify, sublicense, link with, or distribute
|
||||||
|
the Library except as expressly provided under this License. Any
|
||||||
|
attempt otherwise to copy, modify, sublicense, link with, or
|
||||||
|
distribute the Library is void, and will automatically terminate your
|
||||||
|
rights under this License. However, parties who have received copies,
|
||||||
|
or rights, from you under this License will not have their licenses
|
||||||
|
terminated so long as such parties remain in full compliance.
|
||||||
|
|
||||||
|
9. You are not required to accept this License, since you have not
|
||||||
|
signed it. However, nothing else grants you permission to modify or
|
||||||
|
distribute the Library or its derivative works. These actions are
|
||||||
|
prohibited by law if you do not accept this License. Therefore, by
|
||||||
|
modifying or distributing the Library (or any work based on the
|
||||||
|
Library), you indicate your acceptance of this License to do so, and
|
||||||
|
all its terms and conditions for copying, distributing or modifying
|
||||||
|
the Library or works based on it.
|
||||||
|
|
||||||
|
10. Each time you redistribute the Library (or any work based on the
|
||||||
|
Library), the recipient automatically receives a license from the
|
||||||
|
original licensor to copy, distribute, link with or modify the Library
|
||||||
|
subject to these terms and conditions. You may not impose any further
|
||||||
|
restrictions on the recipients' exercise of the rights granted herein.
|
||||||
|
You are not responsible for enforcing compliance by third parties with
|
||||||
|
this License.
|
||||||
|
|
||||||
|
11. If, as a consequence of a court judgment or allegation of patent
|
||||||
|
infringement or for any other reason (not limited to patent issues),
|
||||||
|
conditions are imposed on you (whether by court order, agreement or
|
||||||
|
otherwise) that contradict the conditions of this License, they do not
|
||||||
|
excuse you from the conditions of this License. If you cannot
|
||||||
|
distribute so as to satisfy simultaneously your obligations under this
|
||||||
|
License and any other pertinent obligations, then as a consequence you
|
||||||
|
may not distribute the Library at all. For example, if a patent
|
||||||
|
license would not permit royalty-free redistribution of the Library by
|
||||||
|
all those who receive copies directly or indirectly through you, then
|
||||||
|
the only way you could satisfy both it and this License would be to
|
||||||
|
refrain entirely from distribution of the Library.
|
||||||
|
|
||||||
|
If any portion of this section is held invalid or unenforceable under any
|
||||||
|
particular circumstance, the balance of the section is intended to apply,
|
||||||
|
and the section as a whole is intended to apply in other circumstances.
|
||||||
|
|
||||||
|
It is not the purpose of this section to induce you to infringe any
|
||||||
|
patents or other property right claims or to contest validity of any
|
||||||
|
such claims; this section has the sole purpose of protecting the
|
||||||
|
integrity of the free software distribution system which is
|
||||||
|
implemented by public license practices. Many people have made
|
||||||
|
generous contributions to the wide range of software distributed
|
||||||
|
through that system in reliance on consistent application of that
|
||||||
|
system; it is up to the author/donor to decide if he or she is willing
|
||||||
|
to distribute software through any other system and a licensee cannot
|
||||||
|
impose that choice.
|
||||||
|
|
||||||
|
This section is intended to make thoroughly clear what is believed to
|
||||||
|
be a consequence of the rest of this License.
|
||||||
|
|
||||||
|
12. If the distribution and/or use of the Library is restricted in
|
||||||
|
certain countries either by patents or by copyrighted interfaces, the
|
||||||
|
original copyright holder who places the Library under this License may add
|
||||||
|
an explicit geographical distribution limitation excluding those countries,
|
||||||
|
so that distribution is permitted only in or among countries not thus
|
||||||
|
excluded. In such case, this License incorporates the limitation as if
|
||||||
|
written in the body of this License.
|
||||||
|
|
||||||
|
13. The Free Software Foundation may publish revised and/or new
|
||||||
|
versions of the Lesser General Public License from time to time.
|
||||||
|
Such new versions will be similar in spirit to the present version,
|
||||||
|
but may differ in detail to address new problems or concerns.
|
||||||
|
|
||||||
|
Each version is given a distinguishing version number. If the Library
|
||||||
|
specifies a version number of this License which applies to it and
|
||||||
|
"any later version", you have the option of following the terms and
|
||||||
|
conditions either of that version or of any later version published by
|
||||||
|
the Free Software Foundation. If the Library does not specify a
|
||||||
|
license version number, you may choose any version ever published by
|
||||||
|
the Free Software Foundation.
|
||||||
|
|
||||||
|
14. If you wish to incorporate parts of the Library into other free
|
||||||
|
programs whose distribution conditions are incompatible with these,
|
||||||
|
write to the author to ask for permission. For software which is
|
||||||
|
copyrighted by the Free Software Foundation, write to the Free
|
||||||
|
Software Foundation; we sometimes make exceptions for this. Our
|
||||||
|
decision will be guided by the two goals of preserving the free status
|
||||||
|
of all derivatives of our free software and of promoting the sharing
|
||||||
|
and reuse of software generally.
|
||||||
|
|
||||||
|
NO WARRANTY
|
||||||
|
|
||||||
|
15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
|
||||||
|
WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
|
||||||
|
EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
|
||||||
|
OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
|
||||||
|
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||||
|
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
|
||||||
|
LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
|
||||||
|
THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||||
|
|
||||||
|
16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
|
||||||
|
WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
|
||||||
|
AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
|
||||||
|
FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
|
||||||
|
CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
|
||||||
|
LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
|
||||||
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
|
||||||
|
FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
|
||||||
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
|
||||||
|
DAMAGES.
|
||||||
47
lib/ESP32Ping/README.md
Normal file
47
lib/ESP32Ping/README.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
# ESP32Ping
|
||||||
|
Let the ESP32Ping ping a remote machine.
|
||||||
|
|
||||||
|
#Note that this is a port from https://github.com/dancol90/ESP8266Ping
|
||||||
|
With this library an ESP32Ping can ping a remote machine and know if it's reachable.
|
||||||
|
It provide some basic measurements on ping messages (avg response time).
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
First, include the library in your sketch along with WiFi library:
|
||||||
|
|
||||||
|
```Arduino
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <ESP32Ping.h>
|
||||||
|
```
|
||||||
|
|
||||||
|
Next, simply call the `Ping.ping()` function
|
||||||
|
|
||||||
|
```Arduino
|
||||||
|
IPAddress ip (192, 168, 0, 1); // The remote ip to ping
|
||||||
|
bool ret = Ping.ping(ip);
|
||||||
|
```
|
||||||
|
|
||||||
|
`ret` will be true if the remote responded to pings, false if not reachable.
|
||||||
|
The library supports hostname too, just pass a string instead of the ip address:
|
||||||
|
|
||||||
|
```Arduino
|
||||||
|
bool ret = Ping.ping("www.google.com");
|
||||||
|
```
|
||||||
|
|
||||||
|
Additionally, the function accept a second integer parameter `count` that specify how many pings has to be sent:
|
||||||
|
|
||||||
|
```Arduino
|
||||||
|
bool ret = Ping.ping(ip_or_host, 10);
|
||||||
|
```
|
||||||
|
|
||||||
|
After `Ping.ping()` has been called, the average response time (in milliseconds) can be retrieved with
|
||||||
|
|
||||||
|
```Arduino
|
||||||
|
float avg_time_ms = Ping.averageTime();
|
||||||
|
```
|
||||||
|
## Fixed in 1.3
|
||||||
|
Memory leak bug ( https://github.com/marian-craciunescu/ESP32Ping/issues/4 )
|
||||||
|
## Fixed in 1.4
|
||||||
|
averageTime changed from `int` to `float`.Expect the code to still work , but you should upgrade
|
||||||
|
## Fixed in 1.5
|
||||||
|
Fixed counters data. (Any review and testing is welcomed)
|
||||||
43
lib/ESP32Ping/examples/HostPing/HostPing.ino
Normal file
43
lib/ESP32Ping/examples/HostPing/HostPing.ino
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* This example show how to ping a remote machine using it's hostname
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <ESP32Ping.h>
|
||||||
|
|
||||||
|
const char* ssid = "ssid";
|
||||||
|
const char* password = "passphrase";
|
||||||
|
|
||||||
|
const char* remote_host = "www.google.com";
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
// We start by connecting to a WiFi network
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("Connecting to WiFi");
|
||||||
|
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(100);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
Serial.print("WiFi connected with ip ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
Serial.print("Pinging host ");
|
||||||
|
Serial.println(remote_host);
|
||||||
|
|
||||||
|
if(Ping.ping(remote_host)) {
|
||||||
|
Serial.println("Success!!");
|
||||||
|
} else {
|
||||||
|
Serial.println("Error :(");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() { }
|
||||||
44
lib/ESP32Ping/examples/SimplePing/SimplePing.ino
Normal file
44
lib/ESP32Ping/examples/SimplePing/SimplePing.ino
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* With this library an ESP8266 can ping a remote machine and know if it's reachable.
|
||||||
|
* It provides some basic measurements on ping messages (avg response time).
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <WiFi.h>
|
||||||
|
#include <ESP32Ping.h>
|
||||||
|
|
||||||
|
const char* ssid = "ssid";
|
||||||
|
const char* password = "passphrase";
|
||||||
|
|
||||||
|
const IPAddress remote_ip(192, 168, 0, 1);
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
// We start by connecting to a WiFi network
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
Serial.println("Connecting to WiFi");
|
||||||
|
|
||||||
|
WiFi.begin(ssid, password);
|
||||||
|
|
||||||
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
delay(100);
|
||||||
|
Serial.print(".");
|
||||||
|
}
|
||||||
|
|
||||||
|
Serial.println();
|
||||||
|
Serial.print("WiFi connected with ip ");
|
||||||
|
Serial.println(WiFi.localIP());
|
||||||
|
|
||||||
|
Serial.print("Pinging ip ");
|
||||||
|
Serial.println(remote_ip);
|
||||||
|
|
||||||
|
if(Ping.ping(remote_ip)) {
|
||||||
|
Serial.println("Success!!");
|
||||||
|
} else {
|
||||||
|
Serial.println("Error :(");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() { }
|
||||||
26
lib/ESP32Ping/keywords.txt
Normal file
26
lib/ESP32Ping/keywords.txt
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#######################################
|
||||||
|
# Syntax Coloring Map For ESP32Ping
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Library (KEYWORD3)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
ESP32Ping KEYWORD3
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Datatypes (KEYWORD1)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
Ping KEYWORD1
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Methods and Functions (KEYWORD2)
|
||||||
|
#######################################
|
||||||
|
|
||||||
|
ping KEYWORD2
|
||||||
|
|
||||||
|
#######################################
|
||||||
|
# Constants (LITERAL1)
|
||||||
|
#######################################
|
||||||
|
|
||||||
9
lib/ESP32Ping/library.properties
Normal file
9
lib/ESP32Ping/library.properties
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
name=ESP32Ping
|
||||||
|
version=1.6
|
||||||
|
author=Daniele Colanardi,Marian Craciunescu
|
||||||
|
maintainer=marian4us2007@gmail.com
|
||||||
|
sentence=Let the ESP32 ping a remote machine.
|
||||||
|
paragraph=With this library an ESP32 can ping a remote machine and know if it's reachable. It provide some basic measurements on ping messages (avg response time).
|
||||||
|
category=Communication
|
||||||
|
url=https://github.com/marian-craciunescu/ESP32Ping
|
||||||
|
architectures=esp32
|
||||||
374
lib/ESP32Ping/ping.cpp
Normal file
374
lib/ESP32Ping/ping.cpp
Normal file
@@ -0,0 +1,374 @@
|
|||||||
|
/*
|
||||||
|
* ESP32 Ping library
|
||||||
|
*
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Permission to use, copy, modify, and distribute this software
|
||||||
|
* and its documentation for any purpose and without fee is hereby
|
||||||
|
* granted, provided that the above copyright notice appear in all
|
||||||
|
* copies and that both that the copyright notice and this
|
||||||
|
* permission notice and warranty disclaimer appear in supporting
|
||||||
|
* documentation, and that the name of the author not be used in
|
||||||
|
* advertising or publicity pertaining to distribution of the
|
||||||
|
* software without specific, written prior permission.
|
||||||
|
*
|
||||||
|
* The author disclaim all warranties with regard to this
|
||||||
|
* software, including all implied warranties of merchantability
|
||||||
|
* and fitness. In no event shall the author be liable for any
|
||||||
|
* special, indirect or consequential damages or any damages
|
||||||
|
* whatsoever resulting from loss of use, data or profits, whether
|
||||||
|
* in an action of contract, negligence or other tortious action,
|
||||||
|
* arising out of or in connection with the use or performance of
|
||||||
|
* this software.
|
||||||
|
*
|
||||||
|
* --------------------------------------------------------------------------------
|
||||||
|
* Ping Library is based on the following source code:
|
||||||
|
*
|
||||||
|
* Lua RTOS, ping utility
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Author: Jaume Oliv<69> (jolive@iberoxarxa.com / jolive@whitecatboard.org)
|
||||||
|
*
|
||||||
|
* --------------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without modification,
|
||||||
|
* are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer.
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
* 3. The name of the author may not be used to endorse or promote products
|
||||||
|
* derived from this software without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||||
|
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||||
|
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||||
|
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||||
|
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||||
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||||
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||||
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||||
|
* OF SUCH DAMAGE.
|
||||||
|
*
|
||||||
|
* This file is part of the lwIP TCP/IP stack.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
#include <float.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include "ping.h"
|
||||||
|
|
||||||
|
#include "lwip/inet_chksum.h"
|
||||||
|
#include "lwip/ip.h"
|
||||||
|
#include "lwip/ip4.h"
|
||||||
|
#include "lwip/err.h"
|
||||||
|
#include "lwip/icmp.h"
|
||||||
|
#include "lwip/sockets.h"
|
||||||
|
#include "lwip/sys.h"
|
||||||
|
#include "lwip/netdb.h"
|
||||||
|
#include "lwip/dns.h"
|
||||||
|
|
||||||
|
static uint16_t ping_seq_num;
|
||||||
|
static uint8_t stopped = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Statistics
|
||||||
|
*/
|
||||||
|
static uint32_t transmitted = 0;
|
||||||
|
static uint32_t received = 0;
|
||||||
|
static float min_time = 0;
|
||||||
|
static float max_time = 0;
|
||||||
|
static float mean_time = 0;
|
||||||
|
static float last_mean_time = 0;
|
||||||
|
static float var_time = 0;
|
||||||
|
|
||||||
|
#define PING_ID 0xAFAF
|
||||||
|
|
||||||
|
#define PING_DEFAULT_COUNT 10
|
||||||
|
#define PING_DEFAULT_INTERVAL 1
|
||||||
|
#define PING_DEFAULT_SIZE 32
|
||||||
|
#define PING_DEFAULT_TIMEOUT 1
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper functions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
static void ping_prepare_echo(struct icmp_echo_hdr *iecho, uint16_t len) {
|
||||||
|
size_t i;
|
||||||
|
size_t data_len = len - sizeof(struct icmp_echo_hdr);
|
||||||
|
|
||||||
|
ICMPH_TYPE_SET(iecho, ICMP_ECHO);
|
||||||
|
ICMPH_CODE_SET(iecho, 0);
|
||||||
|
iecho->chksum = 0;
|
||||||
|
iecho->id = PING_ID;
|
||||||
|
iecho->seqno = htons(++ping_seq_num);
|
||||||
|
|
||||||
|
/* fill the additional data buffer with some data */
|
||||||
|
for (i = 0; i < data_len; i++) {
|
||||||
|
((char*)iecho)[sizeof(struct icmp_echo_hdr) + i] = (char)i;
|
||||||
|
}
|
||||||
|
|
||||||
|
iecho->chksum = inet_chksum(iecho, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
static err_t ping_send(int s, ip4_addr_t *addr, int size) {
|
||||||
|
struct icmp_echo_hdr *iecho;
|
||||||
|
struct sockaddr_in to;
|
||||||
|
size_t ping_size = sizeof(struct icmp_echo_hdr) + size;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
iecho = (struct icmp_echo_hdr *)mem_malloc((mem_size_t)ping_size);
|
||||||
|
if (!iecho) {
|
||||||
|
mem_free(iecho);
|
||||||
|
return ERR_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
ping_prepare_echo(iecho, (uint16_t)ping_size);
|
||||||
|
|
||||||
|
to.sin_len = sizeof(to);
|
||||||
|
to.sin_family = AF_INET;
|
||||||
|
inet_addr_from_ip4addr(&to.sin_addr, addr);
|
||||||
|
|
||||||
|
if ((err = sendto(s, iecho, ping_size, 0, (struct sockaddr*)&to, sizeof(to)))) {
|
||||||
|
transmitted++;
|
||||||
|
}
|
||||||
|
mem_free(iecho);
|
||||||
|
return (err ? ERR_OK : ERR_VAL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ping_recv(int s) {
|
||||||
|
char buf[64];
|
||||||
|
int fromlen, len;
|
||||||
|
struct sockaddr_in from;
|
||||||
|
struct ip_hdr *iphdr;
|
||||||
|
struct icmp_echo_hdr *iecho = NULL;
|
||||||
|
char ipa[16];
|
||||||
|
struct timeval begin;
|
||||||
|
struct timeval end;
|
||||||
|
uint64_t micros_begin;
|
||||||
|
uint64_t micros_end;
|
||||||
|
float elapsed;
|
||||||
|
|
||||||
|
// Register begin time
|
||||||
|
gettimeofday(&begin, NULL);
|
||||||
|
|
||||||
|
// Send
|
||||||
|
while ((len = recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0) {
|
||||||
|
if (len >= (int)(sizeof(struct ip_hdr) + sizeof(struct icmp_echo_hdr))) {
|
||||||
|
// Register end time
|
||||||
|
gettimeofday(&end, NULL);
|
||||||
|
|
||||||
|
/// Get from IP address
|
||||||
|
ip4_addr_t fromaddr;
|
||||||
|
inet_addr_to_ip4addr(&fromaddr, &from.sin_addr);
|
||||||
|
|
||||||
|
strcpy(ipa, inet_ntoa(fromaddr));
|
||||||
|
|
||||||
|
// Get echo
|
||||||
|
iphdr = (struct ip_hdr *)buf;
|
||||||
|
iecho = (struct icmp_echo_hdr *)(buf + (IPH_HL(iphdr) * 4));
|
||||||
|
|
||||||
|
// Print ....
|
||||||
|
if ((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num))) {
|
||||||
|
received++;
|
||||||
|
|
||||||
|
// Get elapsed time in milliseconds
|
||||||
|
micros_begin = begin.tv_sec * 1000000;
|
||||||
|
micros_begin += begin.tv_usec;
|
||||||
|
|
||||||
|
micros_end = end.tv_sec * 1000000;
|
||||||
|
micros_end += end.tv_usec;
|
||||||
|
|
||||||
|
elapsed = (float)(micros_end - micros_begin) / (float)1000.0;
|
||||||
|
|
||||||
|
// Update statistics
|
||||||
|
// Mean and variance are computed in an incremental way
|
||||||
|
if (elapsed < min_time) {
|
||||||
|
min_time = elapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (elapsed > max_time) {
|
||||||
|
max_time = elapsed;
|
||||||
|
}
|
||||||
|
|
||||||
|
last_mean_time = mean_time;
|
||||||
|
mean_time = (((received - 1) * mean_time) + elapsed) / received;
|
||||||
|
|
||||||
|
if (received > 1) {
|
||||||
|
var_time = var_time + ((elapsed - last_mean_time) * (elapsed - mean_time));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print ...
|
||||||
|
log_d("%d bytes from %s: icmp_seq=%d time=%.3f ms\r\n", len, ipa,
|
||||||
|
ntohs(iecho->seqno), elapsed
|
||||||
|
);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
// TODO
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (len < 0) {
|
||||||
|
log_d("Request timeout for icmp_seq %d\r\n", ping_seq_num);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
static void stop_action(int i) {
|
||||||
|
signal(i, SIG_DFL);
|
||||||
|
|
||||||
|
stopped = 1;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Operation functions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
void ping(const char *name, int count, int interval, int size, int timeout) {
|
||||||
|
// Resolve name
|
||||||
|
hostent * target = gethostbyname(name);
|
||||||
|
IPAddress adr = *target->h_addr_list[0];
|
||||||
|
if (target->h_length == 0) {
|
||||||
|
// TODO: error not found target?????
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ping_start(adr, count, interval, size, timeout);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ping_start(struct ping_option *ping_o) {
|
||||||
|
|
||||||
|
|
||||||
|
return ping_start(ping_o->ip,ping_o->count,0,0,0,ping_o);
|
||||||
|
|
||||||
|
}
|
||||||
|
bool ping_start(IPAddress adr, int count=0, int interval=0, int size=0, int timeout=0, struct ping_option *ping_o) {
|
||||||
|
// driver_error_t *error;
|
||||||
|
struct sockaddr_in address;
|
||||||
|
ip4_addr_t ping_target;
|
||||||
|
int s;
|
||||||
|
// Get default values if argument are not provided
|
||||||
|
if (count == 0) {
|
||||||
|
count = PING_DEFAULT_COUNT;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (interval == 0) {
|
||||||
|
interval = PING_DEFAULT_INTERVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size == 0) {
|
||||||
|
size = PING_DEFAULT_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (timeout == 0) {
|
||||||
|
timeout = PING_DEFAULT_TIMEOUT;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create socket
|
||||||
|
if ((s = socket(AF_INET, SOCK_RAW, IP_PROTO_ICMP)) < 0) {
|
||||||
|
// TODO: error
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
address.sin_addr.s_addr = adr;
|
||||||
|
ping_target.addr = address.sin_addr.s_addr;
|
||||||
|
|
||||||
|
// Setup socket
|
||||||
|
struct timeval tout;
|
||||||
|
|
||||||
|
// Timeout
|
||||||
|
tout.tv_sec = timeout;
|
||||||
|
tout.tv_usec = 0;
|
||||||
|
|
||||||
|
if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tout, sizeof(tout)) < 0) {
|
||||||
|
closesocket(s);
|
||||||
|
// TODO: error
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
stopped = 0;
|
||||||
|
transmitted = 0;
|
||||||
|
received = 0;
|
||||||
|
min_time = 1.E+9;// FLT_MAX;
|
||||||
|
max_time = 0.0;
|
||||||
|
mean_time = 0.0;
|
||||||
|
var_time = 0.0;
|
||||||
|
|
||||||
|
// Register signal for stop ping
|
||||||
|
//signal(SIGINT, stop_action);
|
||||||
|
|
||||||
|
// Begin ping ...
|
||||||
|
char ipa[16];
|
||||||
|
|
||||||
|
strcpy(ipa, inet_ntoa(ping_target));
|
||||||
|
log_i("PING %s: %d data bytes\r\n", ipa, size);
|
||||||
|
|
||||||
|
ping_seq_num = 0;
|
||||||
|
|
||||||
|
unsigned long ping_started_time = millis();
|
||||||
|
while ((ping_seq_num < count) && (!stopped)) {
|
||||||
|
if (ping_send(s, &ping_target, size) == ERR_OK) {
|
||||||
|
ping_recv(s);
|
||||||
|
}
|
||||||
|
if(ping_seq_num < count){
|
||||||
|
delay( interval*1000L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
closesocket(s);
|
||||||
|
|
||||||
|
log_i("%d packets transmitted, %d packets received, %.1f%% packet loss\r\n",
|
||||||
|
transmitted,
|
||||||
|
received,
|
||||||
|
((((float)transmitted - (float)received) / (float)transmitted) * 100.0)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
if (ping_o) {
|
||||||
|
ping_resp pingresp;
|
||||||
|
log_i("round-trip min/avg/max/stddev = %.3f/%.3f/%.3f/%.3f ms\r\n", min_time, mean_time, max_time, sqrt(var_time / received));
|
||||||
|
pingresp.total_count = count; //Number of pings
|
||||||
|
pingresp.resp_time = mean_time; //Average time for the pings
|
||||||
|
pingresp.seqno = 0; //not relevant
|
||||||
|
pingresp.timeout_count = transmitted - received; //number of pings which failed
|
||||||
|
pingresp.bytes = size; //number of bytes received for 1 ping
|
||||||
|
pingresp.total_bytes = size * count; //number of bytes for all pings
|
||||||
|
pingresp.total_time = (millis() - ping_started_time) / 1000.0; //Time consumed for all pings; it takes into account also timeout pings
|
||||||
|
pingresp.ping_err = transmitted - received; //number of pings failed
|
||||||
|
// Call the callback function
|
||||||
|
ping_o->recv_function(ping_o, &pingresp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return true if at least one ping had a successfull "pong"
|
||||||
|
return (received > 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ping_regist_recv(struct ping_option *ping_opt, ping_recv_function ping_recv)
|
||||||
|
{
|
||||||
|
if (ping_opt == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ping_opt->recv_function = ping_recv;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ping_regist_sent(struct ping_option *ping_opt, ping_sent_function ping_sent)
|
||||||
|
{
|
||||||
|
if (ping_opt == NULL)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
ping_opt->sent_function = ping_sent;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
34
lib/ESP32Ping/ping.h
Normal file
34
lib/ESP32Ping/ping.h
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#ifndef PING_H
|
||||||
|
#define PING_H
|
||||||
|
#include <Arduino.h>
|
||||||
|
|
||||||
|
typedef void(*ping_recv_function)(void* arg, void *pdata);
|
||||||
|
typedef void(*ping_sent_function)(void* arg, void *pdata);
|
||||||
|
|
||||||
|
struct ping_option {
|
||||||
|
uint32_t count;
|
||||||
|
uint32_t ip;
|
||||||
|
uint32_t coarse_time;
|
||||||
|
ping_recv_function recv_function;
|
||||||
|
ping_sent_function sent_function;
|
||||||
|
void* reverse;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ping_resp {
|
||||||
|
uint32_t total_count;
|
||||||
|
float resp_time;
|
||||||
|
uint32_t seqno;
|
||||||
|
uint32_t timeout_count;
|
||||||
|
uint32_t bytes;
|
||||||
|
uint32_t total_bytes;
|
||||||
|
float total_time;
|
||||||
|
int8_t ping_err;
|
||||||
|
};
|
||||||
|
|
||||||
|
bool ping_start(struct ping_option *ping_opt);
|
||||||
|
void ping(const char *name, int count, int interval, int size, int timeout);
|
||||||
|
bool ping_start(IPAddress adr, int count, int interval, int size, int timeout, struct ping_option *ping_o = NULL);
|
||||||
|
|
||||||
|
#endif // PING_H
|
||||||
@@ -5,7 +5,7 @@
|
|||||||
#define NUKI_HUB_VERSION "9.12"
|
#define NUKI_HUB_VERSION "9.12"
|
||||||
#define NUKI_HUB_VERSION_INT (uint32_t)912
|
#define NUKI_HUB_VERSION_INT (uint32_t)912
|
||||||
#define NUKI_HUB_BUILD "unknownbuildnr"
|
#define NUKI_HUB_BUILD "unknownbuildnr"
|
||||||
#define NUKI_HUB_DATE "2025-09-09"
|
#define NUKI_HUB_DATE "2025-09-10"
|
||||||
|
|
||||||
#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
|
#define GITHUB_LATEST_RELEASE_URL (char*)"https://github.com/technyon/nuki_hub/releases/latest"
|
||||||
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"
|
#define GITHUB_OTA_MANIFEST_URL (char*)"https://raw.githubusercontent.com/technyon/nuki_hub/binary/ota/manifest.json"
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
#include "networkDevices/EthernetDevice.h"
|
#include "networkDevices/EthernetDevice.h"
|
||||||
#include "hal/wdt_hal.h"
|
#include "hal/wdt_hal.h"
|
||||||
#include "esp_mac.h"
|
#include "esp_mac.h"
|
||||||
|
#include <ESP32Ping.h>
|
||||||
|
|
||||||
NukiNetwork* NukiNetwork::_inst = nullptr;
|
NukiNetwork* NukiNetwork::_inst = nullptr;
|
||||||
|
|
||||||
@@ -154,6 +155,11 @@ bool NukiNetwork::isConnected()
|
|||||||
return _device->isConnected();
|
return _device->isConnected();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool NukiNetwork::isInternetConnected()
|
||||||
|
{
|
||||||
|
return _hasInternet;
|
||||||
|
}
|
||||||
|
|
||||||
bool NukiNetwork::mqttConnected()
|
bool NukiNetwork::mqttConnected()
|
||||||
{
|
{
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
@@ -297,7 +303,8 @@ void NukiNetwork::readSettings()
|
|||||||
_checkUpdates = _preferences->getBool(preference_check_updates, false);
|
_checkUpdates = _preferences->getBool(preference_check_updates, false);
|
||||||
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval, 0) * 1000;
|
_rssiPublishInterval = _preferences->getInt(preference_rssi_publish_interval, 0) * 1000;
|
||||||
_retainGpio = _preferences->getBool(preference_retain_gpio, false);
|
_retainGpio = _preferences->getBool(preference_retain_gpio, false);
|
||||||
|
_haEnabled = _preferences->getBool(preference_mqtt_hass_enabled, false);
|
||||||
|
|
||||||
if(_rssiPublishInterval == 0)
|
if(_rssiPublishInterval == 0)
|
||||||
{
|
{
|
||||||
_rssiPublishInterval = 60000;
|
_rssiPublishInterval = 60000;
|
||||||
@@ -469,6 +476,8 @@ bool NukiNetwork::update()
|
|||||||
Log->print("IP: ");
|
Log->print("IP: ");
|
||||||
Log->println(_device->localIP());
|
Log->println(_device->localIP());
|
||||||
_firstDisconnected = true;
|
_firstDisconnected = true;
|
||||||
|
|
||||||
|
checkInternetConnectivity();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!_logIp && _device->isConnected() && !_device->mqttConnected() )
|
if(!_logIp && _device->isConnected() && !_device->mqttConnected() )
|
||||||
@@ -575,7 +584,7 @@ bool NukiNetwork::update()
|
|||||||
_lastMaintenanceTs = ts;
|
_lastMaintenanceTs = ts;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_checkUpdates)
|
if(_checkUpdates && (!_haEnabled || (_haEnabled && _haSetupDone)) && _hasInternet)
|
||||||
{
|
{
|
||||||
if(_lastUpdateCheckTs == 0 || (ts - _lastUpdateCheckTs) > 86400000)
|
if(_lastUpdateCheckTs == 0 || (ts - _lastUpdateCheckTs) > 86400000)
|
||||||
{
|
{
|
||||||
@@ -665,6 +674,11 @@ bool NukiNetwork::update()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NukiNetwork::checkInternetConnectivity()
|
||||||
|
{
|
||||||
|
_hasInternet = Ping.ping("github.com", 3);
|
||||||
|
}
|
||||||
|
|
||||||
void NukiNetwork::onMqttConnect(const bool &sessionPresent)
|
void NukiNetwork::onMqttConnect(const bool &sessionPresent)
|
||||||
{
|
{
|
||||||
_connectReplyReceived = true;
|
_connectReplyReceived = true;
|
||||||
@@ -849,6 +863,7 @@ bool NukiNetwork::reconnect(bool force)
|
|||||||
if(_preferences->getBool(preference_mqtt_hass_enabled, false))
|
if(_preferences->getBool(preference_mqtt_hass_enabled, false))
|
||||||
{
|
{
|
||||||
setupHASS(0, 0, {0}, {0}, {0}, false, false);
|
setupHASS(0, 0, {0}, {0}, {0}, false, false);
|
||||||
|
_haSetupDone = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
initTopic(_maintenancePathPrefix, mqtt_topic_reset, "0");
|
initTopic(_maintenancePathPrefix, mqtt_topic_reset, "0");
|
||||||
@@ -1029,7 +1044,7 @@ void NukiNetwork::onMqttDataReceived(const char* topic, byte* payload, const uns
|
|||||||
vTaskDelay(200 / portTICK_PERIOD_MS);
|
vTaskDelay(200 / portTICK_PERIOD_MS);
|
||||||
restartEsp(RestartReason::RequestedViaMqtt);
|
restartEsp(RestartReason::RequestedViaMqtt);
|
||||||
}
|
}
|
||||||
else if(comparePrefixedPath(topic, mqtt_topic_update) && strcmp(data, "1") == 0 && _preferences->getBool(preference_update_from_mqtt, false) && !mqttRecentlyConnected())
|
else if(comparePrefixedPath(topic, mqtt_topic_update) && strcmp(data, "1") == 0 && _preferences->getBool(preference_update_from_mqtt, false) && !mqttRecentlyConnected() && _hasInternet)
|
||||||
{
|
{
|
||||||
Log->println("Update requested via MQTT.");
|
Log->println("Update requested via MQTT.");
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public:
|
|||||||
void scan(bool passive = false, bool async = true);
|
void scan(bool passive = false, bool async = true);
|
||||||
bool isApOpen();
|
bool isApOpen();
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
|
bool isInternetConnected();
|
||||||
bool mqttConnected();
|
bool mqttConnected();
|
||||||
bool wifiConnected();
|
bool wifiConnected();
|
||||||
void clearWifiFallback();
|
void clearWifiFallback();
|
||||||
@@ -114,6 +115,7 @@ private:
|
|||||||
NetworkDeviceType _networkDeviceType = (NetworkDeviceType)-1;
|
NetworkDeviceType _networkDeviceType = (NetworkDeviceType)-1;
|
||||||
bool _firstBootAfterDeviceChange = false;
|
bool _firstBootAfterDeviceChange = false;
|
||||||
bool _webEnabled = true;
|
bool _webEnabled = true;
|
||||||
|
bool _hasInternet = false;
|
||||||
|
|
||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
static void onMqttDataReceivedCallback(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
|
static void onMqttDataReceivedCallback(const espMqttClientTypes::MessageProperties& properties, const char* topic, const uint8_t* payload, size_t len, size_t index, size_t total);
|
||||||
@@ -126,6 +128,7 @@ private:
|
|||||||
bool comparePrefixedPath(const char* fullPath, const char* subPath);
|
bool comparePrefixedPath(const char* fullPath, const char* subPath);
|
||||||
void buildMqttPath(const char *path, char *outPath);
|
void buildMqttPath(const char *path, char *outPath);
|
||||||
void buildMqttPath(char* outPath, std::initializer_list<const char*> paths);
|
void buildMqttPath(char* outPath, std::initializer_list<const char*> paths);
|
||||||
|
void checkInternetConnectivity();
|
||||||
|
|
||||||
const char* _lastWillPayload = "offline";
|
const char* _lastWillPayload = "offline";
|
||||||
char _mqttConnectionStateTopic[211] = {0};
|
char _mqttConnectionStateTopic[211] = {0};
|
||||||
@@ -159,6 +162,8 @@ private:
|
|||||||
bool _publishDebugInfo = false;
|
bool _publishDebugInfo = false;
|
||||||
bool _logIp = true;
|
bool _logIp = true;
|
||||||
bool _retainGpio = false;
|
bool _retainGpio = false;
|
||||||
|
bool _haEnabled = false;
|
||||||
|
bool _haSetupDone = false;
|
||||||
std::vector<String> _subscribedTopics;
|
std::vector<String> _subscribedTopics;
|
||||||
std::map<String, String> _initTopics;
|
std::map<String, String> _initTopics;
|
||||||
int64_t _lastConnectedTs = 0;
|
int64_t _lastConnectedTs = 0;
|
||||||
|
|||||||
@@ -1813,33 +1813,36 @@ esp_err_t WebCfgServer::buildOtaHtml(PsychicRequest *request, PsychicResponse* r
|
|||||||
#ifndef NUKI_HUB_UPDATER
|
#ifndef NUKI_HUB_UPDATER
|
||||||
bool manifestSuccess = false;
|
bool manifestSuccess = false;
|
||||||
JsonDocument doc;
|
JsonDocument doc;
|
||||||
|
|
||||||
NetworkClientSecure *clientOTAUpdate = new NetworkClientSecure;
|
if(_network->isInternetConnected())
|
||||||
if (clientOTAUpdate)
|
|
||||||
{
|
{
|
||||||
clientOTAUpdate->setCACertBundle(x509_crt_imported_bundle_bin_start, x509_crt_imported_bundle_bin_end - x509_crt_imported_bundle_bin_start);
|
NetworkClientSecure *clientOTAUpdate = new NetworkClientSecure;
|
||||||
|
if (clientOTAUpdate)
|
||||||
{
|
{
|
||||||
HTTPClient httpsOTAClient;
|
clientOTAUpdate->setCACertBundle(x509_crt_imported_bundle_bin_start, x509_crt_imported_bundle_bin_end - x509_crt_imported_bundle_bin_start);
|
||||||
httpsOTAClient.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
|
||||||
httpsOTAClient.setTimeout(2500);
|
|
||||||
httpsOTAClient.useHTTP10(true);
|
|
||||||
|
|
||||||
if (httpsOTAClient.begin(*clientOTAUpdate, GITHUB_OTA_MANIFEST_URL))
|
|
||||||
{
|
{
|
||||||
int httpResponseCodeOTA = httpsOTAClient.GET();
|
HTTPClient httpsOTAClient;
|
||||||
|
httpsOTAClient.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
|
||||||
|
httpsOTAClient.setTimeout(2500);
|
||||||
|
httpsOTAClient.useHTTP10(true);
|
||||||
|
|
||||||
if (httpResponseCodeOTA == HTTP_CODE_OK || httpResponseCodeOTA == HTTP_CODE_MOVED_PERMANENTLY)
|
if (httpsOTAClient.begin(*clientOTAUpdate, GITHUB_OTA_MANIFEST_URL))
|
||||||
{
|
{
|
||||||
DeserializationError jsonError = deserializeJson(doc, httpsOTAClient.getStream());
|
int httpResponseCodeOTA = httpsOTAClient.GET();
|
||||||
if (!jsonError)
|
|
||||||
|
if (httpResponseCodeOTA == HTTP_CODE_OK || httpResponseCodeOTA == HTTP_CODE_MOVED_PERMANENTLY)
|
||||||
{
|
{
|
||||||
manifestSuccess = true;
|
DeserializationError jsonError = deserializeJson(doc, httpsOTAClient.getStream());
|
||||||
|
if (!jsonError)
|
||||||
|
{
|
||||||
|
manifestSuccess = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
httpsOTAClient.end();
|
||||||
}
|
}
|
||||||
httpsOTAClient.end();
|
|
||||||
}
|
}
|
||||||
|
delete clientOTAUpdate;
|
||||||
}
|
}
|
||||||
delete clientOTAUpdate;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
response.print("<div id=\"msgdiv\" style=\"visibility:hidden\">Initiating Over-the-air update. This will take about two minutes, please be patient.<br>You will be forwarded automatically when the update is complete.</div>");
|
response.print("<div id=\"msgdiv\" style=\"visibility:hidden\">Initiating Over-the-air update. This will take about two minutes, please be patient.<br>You will be forwarded automatically when the update is complete.</div>");
|
||||||
@@ -6365,6 +6368,9 @@ esp_err_t WebCfgServer::buildInfoHtml(PsychicRequest *request, PsychicResponse*
|
|||||||
response.print(_network->isConnected() ? "Yes" : "No");
|
response.print(_network->isConnected() ? "Yes" : "No");
|
||||||
if(_network->isConnected())
|
if(_network->isConnected())
|
||||||
{
|
{
|
||||||
|
response.print("\nInternet connected: ");
|
||||||
|
response.print(_network->isInternetConnected() ? "Yes" : "No");
|
||||||
|
|
||||||
response.print("\nIP Address: ");
|
response.print("\nIP Address: ");
|
||||||
response.print(_network->localIP());
|
response.print(_network->localIP());
|
||||||
|
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ lib_deps =
|
|||||||
DuoAuthLibrary=symlink://../lib/DuoAuthLibrary
|
DuoAuthLibrary=symlink://../lib/DuoAuthLibrary
|
||||||
Arduino-Base32-Decode=symlink://../lib/Arduino-Base32-Decode
|
Arduino-Base32-Decode=symlink://../lib/Arduino-Base32-Decode
|
||||||
Arduino-TOTP-RFC6238-generator=symlink://../lib/Arduino-TOTP-RFC6238-generator
|
Arduino-TOTP-RFC6238-generator=symlink://../lib/Arduino-TOTP-RFC6238-generator
|
||||||
|
ESP32Ping=symlink://../lib/ESP32Ping
|
||||||
monitor_speed = 115200
|
monitor_speed = 115200
|
||||||
monitor_filters =
|
monitor_filters =
|
||||||
esp32_exception_decoder
|
esp32_exception_decoder
|
||||||
|
|||||||
Reference in New Issue
Block a user