Compare commits

...

12 Commits

Author SHA1 Message Date
6bf104874a Add LGPL 2.1 License 2019-04-16 03:08:50 +02:00
9a9ff62216 Add connect with timeout to Client class 2019-04-15 18:01:43 +02:00
3d6e4e1b94 Use milliseconds for timeout 2019-04-15 17:27:54 +02:00
01d7ea7b80 Refactored use of LOG_X(LOG_TAG, ...) to log_x(...) (#2672)
* Replaced ARDUINO_VARIANT with const char

* Fixed missing return value

* Added quotes around defined value in macro (Issue #2193)

* Change logging from Error to Verbose when not found and default available

* Move Enter and Exit logging to Verbose Level

* Refactored LOG_X() into log_x()
2019-04-15 17:26:35 +02:00
Bob
af23d0bb10 Return empty string instead of "0" (#2673) 2019-04-15 17:23:42 +02:00
582e6433e9 Add proper timeout handling to WiFiClientSecure 2019-04-15 17:19:49 +02:00
ef07a84ade Update esp32-camera driver 2019-04-13 22:52:21 +02:00
ea043cdb14 Fix WiFi Multi not clearing password 2019-04-13 17:19:06 +02:00
c60092951f Add missing definitions 2019-04-13 17:18:25 +02:00
fa74767b2e Allow selecting in IDF the running core for Arduino's core tasks 2019-04-13 17:13:13 +02:00
d922557e01 Set default Serial1 pins for Adafruit Feather 32 2019-04-13 13:28:16 +02:00
33d4186b35 Add board "SparkFun LoRa Gateway 1-Channel". (#2664)
* Add board "SparkFun LoRa Gateway 1-Channel".

* Extend boards.txt.

Source: https://learn.sparkfun.com/tutorials/sparkfun-lora-gateway-1-channel-hookup-guide/all
2019-04-13 12:26:35 +02:00
41 changed files with 1181 additions and 553 deletions

View File

@ -19,6 +19,70 @@ config AUTOSTART_ARDUINO
If disabled, you can call initArduino() to run any preparations
required by the framework
choice ARDUINO_RUNNING_CORE
bool "Core on which Arduino's setup() and loop() are running"
default ARDUINO_RUN_CORE1
help
Select on which core Arduino's setup() and loop() functions run
config ARDUINO_RUN_CORE0
bool "CORE 0"
config ARDUINO_RUN_CORE1
bool "CORE 1"
config ARDUINO_RUN_NO_AFFINITY
bool "BOTH"
endchoice
config ARDUINO_RUNNING_CORE
int
default 0 if ARDUINO_RUN_CORE0
default 1 if ARDUINO_RUN_CORE1
default -1 if ARDUINO_RUN_NO_AFFINITY
choice ARDUINO_EVENT_RUNNING_CORE
bool "Core on which Arduino's event handler is running"
default ARDUINO_EVENT_RUN_CORE1
help
Select on which core Arduino's WiFi.onEvent() run
config ARDUINO_EVENT_RUN_CORE0
bool "CORE 0"
config ARDUINO_EVENT_RUN_CORE1
bool "CORE 1"
config ARDUINO_EVENT_RUN_NO_AFFINITY
bool "BOTH"
endchoice
config ARDUINO_EVENT_RUNNING_CORE
int
default 0 if ARDUINO_EVENT_RUN_CORE0
default 1 if ARDUINO_EVENT_RUN_CORE1
default -1 if ARDUINO_EVENT_RUN_NO_AFFINITY
choice ARDUINO_UDP_RUNNING_CORE
bool "Core on which Arduino's UDP is running"
default ARDUINO_UDP_RUN_CORE1
help
Select on which core Arduino's UDP run
config ARDUINO_UDP_RUN_CORE0
bool "CORE 0"
config ARDUINO_UDP_RUN_CORE1
bool "CORE 1"
config ARDUINO_UDP_RUN_NO_AFFINITY
bool "BOTH"
endchoice
config ARDUINO_UDP_RUNNING_CORE
int
default 0 if ARDUINO_UDP_RUN_CORE0
default 1 if ARDUINO_UDP_RUN_CORE1
default -1 if ARDUINO_UDP_RUN_NO_AFFINITY
config DISABLE_HAL_LOCKS
bool "Disable mutex locks for HAL"
default "n"

503
LICENSE.md Normal file
View File

@ -0,0 +1,503 @@
### 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.
### 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.
### END OF TERMS AND CONDITIONS
### How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
possible use to the public, we recommend making it free software that
everyone can redistribute and change. You can do so by permitting
redistribution under these terms (or, alternatively, under the terms
of the ordinary General Public License).
To apply these terms, attach the following notices to the library. It
is safest to attach them to the start of each source file to most
effectively convey the exclusion of warranty; and each file should
have at least the "copyright" line and a pointer to where the full
notice is found.
one line to give the library's name and an idea of what it does.
Copyright (C) year name of author
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 Street, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper
mail.
You should also get your employer (if you work as a programmer) or
your school, if any, to sign a "copyright disclaimer" for the library,
if necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in
the library `Frob' (a library for tweaking knobs) written
by James Random Hacker.
signature of Ty Coon, 1 April 1990
Ty Coon, President of Vice
That's all there is to it!

View File

@ -3451,4 +3451,75 @@ esp32cam.build.code_debug=0
##############################################################
sparkfun_lora_gateway_1-channel.name=SparkFun LoRa Gateway 1-Channel
sparkfun_lora_gateway_1-channel.upload.tool=esptool_py
sparkfun_lora_gateway_1-channel.upload.maximum_size=1310720
sparkfun_lora_gateway_1-channel.upload.maximum_data_size=294912
sparkfun_lora_gateway_1-channel.upload.wait_for_upload_port=true
sparkfun_lora_gateway_1-channel.serial.disableDTR=true
sparkfun_lora_gateway_1-channel.serial.disableRTS=true
sparkfun_lora_gateway_1-channel.build.mcu=esp32
sparkfun_lora_gateway_1-channel.build.core=esp32
sparkfun_lora_gateway_1-channel.build.variant=sparkfun_lora_gateway_1-channel
sparkfun_lora_gateway_1-channel.build.board=ESP32_DEV
sparkfun_lora_gateway_1-channel.build.f_cpu=240000000L
sparkfun_lora_gateway_1-channel.build.flash_size=4MB
sparkfun_lora_gateway_1-channel.build.flash_freq=40m
sparkfun_lora_gateway_1-channel.build.flash_mode=dio
sparkfun_lora_gateway_1-channel.build.boot=dio
sparkfun_lora_gateway_1-channel.build.partitions=default
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.default=Default
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.default.build.partitions=default
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.minimal=Minimal (2MB FLASH)
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.minimal.build.partitions=minimal
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.no_ota=No OTA (Large APP)
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.no_ota.build.partitions=no_ota
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.no_ota.upload.maximum_size=2097152
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.min_spiffs=Minimal SPIFFS (Large APPS with OTA)
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.min_spiffs.build.partitions=min_spiffs
sparkfun_lora_gateway_1-channel.menu.PartitionScheme.min_spiffs.upload.maximum_size=1966080
sparkfun_lora_gateway_1-channel.menu.FlashMode.qio=QIO
sparkfun_lora_gateway_1-channel.menu.FlashMode.qio.build.flash_mode=dio
sparkfun_lora_gateway_1-channel.menu.FlashMode.qio.build.boot=qio
sparkfun_lora_gateway_1-channel.menu.FlashMode.dio=DIO
sparkfun_lora_gateway_1-channel.menu.FlashMode.dio.build.flash_mode=dio
sparkfun_lora_gateway_1-channel.menu.FlashMode.dio.build.boot=dio
sparkfun_lora_gateway_1-channel.menu.FlashMode.qout=QOUT
sparkfun_lora_gateway_1-channel.menu.FlashMode.qout.build.flash_mode=dout
sparkfun_lora_gateway_1-channel.menu.FlashMode.qout.build.boot=qout
sparkfun_lora_gateway_1-channel.menu.FlashMode.dout=DOUT
sparkfun_lora_gateway_1-channel.menu.FlashMode.dout.build.flash_mode=dout
sparkfun_lora_gateway_1-channel.menu.FlashMode.dout.build.boot=dout
sparkfun_lora_gateway_1-channel.menu.FlashFreq.80=80MHz
sparkfun_lora_gateway_1-channel.menu.FlashFreq.80.build.flash_freq=80m
sparkfun_lora_gateway_1-channel.menu.FlashFreq.40=40MHz
sparkfun_lora_gateway_1-channel.menu.FlashFreq.40.build.flash_freq=40m
sparkfun_lora_gateway_1-channel.menu.FlashSize.4M=4MB (32Mb)
sparkfun_lora_gateway_1-channel.menu.FlashSize.4M.build.flash_size=4MB
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.921600=921600
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.921600.upload.speed=921600
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.115200=115200
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.115200.upload.speed=115200
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.256000.windows=256000
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.256000.upload.speed=256000
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.230400.windows.upload.speed=256000
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.230400=230400
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.230400.upload.speed=230400
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.460800.linux=460800
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.460800.macosx=460800
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.460800.upload.speed=460800
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.512000.windows=512000
sparkfun_lora_gateway_1-channel.menu.UploadSpeed.512000.upload.speed=512000
##############################################################

View File

@ -28,6 +28,8 @@ class Client: public Stream
public:
virtual int connect(IPAddress ip, uint16_t port) =0;
virtual int connect(const char *host, uint16_t port) =0;
virtual int connect(IPAddress ip, uint16_t port, int timeout) =0;
virtual int connect(const char *host, uint16_t port, int timeout) =0;
virtual size_t write(uint8_t) =0;
virtual size_t write(const uint8_t *buf, size_t size) =0;
virtual int available() = 0;

View File

@ -111,6 +111,24 @@ void disableCore1WDT(){
}
#endif
BaseType_t xTaskCreateUniversal( TaskFunction_t pxTaskCode,
const char * const pcName,
const uint32_t usStackDepth,
void * const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t * const pxCreatedTask,
const BaseType_t xCoreID ){
#ifndef CONFIG_FREERTOS_UNICORE
if(xCoreID >= 0 && xCoreID < 2) {
return xTaskCreatePinnedToCore(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask, xCoreID);
} else {
#endif
return xTaskCreate(pxTaskCode, pcName, usStackDepth, pvParameters, uxPriority, pxCreatedTask);
#ifndef CONFIG_FREERTOS_UNICORE
}
#endif
}
unsigned long IRAM_ATTR micros()
{
return (unsigned long) (esp_timer_get_time());

View File

@ -90,6 +90,16 @@ void enableCore1WDT();
void disableCore1WDT();
#endif
//if xCoreID < 0 or CPU is unicore, it will use xTaskCreate, else xTaskCreatePinnedToCore
//allows to easily handle all possible situations without repetitive code
BaseType_t xTaskCreateUniversal( TaskFunction_t pxTaskCode,
const char * const pcName,
const uint32_t usStackDepth,
void * const pvParameters,
UBaseType_t uxPriority,
TaskHandle_t * const pxCreatedTask,
const BaseType_t xCoreID );
unsigned long micros();
unsigned long millis();
void delay(uint32_t);

View File

@ -7,12 +7,6 @@ TaskHandle_t loopTaskHandle = NULL;
#if CONFIG_AUTOSTART_ARDUINO
#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif
bool loopTaskWDTEnabled;
void loopTask(void *pvParameters)
@ -30,7 +24,7 @@ extern "C" void app_main()
{
loopTaskWDTEnabled = false;
initArduino();
xTaskCreatePinnedToCore(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, ARDUINO_RUNNING_CORE);
xTaskCreateUniversal(loopTask, "loopTask", 8192, NULL, 1, &loopTaskHandle, CONFIG_ARDUINO_RUNNING_CORE);
}
#endif

View File

@ -150,7 +150,7 @@ static bool _udp_task_start(){
}
}
if(!_udp_task_handle){
xTaskCreate(_udp_task, "async_udp", 4096, NULL, 3, (TaskHandle_t*)&_udp_task_handle);
xTaskCreateUniversal(_udp_task, "async_udp", 4096, NULL, 3, (TaskHandle_t*)&_udp_task_handle, CONFIG_ARDUINO_UDP_RUNNING_CORE);
if(!_udp_task_handle){
return false;
}

View File

@ -16,13 +16,7 @@
#include <sstream>
#include "BLEAdvertisedDevice.h"
#include "BLEUtils.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG="BLEAdvertisedDevice";
#endif
BLEAdvertisedDevice::BLEAdvertisedDevice() {
m_adFlag = 0;
@ -249,7 +243,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
length--;
char* pHex = BLEUtils::buildHexData(nullptr, payload, length);
ESP_LOGD(LOG_TAG, "Type: 0x%.2x (%s), length: %d, data: %s",
log_d("Type: 0x%.2x (%s), length: %d, data: %s",
ad_type, BLEUtils::advTypeToString(ad_type), length, pHex);
free(pHex);
@ -308,7 +302,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
case ESP_BLE_AD_TYPE_SERVICE_DATA: { // Adv Data Type: 0x16 (Service Data) - 2 byte UUID
if (length < 2) {
ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA");
log_e("Length too small for ESP_BLE_AD_TYPE_SERVICE_DATA");
break;
}
uint16_t uuid = *(uint16_t*)payload;
@ -321,7 +315,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
case ESP_BLE_AD_TYPE_32SERVICE_DATA: { // Adv Data Type: 0x20 (Service Data) - 4 byte UUID
if (length < 4) {
ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA");
log_e("Length too small for ESP_BLE_AD_TYPE_32SERVICE_DATA");
break;
}
uint32_t uuid = *(uint32_t*) payload;
@ -334,7 +328,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
case ESP_BLE_AD_TYPE_128SERVICE_DATA: { // Adv Data Type: 0x21 (Service Data) - 16 byte UUID
if (length < 16) {
ESP_LOGE(LOG_TAG, "Length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA");
log_e("Length too small for ESP_BLE_AD_TYPE_128SERVICE_DATA");
break;
}
@ -346,7 +340,7 @@ void BLEAdvertisedDevice::parseAdvertisement(uint8_t* payload, size_t total_len)
} //ESP_BLE_AD_TYPE_32SERVICE_DATA
default: {
ESP_LOGD(LOG_TAG, "Unhandled type: adType: %d - 0x%.2x", ad_type, ad_type);
log_d("Unhandled type: adType: %d - 0x%.2x", ad_type, ad_type);
break;
}
} // switch
@ -386,7 +380,7 @@ void BLEAdvertisedDevice::setAdFlag(uint8_t adFlag) {
void BLEAdvertisedDevice::setAppearance(uint16_t appearance) {
m_appearance = appearance;
m_haveAppearance = true;
ESP_LOGD(LOG_TAG, "- appearance: %d", m_appearance);
log_d("- appearance: %d", m_appearance);
} // setAppearance
@ -398,7 +392,7 @@ void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) {
m_manufacturerData = manufacturerData;
m_haveManufacturerData = true;
char* pHex = BLEUtils::buildHexData(nullptr, (uint8_t*) m_manufacturerData.data(), (uint8_t) m_manufacturerData.length());
ESP_LOGD(LOG_TAG, "- manufacturer data: %s", pHex);
log_d("- manufacturer data: %s", pHex);
free(pHex);
} // setManufacturerData
@ -410,7 +404,7 @@ void BLEAdvertisedDevice::setManufacturerData(std::string manufacturerData) {
void BLEAdvertisedDevice::setName(std::string name) {
m_name = name;
m_haveName = true;
ESP_LOGD(LOG_TAG, "- setName(): name: %s", m_name.c_str());
log_d("- setName(): name: %s", m_name.c_str());
} // setName
@ -421,7 +415,7 @@ void BLEAdvertisedDevice::setName(std::string name) {
void BLEAdvertisedDevice::setRSSI(int rssi) {
m_rssi = rssi;
m_haveRSSI = true;
ESP_LOGD(LOG_TAG, "- setRSSI(): rssi: %d", m_rssi);
log_d("- setRSSI(): rssi: %d", m_rssi);
} // setRSSI
@ -450,7 +444,7 @@ void BLEAdvertisedDevice::setServiceUUID(const char* serviceUUID) {
void BLEAdvertisedDevice::setServiceUUID(BLEUUID serviceUUID) {
m_serviceUUIDs.push_back(serviceUUID);
m_haveServiceUUID = true;
ESP_LOGD(LOG_TAG, "- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str());
log_d("- addServiceUUID(): serviceUUID: %s", serviceUUID.toString().c_str());
} // setServiceUUID
@ -481,7 +475,7 @@ void BLEAdvertisedDevice::setServiceDataUUID(BLEUUID uuid) {
void BLEAdvertisedDevice::setTXPower(int8_t txPower) {
m_txPower = txPower;
m_haveTXPower = true;
ESP_LOGD(LOG_TAG, "- txPower: %d", m_txPower);
log_d("- txPower: %d", m_txPower);
} // setTXPower

View File

@ -22,16 +22,7 @@
#include <esp_err.h>
#include "BLEUtils.h"
#include "GeneralUtils.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEAdvertising";
#endif
/**
* @brief Construct a default advertising object.
@ -120,25 +111,25 @@ void BLEAdvertising::setScanResponse(bool set) {
* @param [in] connectWhitelistOnly If true, only allow connections from those on the white list.
*/
void BLEAdvertising::setScanFilter(bool scanRequestWhitelistOnly, bool connectWhitelistOnly) {
ESP_LOGD(LOG_TAG, ">> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d", scanRequestWhitelistOnly, connectWhitelistOnly);
log_v(">> setScanFilter: scanRequestWhitelistOnly: %d, connectWhitelistOnly: %d", scanRequestWhitelistOnly, connectWhitelistOnly);
if (!scanRequestWhitelistOnly && !connectWhitelistOnly) {
m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_ANY;
ESP_LOGD(LOG_TAG, "<< setScanFilter");
log_v("<< setScanFilter");
return;
}
if (scanRequestWhitelistOnly && !connectWhitelistOnly) {
m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_ANY;
ESP_LOGD(LOG_TAG, "<< setScanFilter");
log_v("<< setScanFilter");
return;
}
if (!scanRequestWhitelistOnly && connectWhitelistOnly) {
m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_ANY_CON_WLST;
ESP_LOGD(LOG_TAG, "<< setScanFilter");
log_v("<< setScanFilter");
return;
}
if (scanRequestWhitelistOnly && connectWhitelistOnly) {
m_advParams.adv_filter_policy = ADV_FILTER_ALLOW_SCAN_WLST_CON_WLST;
ESP_LOGD(LOG_TAG, "<< setScanFilter");
log_v("<< setScanFilter");
return;
}
} // setScanFilter
@ -149,15 +140,15 @@ void BLEAdvertising::setScanFilter(bool scanRequestWhitelistOnly, bool connectWh
* @param [in] advertisementData The data to be advertised.
*/
void BLEAdvertising::setAdvertisementData(BLEAdvertisementData& advertisementData) {
ESP_LOGD(LOG_TAG, ">> setAdvertisementData");
log_v(">> setAdvertisementData");
esp_err_t errRc = ::esp_ble_gap_config_adv_data_raw(
(uint8_t*)advertisementData.getPayload().data(),
advertisementData.getPayload().length());
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_config_adv_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_config_adv_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc));
}
m_customAdvData = true; // Set the flag that indicates we are using custom advertising data.
ESP_LOGD(LOG_TAG, "<< setAdvertisementData");
log_v("<< setAdvertisementData");
} // setAdvertisementData
@ -166,15 +157,15 @@ void BLEAdvertising::setAdvertisementData(BLEAdvertisementData& advertisementDat
* @param [in] advertisementData The data to be advertised.
*/
void BLEAdvertising::setScanResponseData(BLEAdvertisementData& advertisementData) {
ESP_LOGD(LOG_TAG, ">> setScanResponseData");
log_v(">> setScanResponseData");
esp_err_t errRc = ::esp_ble_gap_config_scan_rsp_data_raw(
(uint8_t*)advertisementData.getPayload().data(),
advertisementData.getPayload().length());
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_config_scan_rsp_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_config_scan_rsp_data_raw: %d %s", errRc, GeneralUtils::errorToString(errRc));
}
m_customScanResponseData = true; // Set the flag that indicates we are using custom scan response data.
ESP_LOGD(LOG_TAG, "<< setScanResponseData");
log_v("<< setScanResponseData");
} // setScanResponseData
/**
@ -183,7 +174,7 @@ void BLEAdvertising::setScanResponseData(BLEAdvertisementData& advertisementData
* @return N/A.
*/
void BLEAdvertising::start() {
ESP_LOGD(LOG_TAG, ">> start: customAdvData: %d, customScanResponseData: %d", m_customAdvData, m_customScanResponseData);
log_v(">> start: customAdvData: %d, customScanResponseData: %d", m_customAdvData, m_customScanResponseData);
// We have a vector of service UUIDs that we wish to advertise. In order to use the
// ESP-IDF framework, these must be supplied in a contiguous array of their 128bit (16 byte)
@ -195,14 +186,14 @@ void BLEAdvertising::start() {
m_advData.p_service_uuid = new uint8_t[m_advData.service_uuid_len];
uint8_t* p = m_advData.p_service_uuid;
for (int i = 0; i < numServices; i++) {
ESP_LOGD(LOG_TAG, "- advertising service: %s", m_serviceUUIDs[i].toString().c_str());
log_d("- advertising service: %s", m_serviceUUIDs[i].toString().c_str());
BLEUUID serviceUUID128 = m_serviceUUIDs[i].to128();
memcpy(p, serviceUUID128.getNative()->uuid.uuid128, 16);
p += 16;
}
} else {
m_advData.service_uuid_len = 0;
ESP_LOGD(LOG_TAG, "- no services advertised");
log_d("- no services advertised");
}
esp_err_t errRc;
@ -214,7 +205,7 @@ void BLEAdvertising::start() {
m_advData.include_txpower = !m_scanResp;
errRc = ::esp_ble_gap_config_adv_data(&m_advData);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "<< esp_ble_gap_config_adv_data: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("<< esp_ble_gap_config_adv_data: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
}
@ -225,7 +216,7 @@ void BLEAdvertising::start() {
m_advData.include_txpower = m_scanResp;
errRc = ::esp_ble_gap_config_adv_data(&m_advData);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("<< esp_ble_gap_config_adv_data (Scan response): rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
}
@ -240,10 +231,10 @@ void BLEAdvertising::start() {
// Start advertising.
errRc = ::esp_ble_gap_start_advertising(&m_advParams);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "<< esp_ble_gap_start_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("<< esp_ble_gap_start_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
ESP_LOGD(LOG_TAG, "<< start");
log_v("<< start");
} // start
@ -253,13 +244,13 @@ void BLEAdvertising::start() {
* @return N/A.
*/
void BLEAdvertising::stop() {
ESP_LOGD(LOG_TAG, ">> stop");
log_v(">> stop");
esp_err_t errRc = ::esp_ble_gap_stop_advertising();
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_stop_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_stop_advertising: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
ESP_LOGD(LOG_TAG, "<< stop");
log_v("<< stop");
} // stop
/**
@ -352,12 +343,12 @@ void BLEAdvertisementData::setFlags(uint8_t flag) {
* @param [in] data Manufacturer data.
*/
void BLEAdvertisementData::setManufacturerData(std::string data) {
ESP_LOGD("BLEAdvertisementData", ">> setManufacturerData");
log_d("BLEAdvertisementData", ">> setManufacturerData");
char cdata[2];
cdata[0] = data.length() + 1;
cdata[1] = ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE; // 0xff
addData(std::string(cdata, 2) + data);
ESP_LOGD("BLEAdvertisementData", "<< setManufacturerData");
log_d("BLEAdvertisementData", "<< setManufacturerData");
} // setManufacturerData
@ -366,12 +357,12 @@ void BLEAdvertisementData::setManufacturerData(std::string data) {
* @param [in] The complete name of the device.
*/
void BLEAdvertisementData::setName(std::string name) {
ESP_LOGD("BLEAdvertisementData", ">> setName: %s", name.c_str());
log_d("BLEAdvertisementData", ">> setName: %s", name.c_str());
char cdata[2];
cdata[0] = name.length() + 1;
cdata[1] = ESP_BLE_AD_TYPE_NAME_CMPL; // 0x09
addData(std::string(cdata, 2) + name);
ESP_LOGD("BLEAdvertisementData", "<< setName");
log_d("BLEAdvertisementData", "<< setName");
} // setName
@ -455,12 +446,12 @@ void BLEAdvertisementData::setServiceData(BLEUUID uuid, std::string data) {
* @param [in] The short name of the device.
*/
void BLEAdvertisementData::setShortName(std::string name) {
ESP_LOGD("BLEAdvertisementData", ">> setShortName: %s", name.c_str());
log_d("BLEAdvertisementData", ">> setShortName: %s", name.c_str());
char cdata[2];
cdata[0] = name.length() + 1;
cdata[1] = ESP_BLE_AD_TYPE_NAME_SHORT; // 0x08
addData(std::string(cdata, 2) + name);
ESP_LOGD("BLEAdvertisementData", "<< setShortName");
log_d("BLEAdvertisementData", "<< setShortName");
} // setShortName
@ -476,7 +467,7 @@ void BLEAdvertising::handleGAPEvent(
esp_gap_ble_cb_event_t event,
esp_ble_gap_cb_param_t* param) {
ESP_LOGD(LOG_TAG, "handleGAPEvent [event no: %d]", (int)event);
log_d("handleGAPEvent [event no: %d]", (int)event);
switch(event) {
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: {
@ -492,7 +483,7 @@ void BLEAdvertising::handleGAPEvent(
break;
}
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: {
ESP_LOGI(LOG_TAG, "STOP advertising");
log_i("STOP advertising");
start();
break;
}

View File

@ -8,13 +8,7 @@
#if defined(CONFIG_BT_ENABLED)
#include <string.h>
#include "BLEBeacon.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEBeacon";
#endif
#define ENDIAN_CHANGE_U16(x) ((((x)&0xFF00)>>8) + (((x)&0xFF)<<8))
@ -58,7 +52,7 @@ int8_t BLEBeacon::getSignalPower() {
*/
void BLEBeacon::setData(std::string data) {
if (data.length() != sizeof(m_beaconData)) {
ESP_LOGE(LOG_TAG, "Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_beaconData));
log_e("Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_beaconData));
return;
}
memcpy(&m_beaconData, data.data(), sizeof(m_beaconData));

View File

@ -18,13 +18,7 @@
#include "BLEUtils.h"
#include "BLE2902.h"
#include "GeneralUtils.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLECharacteristic";
#endif
#define NULL_HANDLE (0xffff)
@ -70,9 +64,9 @@ BLECharacteristic::~BLECharacteristic() {
* @return N/A.
*/
void BLECharacteristic::addDescriptor(BLEDescriptor* pDescriptor) {
ESP_LOGD(LOG_TAG, ">> addDescriptor(): Adding %s to %s", pDescriptor->toString().c_str(), toString().c_str());
log_v(">> addDescriptor(): Adding %s to %s", pDescriptor->toString().c_str(), toString().c_str());
m_descriptorMap.setByUUID(pDescriptor->getUUID(), pDescriptor);
ESP_LOGD(LOG_TAG, "<< addDescriptor()");
log_v("<< addDescriptor()");
} // addDescriptor
@ -81,16 +75,16 @@ void BLECharacteristic::addDescriptor(BLEDescriptor* pDescriptor) {
* @param [in] pService The service with which to associate this characteristic.
*/
void BLECharacteristic::executeCreate(BLEService* pService) {
ESP_LOGD(LOG_TAG, ">> executeCreate()");
log_v(">> executeCreate()");
if (m_handle != NULL_HANDLE) {
ESP_LOGE(LOG_TAG, "Characteristic already has a handle.");
log_e("Characteristic already has a handle.");
return;
}
m_pService = pService; // Save the service to which this characteristic belongs.
ESP_LOGD(LOG_TAG, "Registering characteristic (esp_ble_gatts_add_char): uuid: %s, service: %s",
log_d("Registering characteristic (esp_ble_gatts_add_char): uuid: %s, service: %s",
getUUID().toString().c_str(),
m_pService->toString().c_str());
@ -107,7 +101,7 @@ void BLECharacteristic::executeCreate(BLEService* pService) {
&control); // Whether to auto respond or not.
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_add_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("<< esp_ble_gatts_add_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
m_semaphoreCreateEvt.wait("executeCreate");
@ -118,7 +112,7 @@ void BLECharacteristic::executeCreate(BLEService* pService) {
pDescriptor = m_descriptorMap.getNext();
} // End while
ESP_LOGD(LOG_TAG, "<< executeCreate");
log_v("<< executeCreate");
} // executeCreate
@ -200,7 +194,7 @@ void BLECharacteristic::handleGATTServerEvent(
esp_gatts_cb_event_t event,
esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t* param) {
ESP_LOGD(LOG_TAG, ">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str());
log_v(">> handleGATTServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str());
switch(event) {
// Events handled:
@ -238,7 +232,7 @@ void BLECharacteristic::handleGATTServerEvent(
param->write.conn_id,
param->write.trans_id, ESP_GATT_OK, nullptr);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
break;
} // ESP_GATTS_EXEC_WRITE_EVT
@ -288,11 +282,11 @@ void BLECharacteristic::handleGATTServerEvent(
setValue(param->write.value, param->write.len);
}
ESP_LOGD(LOG_TAG, " - Response to write event: New value: handle: %.2x, uuid: %s",
log_d(" - Response to write event: New value: handle: %.2x, uuid: %s",
getHandle(), getUUID().toString().c_str());
char* pHexData = BLEUtils::buildHexData(nullptr, param->write.value, param->write.len);
ESP_LOGD(LOG_TAG, " - Data: length: %d, data: %s", param->write.len, pHexData);
log_d(" - Data: length: %d, data: %s", param->write.len, pHexData);
free(pHexData);
if (param->write.need_rsp) {
@ -309,7 +303,7 @@ void BLECharacteristic::handleGATTServerEvent(
param->write.conn_id,
param->write.trans_id, ESP_GATT_OK, &rsp);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
} // Response needed
@ -361,9 +355,9 @@ void BLECharacteristic::handleGATTServerEvent(
// get mtu for peer device that we are sending read request to
uint16_t maxOffset = getService()->getServer()->getPeerMTU(param->read.conn_id) - 1;
ESP_LOGD(LOG_TAG, "mtu value: %d", maxOffset);
log_d("mtu value: %d", maxOffset);
if (param->read.need_rsp) {
ESP_LOGD(LOG_TAG, "Sending a response (esp_ble_gatts_send_response)");
log_d("Sending a response (esp_ble_gatts_send_response)");
esp_gatt_rsp_t rsp;
if (param->read.is_long) {
@ -407,7 +401,7 @@ void BLECharacteristic::handleGATTServerEvent(
rsp.attr_value.auth_req = ESP_GATT_AUTH_REQ_NONE;
char *pHexData = BLEUtils::buildHexData(nullptr, rsp.attr_value.value, rsp.attr_value.len);
ESP_LOGD(LOG_TAG, " - Data: length=%d, data=%s, offset=%d", rsp.attr_value.len, pHexData, rsp.attr_value.offset);
log_d(" - Data: length=%d, data=%s, offset=%d", rsp.attr_value.len, pHexData, rsp.attr_value.offset);
free(pHexData);
esp_err_t errRc = ::esp_ble_gatts_send_response(
@ -416,7 +410,7 @@ void BLECharacteristic::handleGATTServerEvent(
ESP_GATT_OK,
&rsp);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gatts_send_response: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
} // Response needed
} // Handle matches this characteristic.
@ -431,7 +425,7 @@ void BLECharacteristic::handleGATTServerEvent(
// - uint16_t conn_id The connection used.
//
case ESP_GATTS_CONF_EVT: {
// ESP_LOGD(LOG_TAG, "m_handle = %d, conf->handle = %d", m_handle, param->conf.handle);
// log_d("m_handle = %d, conf->handle = %d", m_handle, param->conf.handle);
if(param->conf.conn_id == getService()->getServer()->getConnId()) // && param->conf.handle == m_handle) // bug in esp-idf and not implemented in arduino yet
m_semaphoreConfEvt.give(param->conf.status);
break;
@ -456,7 +450,7 @@ void BLECharacteristic::handleGATTServerEvent(
// event.
m_descriptorMap.handleGATTServerEvent(event, gatts_if, param);
ESP_LOGD(LOG_TAG, "<< handleGATTServerEvent");
log_v("<< handleGATTServerEvent");
} // handleGATTServerEvent
@ -468,9 +462,9 @@ void BLECharacteristic::handleGATTServerEvent(
*/
void BLECharacteristic::indicate() {
ESP_LOGD(LOG_TAG, ">> indicate: length: %d", m_value.getValue().length());
log_v(">> indicate: length: %d", m_value.getValue().length());
notify(false);
ESP_LOGD(LOG_TAG, "<< indicate");
log_v("<< indicate");
} // indicate
@ -481,7 +475,7 @@ void BLECharacteristic::indicate() {
* @return N/A.
*/
void BLECharacteristic::notify(bool is_notification) {
ESP_LOGD(LOG_TAG, ">> notify: length: %d", m_value.getValue().length());
log_v(">> notify: length: %d", m_value.getValue().length());
assert(getService() != nullptr);
assert(getService()->getServer() != nullptr);
@ -489,7 +483,7 @@ void BLECharacteristic::notify(bool is_notification) {
GeneralUtils::hexDump((uint8_t*)m_value.getValue().data(), m_value.getValue().length());
if (getService()->getServer()->getConnectedCount() == 0) {
ESP_LOGD(LOG_TAG, "<< notify: No connected clients.");
log_v("<< notify: No connected clients.");
return;
}
@ -499,20 +493,20 @@ void BLECharacteristic::notify(bool is_notification) {
BLE2902 *p2902 = (BLE2902*)getDescriptorByUUID((uint16_t)0x2902);
if(is_notification) {
if (p2902 != nullptr && !p2902->getNotifications()) {
ESP_LOGD(LOG_TAG, "<< notifications disabled; ignoring");
log_v("<< notifications disabled; ignoring");
return;
}
}
else{
if (p2902 != nullptr && !p2902->getIndications()) {
ESP_LOGD(LOG_TAG, "<< indications disabled; ignoring");
log_v("<< indications disabled; ignoring");
return;
}
}
for (auto &myPair : getService()->getServer()->getPeerDevices(false)) {
uint16_t _mtu = (myPair.second.mtu);
if (m_value.getValue().length() > _mtu - 3) {
ESP_LOGW(LOG_TAG, "- Truncating to %d bytes (maximum notify size)", _mtu - 3);
log_w("- Truncating to %d bytes (maximum notify size)", _mtu - 3);
}
size_t length = m_value.getValue().length();
@ -523,14 +517,14 @@ void BLECharacteristic::notify(bool is_notification) {
myPair.first,
getHandle(), length, (uint8_t*)m_value.getValue().data(), !is_notification); // The need_confirm = false makes this a notify.
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_send_ %s: rc=%d %s",is_notification?"notify":"indicate", errRc, GeneralUtils::errorToString(errRc));
log_e("<< esp_ble_gatts_send_ %s: rc=%d %s",is_notification?"notify":"indicate", errRc, GeneralUtils::errorToString(errRc));
m_semaphoreConfEvt.give();
return;
}
if(!is_notification)
m_semaphoreConfEvt.wait("indicate");
}
ESP_LOGD(LOG_TAG, "<< notify");
log_v("<< notify");
} // Notify
@ -542,7 +536,7 @@ void BLECharacteristic::notify(bool is_notification) {
* @return N/A
*/
void BLECharacteristic::setBroadcastProperty(bool value) {
//ESP_LOGD(LOG_TAG, "setBroadcastProperty(%d)", value);
//log_d("setBroadcastProperty(%d)", value);
if (value) {
m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_BROADCAST);
} else {
@ -556,9 +550,9 @@ void BLECharacteristic::setBroadcastProperty(bool value) {
* @param [in] pCallbacks An instance of a callbacks structure used to define any callbacks for the characteristic.
*/
void BLECharacteristic::setCallbacks(BLECharacteristicCallbacks* pCallbacks) {
ESP_LOGD(LOG_TAG, ">> setCallbacks: 0x%x", (uint32_t)pCallbacks);
log_v(">> setCallbacks: 0x%x", (uint32_t)pCallbacks);
m_pCallbacks = pCallbacks;
ESP_LOGD(LOG_TAG, "<< setCallbacks");
log_v("<< setCallbacks");
} // setCallbacks
@ -573,9 +567,9 @@ void BLECharacteristic::setCallbacks(BLECharacteristicCallbacks* pCallbacks) {
* @param [in] handle The handle associated with this characteristic.
*/
void BLECharacteristic::setHandle(uint16_t handle) {
ESP_LOGD(LOG_TAG, ">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString().c_str());
log_v(">> setHandle: handle=0x%.2x, characteristic uuid=%s", handle, getUUID().toString().c_str());
m_handle = handle;
ESP_LOGD(LOG_TAG, "<< setHandle");
log_v("<< setHandle");
} // setHandle
@ -584,7 +578,7 @@ void BLECharacteristic::setHandle(uint16_t handle) {
* @param [in] value Set to true if we are to allow indicate messages.
*/
void BLECharacteristic::setIndicateProperty(bool value) {
//ESP_LOGD(LOG_TAG, "setIndicateProperty(%d)", value);
//log_d("setIndicateProperty(%d)", value);
if (value) {
m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_INDICATE);
} else {
@ -598,7 +592,7 @@ void BLECharacteristic::setIndicateProperty(bool value) {
* @param [in] value Set to true if we are to allow notification messages.
*/
void BLECharacteristic::setNotifyProperty(bool value) {
//ESP_LOGD(LOG_TAG, "setNotifyProperty(%d)", value);
//log_d("setNotifyProperty(%d)", value);
if (value) {
m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_NOTIFY);
} else {
@ -612,7 +606,7 @@ void BLECharacteristic::setNotifyProperty(bool value) {
* @param [in] value Set to true if we are to allow reads.
*/
void BLECharacteristic::setReadProperty(bool value) {
//ESP_LOGD(LOG_TAG, "setReadProperty(%d)", value);
//log_d("setReadProperty(%d)", value);
if (value) {
m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_READ);
} else {
@ -628,14 +622,14 @@ void BLECharacteristic::setReadProperty(bool value) {
*/
void BLECharacteristic::setValue(uint8_t* data, size_t length) {
char* pHex = BLEUtils::buildHexData(nullptr, data, length);
ESP_LOGD(LOG_TAG, ">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str());
log_v(">> setValue: length=%d, data=%s, characteristic UUID=%s", length, pHex, getUUID().toString().c_str());
free(pHex);
if (length > ESP_GATT_MAX_ATTR_LEN) {
ESP_LOGE(LOG_TAG, "Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN);
log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN);
return;
}
m_value.setValue(data, length);
ESP_LOGD(LOG_TAG, "<< setValue");
log_v("<< setValue");
} // setValue
@ -693,7 +687,7 @@ void BLECharacteristic::setValue(double& data64) {
* @param [in] value Set to true if we are to allow writes with no response.
*/
void BLECharacteristic::setWriteNoResponseProperty(bool value) {
//ESP_LOGD(LOG_TAG, "setWriteNoResponseProperty(%d)", value);
//log_d("setWriteNoResponseProperty(%d)", value);
if (value) {
m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_WRITE_NR);
} else {
@ -707,7 +701,7 @@ void BLECharacteristic::setWriteNoResponseProperty(bool value) {
* @param [in] value Set to true if we are to allow writes.
*/
void BLECharacteristic::setWriteProperty(bool value) {
//ESP_LOGD(LOG_TAG, "setWriteProperty(%d)", value);
//log_d("setWriteProperty(%d)", value);
if (value) {
m_properties = (esp_gatt_char_prop_t)(m_properties | ESP_GATT_CHAR_PROP_BIT_WRITE);
} else {
@ -743,8 +737,8 @@ BLECharacteristicCallbacks::~BLECharacteristicCallbacks() {}
* @param [in] pCharacteristic The characteristic that is the source of the event.
*/
void BLECharacteristicCallbacks::onRead(BLECharacteristic* pCharacteristic) {
ESP_LOGD("BLECharacteristicCallbacks", ">> onRead: default");
ESP_LOGD("BLECharacteristicCallbacks", "<< onRead");
log_d("BLECharacteristicCallbacks", ">> onRead: default");
log_d("BLECharacteristicCallbacks", "<< onRead");
} // onRead
@ -753,8 +747,8 @@ void BLECharacteristicCallbacks::onRead(BLECharacteristic* pCharacteristic) {
* @param [in] pCharacteristic The characteristic that is the source of the event.
*/
void BLECharacteristicCallbacks::onWrite(BLECharacteristic* pCharacteristic) {
ESP_LOGD("BLECharacteristicCallbacks", ">> onWrite: default");
ESP_LOGD("BLECharacteristicCallbacks", "<< onWrite");
log_d("BLECharacteristicCallbacks", ">> onWrite: default");
log_d("BLECharacteristicCallbacks", "<< onWrite");
} // onWrite
#endif /* CONFIG_BT_ENABLED */

View File

@ -18,14 +18,7 @@
#include <sstream>
#include <unordered_set>
#include "BLEDevice.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEClient";
#endif
/*
* Design
@ -75,14 +68,14 @@ BLEClient::~BLEClient() {
*
*/
void BLEClient::clearServices() {
ESP_LOGD(LOG_TAG, ">> clearServices");
log_v(">> clearServices");
// Delete all the services.
for (auto &myPair : m_servicesMap) {
delete myPair.second;
}
m_servicesMap.clear();
m_haveServices = false;
ESP_LOGD(LOG_TAG, "<< clearServices");
log_v("<< clearServices");
} // clearServices
/**
@ -100,7 +93,7 @@ bool BLEClient::connect(BLEAdvertisedDevice* device) {
* @return True on success.
*/
bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) {
ESP_LOGD(LOG_TAG, ">> connect(%s)", address.toString().c_str());
log_v(">> connect(%s)", address.toString().c_str());
// We need the connection handle that we get from registering the application. We register the app
// and then block on its completion. When the event has arrived, we will have the handle.
@ -111,7 +104,7 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) {
// clearServices(); // we dont need to delete services since every client is unique?
esp_err_t errRc = ::esp_ble_gattc_app_register(m_appId);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_app_register: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_app_register: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return false;
}
@ -128,12 +121,12 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) {
1 // direct connection <-- maybe needs to be changed in case of direct indirect connection???
);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return false;
}
uint32_t rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete.
ESP_LOGD(LOG_TAG, "<< connect(), rc=%d", rc==ESP_GATT_OK);
log_v("<< connect(), rc=%d", rc==ESP_GATT_OK);
return rc == ESP_GATT_OK;
} // connect
@ -143,13 +136,13 @@ bool BLEClient::connect(BLEAddress address, esp_ble_addr_type_t type) {
* @return N/A.
*/
void BLEClient::disconnect() {
ESP_LOGD(LOG_TAG, ">> disconnect()");
log_v(">> disconnect()");
esp_err_t errRc = ::esp_ble_gattc_close(getGattcIf(), getConnId());
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_close: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_close: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
ESP_LOGD(LOG_TAG, "<< disconnect()");
log_v("<< disconnect()");
} // disconnect
@ -161,14 +154,14 @@ void BLEClient::gattClientEventHandler(
esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t* evtParam) {
ESP_LOGD(LOG_TAG, "gattClientEventHandler [esp_gatt_if: %d] ... %s",
log_d("gattClientEventHandler [esp_gatt_if: %d] ... %s",
gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str());
// Execute handler code based on the type of event received.
switch(event) {
case ESP_GATTC_SRVC_CHG_EVT:
ESP_LOGI(LOG_TAG, "SERVICE CHANGED");
log_i("SERVICE CHANGED");
break;
case ESP_GATTC_CLOSE_EVT: {
@ -234,7 +227,7 @@ void BLEClient::gattClientEventHandler(
case ESP_GATTC_CFG_MTU_EVT:
if(evtParam->cfg_mtu.status != ESP_GATT_OK) {
ESP_LOGE(LOG_TAG,"Config mtu failed");
log_e("Config mtu failed");
}
m_mtu = evtParam->cfg_mtu.mtu;
break;
@ -243,7 +236,7 @@ void BLEClient::gattClientEventHandler(
BLEDevice::updatePeerDevice(this, true, m_gattc_if);
esp_err_t errRc = esp_ble_gattc_send_mtu_req(gattc_if, evtParam->connect.conn_id);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_send_mtu_req: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
if(BLEDevice::m_securityLevel){
@ -263,17 +256,17 @@ void BLEClient::gattClientEventHandler(
case ESP_GATTC_SEARCH_CMPL_EVT: {
esp_ble_gattc_cb_param_t* p_data = (esp_ble_gattc_cb_param_t*)evtParam;
if (p_data->search_cmpl.status != ESP_GATT_OK){
ESP_LOGE(LOG_TAG, "search service failed, error status = %x", p_data->search_cmpl.status);
log_e("search service failed, error status = %x", p_data->search_cmpl.status);
break;
}
#ifndef ARDUINO_ARCH_ESP32
// commented out just for now to keep backward compatibility
// if(p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_REMOTE_DEVICE) {
// ESP_LOGI(LOG_TAG, "Get service information from remote device");
// log_i("Get service information from remote device");
// } else if (p_data->search_cmpl.searched_service_source == ESP_GATT_SERVICE_FROM_NVS_FLASH) {
// ESP_LOGI(LOG_TAG, "Get service information from flash");
// log_i("Get service information from flash");
// } else {
// ESP_LOGI(LOG_TAG, "unknown service source");
// log_i("unknown service source");
// }
#endif
m_semaphoreSearchCmplEvt.give(0);
@ -343,9 +336,9 @@ BLEAddress BLEClient::getPeerAddress() {
* @return The RSSI value.
*/
int BLEClient::getRssi() {
ESP_LOGD(LOG_TAG, ">> getRssi()");
log_v(">> getRssi()");
if (!isConnected()) {
ESP_LOGD(LOG_TAG, "<< getRssi(): Not connected");
log_v("<< getRssi(): Not connected");
return 0;
}
// We make the API call to read the RSSI value which is an asynchronous operation. We expect to receive
@ -354,11 +347,11 @@ int BLEClient::getRssi() {
m_semaphoreRssiCmplEvt.take("getRssi");
esp_err_t rc = ::esp_ble_gap_read_rssi(*getPeerAddress().getNative());
if (rc != ESP_OK) {
ESP_LOGE(LOG_TAG, "<< getRssi: esp_ble_gap_read_rssi: rc=%d %s", rc, GeneralUtils::errorToString(rc));
log_e("<< getRssi: esp_ble_gap_read_rssi: rc=%d %s", rc, GeneralUtils::errorToString(rc));
return 0;
}
int rssiValue = m_semaphoreRssiCmplEvt.wait("getRssi");
ESP_LOGD(LOG_TAG, "<< getRssi(): %d", rssiValue);
log_v("<< getRssi(): %d", rssiValue);
return rssiValue;
} // getRssi
@ -380,7 +373,7 @@ BLERemoteService* BLEClient::getService(const char* uuid) {
* @throws BLEUuidNotFound
*/
BLERemoteService* BLEClient::getService(BLEUUID uuid) {
ESP_LOGD(LOG_TAG, ">> getService: uuid: %s", uuid.toString().c_str());
log_v(">> getService: uuid: %s", uuid.toString().c_str());
// Design
// ------
// We wish to retrieve the service given its UUID. It is possible that we have not yet asked the
@ -393,11 +386,11 @@ BLERemoteService* BLEClient::getService(BLEUUID uuid) {
std::string uuidStr = uuid.toString();
for (auto &myPair : m_servicesMap) {
if (myPair.first == uuidStr) {
ESP_LOGD(LOG_TAG, "<< getService: found the service with uuid: %s", uuid.toString().c_str());
log_v("<< getService: found the service with uuid: %s", uuid.toString().c_str());
return myPair.second;
}
} // End of each of the services.
ESP_LOGD(LOG_TAG, "<< getService: not found");
log_v("<< getService: not found");
return nullptr;
} // getService
@ -416,7 +409,7 @@ std::map<std::string, BLERemoteService*>* BLEClient::getServices() {
* peer BLE partner to be returned as events. Each event will be an an instance of ESP_GATTC_SEARCH_RES_EVT
* and will culminate with an ESP_GATTC_SEARCH_CMPL_EVT when all have been received.
*/
ESP_LOGD(LOG_TAG, ">> getServices");
log_v(">> getServices");
// TODO implement retrieving services from cache
clearServices(); // Clear any services that may exist.
@ -428,12 +421,12 @@ std::map<std::string, BLERemoteService*>* BLEClient::getServices() {
m_semaphoreSearchCmplEvt.take("getServices");
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_search_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_search_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return &m_servicesMap;
}
// If sucessfull, remember that we now have services.
m_haveServices = (m_semaphoreSearchCmplEvt.wait("getServices") == 0);
ESP_LOGD(LOG_TAG, "<< getServices");
log_v("<< getServices");
return &m_servicesMap;
} // getServices
@ -445,9 +438,9 @@ std::map<std::string, BLERemoteService*>* BLEClient::getServices() {
* @throws BLEUuidNotFound
*/
std::string BLEClient::getValue(BLEUUID serviceUUID, BLEUUID characteristicUUID) {
ESP_LOGD(LOG_TAG, ">> getValue: serviceUUID: %s, characteristicUUID: %s", serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
log_v(">> getValue: serviceUUID: %s, characteristicUUID: %s", serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
std::string ret = getService(serviceUUID)->getCharacteristic(characteristicUUID)->readValue();
ESP_LOGD(LOG_TAG, "<<getValue");
log_v("<<getValue");
return ret;
} // getValue
@ -461,7 +454,7 @@ std::string BLEClient::getValue(BLEUUID serviceUUID, BLEUUID characteristicUUID)
void BLEClient::handleGAPEvent(
esp_gap_ble_cb_event_t event,
esp_ble_gap_cb_param_t* param) {
ESP_LOGD(LOG_TAG, "BLEClient ... handling GAP event!");
log_d("BLEClient ... handling GAP event!");
switch (event) {
//
// ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT
@ -508,9 +501,9 @@ void BLEClient::setClientCallbacks(BLEClientCallbacks* pClientCallbacks) {
* @throws BLEUuidNotFound
*/
void BLEClient::setValue(BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value) {
ESP_LOGD(LOG_TAG, ">> setValue: serviceUUID: %s, characteristicUUID: %s", serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
log_v(">> setValue: serviceUUID: %s, characteristicUUID: %s", serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
getService(serviceUUID)->getCharacteristic(characteristicUUID)->writeValue(value);
ESP_LOGD(LOG_TAG, "<< setValue");
log_v("<< setValue");
} // setValue
uint16_t BLEClient::getMTU() {

View File

@ -15,16 +15,7 @@
#include "BLEService.h"
#include "BLEDescriptor.h"
#include "GeneralUtils.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEDescriptor";
#endif
#define NULL_HANDLE (0xffff)
@ -63,10 +54,10 @@ BLEDescriptor::~BLEDescriptor() {
* @param [in] pCharacteristic The characteristic to which to register this descriptor.
*/
void BLEDescriptor::executeCreate(BLECharacteristic* pCharacteristic) {
ESP_LOGD(LOG_TAG, ">> executeCreate(): %s", toString().c_str());
log_v(">> executeCreate(): %s", toString().c_str());
if (m_handle != NULL_HANDLE) {
ESP_LOGE(LOG_TAG, "Descriptor already has a handle.");
log_e("Descriptor already has a handle.");
return;
}
@ -82,12 +73,12 @@ void BLEDescriptor::executeCreate(BLECharacteristic* pCharacteristic) {
&m_value,
&control);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_add_char_descr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("<< esp_ble_gatts_add_char_descr: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
m_semaphoreCreateEvt.wait("executeCreate");
ESP_LOGD(LOG_TAG, "<< executeCreate");
log_v("<< executeCreate");
} // executeCreate
@ -213,9 +204,9 @@ void BLEDescriptor::handleGATTServerEvent(
* @param [in] pCallbacks An instance of a callback structure used to define any callbacks for the descriptor.
*/
void BLEDescriptor::setCallbacks(BLEDescriptorCallbacks* pCallback) {
ESP_LOGD(LOG_TAG, ">> setCallbacks: 0x%x", (uint32_t) pCallback);
log_v(">> setCallbacks: 0x%x", (uint32_t) pCallback);
m_pCallback = pCallback;
ESP_LOGD(LOG_TAG, "<< setCallbacks");
log_v("<< setCallbacks");
} // setCallbacks
@ -226,9 +217,9 @@ void BLEDescriptor::setCallbacks(BLEDescriptorCallbacks* pCallback) {
* @return N/A.
*/
void BLEDescriptor::setHandle(uint16_t handle) {
ESP_LOGD(LOG_TAG, ">> setHandle(0x%.2x): Setting descriptor handle to be 0x%.2x", handle, handle);
log_v(">> setHandle(0x%.2x): Setting descriptor handle to be 0x%.2x", handle, handle);
m_handle = handle;
ESP_LOGD(LOG_TAG, "<< setHandle()");
log_v("<< setHandle()");
} // setHandle
@ -239,7 +230,7 @@ void BLEDescriptor::setHandle(uint16_t handle) {
*/
void BLEDescriptor::setValue(uint8_t* data, size_t length) {
if (length > ESP_GATT_MAX_ATTR_LEN) {
ESP_LOGE(LOG_TAG, "Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN);
log_e("Size %d too large, must be no bigger than %d", length, ESP_GATT_MAX_ATTR_LEN);
return;
}
m_value.attr_len = length;
@ -278,8 +269,8 @@ BLEDescriptorCallbacks::~BLEDescriptorCallbacks() {}
* @param [in] pDescriptor The descriptor that is the source of the event.
*/
void BLEDescriptorCallbacks::onRead(BLEDescriptor* pDescriptor) {
ESP_LOGD("BLEDescriptorCallbacks", ">> onRead: default");
ESP_LOGD("BLEDescriptorCallbacks", "<< onRead");
log_d("BLEDescriptorCallbacks", ">> onRead: default");
log_d("BLEDescriptorCallbacks", "<< onRead");
} // onRead
@ -288,8 +279,8 @@ void BLEDescriptorCallbacks::onRead(BLEDescriptor* pDescriptor) {
* @param [in] pDescriptor The descriptor that is the source of the event.
*/
void BLEDescriptorCallbacks::onWrite(BLEDescriptor* pDescriptor) {
ESP_LOGD("BLEDescriptorCallbacks", ">> onWrite: default");
ESP_LOGD("BLEDescriptorCallbacks", "<< onWrite");
log_d("BLEDescriptorCallbacks", ">> onWrite: default");
log_d("BLEDescriptorCallbacks", "<< onWrite");
} // onWrite

View File

@ -34,7 +34,7 @@
#if defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEDevice";
@ -63,13 +63,13 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
* @return A new instance of the client.
*/
/* STATIC */ BLEClient* BLEDevice::createClient() {
ESP_LOGD(LOG_TAG, ">> createClient");
log_v(">> createClient");
#ifndef CONFIG_GATTC_ENABLE // Check that BLE GATTC is enabled in make menuconfig
ESP_LOGE(LOG_TAG, "BLE GATTC is not enabled - CONFIG_GATTC_ENABLE not defined");
log_e("BLE GATTC is not enabled - CONFIG_GATTC_ENABLE not defined");
abort();
#endif // CONFIG_GATTC_ENABLE
m_pClient = new BLEClient();
ESP_LOGD(LOG_TAG, "<< createClient");
log_v("<< createClient");
return m_pClient;
} // createClient
@ -79,14 +79,14 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
* @return A new instance of the server.
*/
/* STATIC */ BLEServer* BLEDevice::createServer() {
ESP_LOGD(LOG_TAG, ">> createServer");
log_v(">> createServer");
#ifndef CONFIG_GATTS_ENABLE // Check that BLE GATTS is enabled in make menuconfig
ESP_LOGE(LOG_TAG, "BLE GATTS is not enabled - CONFIG_GATTS_ENABLE not defined");
log_e("BLE GATTS is not enabled - CONFIG_GATTS_ENABLE not defined");
abort();
#endif // CONFIG_GATTS_ENABLE
m_pServer = new BLEServer();
m_pServer->createApp(m_appId++);
ESP_LOGD(LOG_TAG, "<< createServer");
log_v("<< createServer");
return m_pServer;
} // createServer
@ -103,7 +103,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t* param
) {
ESP_LOGD(LOG_TAG, "gattServerEventHandler [esp_gatt_if: %d] ... %s",
log_d("gattServerEventHandler [esp_gatt_if: %d] ... %s",
gatts_if,
BLEUtils::gattServerEventTypeToString(event).c_str());
@ -150,7 +150,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
esp_gatt_if_t gattc_if,
esp_ble_gattc_cb_param_t* param) {
ESP_LOGD(LOG_TAG, "gattClientEventHandler [esp_gatt_if: %d] ... %s",
log_d("gattClientEventHandler [esp_gatt_if: %d] ... %s",
gattc_if, BLEUtils::gattClientEventTypeToString(event).c_str());
BLEUtils::dumpGattClientEvent(event, gattc_if, param);
@ -194,16 +194,16 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
switch(event) {
case ESP_GAP_BLE_OOB_REQ_EVT: /* OOB request event */
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_OOB_REQ_EVT");
log_i("ESP_GAP_BLE_OOB_REQ_EVT");
break;
case ESP_GAP_BLE_LOCAL_IR_EVT: /* BLE local IR event */
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_LOCAL_IR_EVT");
log_i("ESP_GAP_BLE_LOCAL_IR_EVT");
break;
case ESP_GAP_BLE_LOCAL_ER_EVT: /* BLE local ER event */
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_LOCAL_ER_EVT");
log_i("ESP_GAP_BLE_LOCAL_ER_EVT");
break;
case ESP_GAP_BLE_NC_REQ_EVT: /* NUMERIC CONFIRMATION */
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_NC_REQ_EVT");
log_i("ESP_GAP_BLE_NC_REQ_EVT");
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
if(BLEDevice::m_securityCallbacks != nullptr){
esp_ble_confirm_reply(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onConfirmPIN(param->ble_security.key_notif.passkey));
@ -211,8 +211,8 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
#endif // CONFIG_BLE_SMP_ENABLE
break;
case ESP_GAP_BLE_PASSKEY_REQ_EVT: /* passkey request event */
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PASSKEY_REQ_EVT: ");
// esp_log_buffer_hex(LOG_TAG, m_remote_bda, sizeof(m_remote_bda));
log_i("ESP_GAP_BLE_PASSKEY_REQ_EVT: ");
// esp_log_buffer_hex(m_remote_bda, sizeof(m_remote_bda));
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
if(BLEDevice::m_securityCallbacks != nullptr){
esp_ble_passkey_reply(param->ble_security.ble_req.bd_addr, true, BLEDevice::m_securityCallbacks->onPassKeyRequest());
@ -225,7 +225,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
case ESP_GAP_BLE_SEC_REQ_EVT:
/* send the positive(true) security response to the peer device to accept the security request.
If not accept the security request, should sent the security response with negative(false) accept value*/
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_SEC_REQ_EVT");
log_i("ESP_GAP_BLE_SEC_REQ_EVT");
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
if(BLEDevice::m_securityCallbacks!=nullptr){
esp_ble_gap_security_rsp(param->ble_security.ble_req.bd_addr, BLEDevice::m_securityCallbacks->onSecurityRequest());
@ -240,9 +240,9 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
*/
case ESP_GAP_BLE_PASSKEY_NOTIF_EVT: //the app will receive this evt when the IO has Output capability and the peer device IO has Input capability.
//display the passkey number to the user to input it in the peer deivce within 30 seconds
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_PASSKEY_NOTIF_EVT");
log_i("ESP_GAP_BLE_PASSKEY_NOTIF_EVT");
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
ESP_LOGI(LOG_TAG, "passKey = %d", param->ble_security.key_notif.passkey);
log_i("passKey = %d", param->ble_security.key_notif.passkey);
if(BLEDevice::m_securityCallbacks!=nullptr){
BLEDevice::m_securityCallbacks->onPassKeyNotify(param->ble_security.key_notif.passkey);
}
@ -250,13 +250,13 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
break;
case ESP_GAP_BLE_KEY_EVT:
//shows the ble key type info share with peer device to the user.
ESP_LOGD(LOG_TAG, "ESP_GAP_BLE_KEY_EVT");
log_d("ESP_GAP_BLE_KEY_EVT");
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
ESP_LOGI(LOG_TAG, "key type = %s", BLESecurity::esp_key_type_to_str(param->ble_security.ble_key.key_type));
log_i("key type = %s", BLESecurity::esp_key_type_to_str(param->ble_security.ble_key.key_type));
#endif // CONFIG_BLE_SMP_ENABLE
break;
case ESP_GAP_BLE_AUTH_CMPL_EVT:
ESP_LOGI(LOG_TAG, "ESP_GAP_BLE_AUTH_CMPL_EVT");
log_i("ESP_GAP_BLE_AUTH_CMPL_EVT");
#ifdef CONFIG_BLE_SMP_ENABLE // Check that BLE SMP (security) is configured in make menuconfig
if(BLEDevice::m_securityCallbacks != nullptr){
BLEDevice::m_securityCallbacks->onAuthenticationComplete(param->ble_security.auth_cmpl);
@ -305,12 +305,12 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
* try and release/delete it.
*/
/* STATIC */ BLEScan* BLEDevice::getScan() {
//ESP_LOGD(LOG_TAG, ">> getScan");
//log_v(">> getScan");
if (m_pScan == nullptr) {
m_pScan = new BLEScan();
//ESP_LOGD(LOG_TAG, " - creating a new scan object");
//log_d(" - creating a new scan object");
}
//ESP_LOGD(LOG_TAG, "<< getScan: Returning object at 0x%x", (uint32_t)m_pScan);
//log_v("<< getScan: Returning object at 0x%x", (uint32_t)m_pScan);
return m_pScan;
} // getScan
@ -322,12 +322,12 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
* @param [in] characteristicUUID
*/
/* STATIC */ std::string BLEDevice::getValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID) {
ESP_LOGD(LOG_TAG, ">> getValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
log_v(">> getValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
BLEClient* pClient = createClient();
pClient->connect(bdAddress);
std::string ret = pClient->getValue(serviceUUID, characteristicUUID);
pClient->disconnect();
ESP_LOGD(LOG_TAG, "<< getValue");
log_v("<< getValue");
return ret;
} // getValue
@ -349,7 +349,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
#else
errRc = ::nvs_flash_init();
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "nvs_flash_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("nvs_flash_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
@ -359,20 +359,20 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
esp_bt_controller_config_t bt_cfg = BT_CONTROLLER_INIT_CONFIG_DEFAULT();
errRc = esp_bt_controller_init(&bt_cfg);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_bt_controller_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_bt_controller_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
#ifndef CLASSIC_BT_ENABLED
errRc = esp_bt_controller_enable(ESP_BT_MODE_BLE);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
#else
errRc = esp_bt_controller_enable(ESP_BT_MODE_BTDM);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_bt_controller_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
#endif
@ -382,7 +382,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
if (bt_state == ESP_BLUEDROID_STATUS_UNINITIALIZED) {
errRc = esp_bluedroid_init();
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_bluedroid_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_bluedroid_init: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
}
@ -390,21 +390,21 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
if (bt_state != ESP_BLUEDROID_STATUS_ENABLED) {
errRc = esp_bluedroid_enable();
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_bluedroid_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_bluedroid_enable: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
}
errRc = esp_ble_gap_register_callback(BLEDevice::gapEventHandler);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
#ifdef CONFIG_GATTC_ENABLE // Check that BLE client is configured in make menuconfig
errRc = esp_ble_gattc_register_callback(BLEDevice::gattClientEventHandler);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
#endif // CONFIG_GATTC_ENABLE
@ -412,14 +412,14 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
#ifdef CONFIG_GATTS_ENABLE // Check that BLE server is configured in make menuconfig
errRc = esp_ble_gatts_register_callback(BLEDevice::gattServerEventHandler);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gatts_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gatts_register_callback: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
#endif // CONFIG_GATTS_ENABLE
errRc = ::esp_ble_gap_set_device_name(deviceName.c_str());
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_set_device_name: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_set_device_name: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
};
@ -427,7 +427,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
esp_ble_io_cap_t iocap = ESP_IO_CAP_NONE;
errRc = ::esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_set_security_param: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_set_security_param: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
};
#endif // CONFIG_BLE_SMP_ENABLE
@ -450,12 +450,12 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
* @param [in] powerLevel.
*/
/* STATIC */ void BLEDevice::setPower(esp_power_level_t powerLevel) {
ESP_LOGD(LOG_TAG, ">> setPower: %d", powerLevel);
log_v(">> setPower: %d", powerLevel);
esp_err_t errRc = ::esp_ble_tx_power_set(ESP_BLE_PWR_TYPE_DEFAULT, powerLevel);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_tx_power_set: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_tx_power_set: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
};
ESP_LOGD(LOG_TAG, "<< setPower");
log_v("<< setPower");
} // setPower
@ -466,7 +466,7 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
* @param [in] characteristicUUID
*/
/* STATIC */ void BLEDevice::setValue(BLEAddress bdAddress, BLEUUID serviceUUID, BLEUUID characteristicUUID, std::string value) {
ESP_LOGD(LOG_TAG, ">> setValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
log_v(">> setValue: bdAddress: %s, serviceUUID: %s, characteristicUUID: %s", bdAddress.toString().c_str(), serviceUUID.toString().c_str(), characteristicUUID.toString().c_str());
BLEClient* pClient = createClient();
pClient->connect(bdAddress);
pClient->setValue(serviceUUID, characteristicUUID, value);
@ -490,12 +490,12 @@ gatts_event_handler BLEDevice::m_customGattsHandler = nullptr;
* @param [in] address The address to add to the white list.
*/
void BLEDevice::whiteListAdd(BLEAddress address) {
ESP_LOGD(LOG_TAG, ">> whiteListAdd: %s", address.toString().c_str());
log_v(">> whiteListAdd: %s", address.toString().c_str());
esp_err_t errRc = esp_ble_gap_update_whitelist(true, *address.getNative()); // True to add an entry.
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
ESP_LOGD(LOG_TAG, "<< whiteListAdd");
log_v("<< whiteListAdd");
} // whiteListAdd
@ -504,12 +504,12 @@ void BLEDevice::whiteListAdd(BLEAddress address) {
* @param [in] address The address to remove from the white list.
*/
void BLEDevice::whiteListRemove(BLEAddress address) {
ESP_LOGD(LOG_TAG, ">> whiteListRemove: %s", address.toString().c_str());
log_v(">> whiteListRemove: %s", address.toString().c_str());
esp_err_t errRc = esp_ble_gap_update_whitelist(false, *address.getNative()); // False to remove an entry.
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_update_whitelist: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
ESP_LOGD(LOG_TAG, "<< whiteListRemove");
log_v("<< whiteListRemove");
} // whiteListRemove
/*
@ -533,14 +533,14 @@ void BLEDevice::setSecurityCallbacks(BLESecurityCallbacks* callbacks) {
* @param [in] mtu Value to set local mtu, should be larger than 23 and lower or equal to 517
*/
esp_err_t BLEDevice::setMTU(uint16_t mtu) {
ESP_LOGD(LOG_TAG, ">> setLocalMTU: %d", mtu);
log_v(">> setLocalMTU: %d", mtu);
esp_err_t err = esp_ble_gatt_set_local_mtu(mtu);
if (err == ESP_OK) {
m_localMTU = mtu;
} else {
ESP_LOGE(LOG_TAG, "can't set local mtu value: %d", mtu);
log_e("can't set local mtu value: %d", mtu);
}
ESP_LOGD(LOG_TAG, "<< setLocalMTU");
log_v("<< setLocalMTU");
return err;
}
@ -558,16 +558,16 @@ bool BLEDevice::getInitialized() {
BLEAdvertising* BLEDevice::getAdvertising() {
if(m_bleAdvertising == nullptr) {
m_bleAdvertising = new BLEAdvertising();
ESP_LOGI(LOG_TAG, "create advertising");
log_i("create advertising");
}
ESP_LOGD(LOG_TAG, "get advertising");
log_d("get advertising");
return m_bleAdvertising;
}
void BLEDevice::startAdvertising() {
ESP_LOGD(LOG_TAG, ">> startAdvertising");
log_v(">> startAdvertising");
getAdvertising()->start();
ESP_LOGD(LOG_TAG, "<< startAdvertising");
log_v("<< startAdvertising");
} // startAdvertising
/* multi connect support */
@ -581,7 +581,7 @@ BLEClient* BLEDevice::getClientByGattIf(uint16_t conn_id) {
}
void BLEDevice::updatePeerDevice(void* peer, bool _client, uint16_t conn_id) {
ESP_LOGD(LOG_TAG, "update conn_id: %d, GATT role: %s", conn_id, _client? "client":"server");
log_d("update conn_id: %d, GATT role: %s", conn_id, _client? "client":"server");
std::map<uint16_t, conn_status_t>::iterator it = m_connectedClientsMap.find(ESP_GATT_IF_NONE);
if (it != m_connectedClientsMap.end()) {
std::swap(m_connectedClientsMap[conn_id], it->second);
@ -597,7 +597,7 @@ void BLEDevice::updatePeerDevice(void* peer, bool _client, uint16_t conn_id) {
}
void BLEDevice::addPeerDevice(void* peer, bool _client, uint16_t conn_id) {
ESP_LOGI(LOG_TAG, "add conn_id: %d, GATT role: %s", conn_id, _client? "client":"server");
log_i("add conn_id: %d, GATT role: %s", conn_id, _client? "client":"server");
conn_status_t status = {
.peer_device = peer,
.connected = true,
@ -608,7 +608,7 @@ void BLEDevice::addPeerDevice(void* peer, bool _client, uint16_t conn_id) {
}
void BLEDevice::removePeerDevice(uint16_t conn_id, bool _client) {
ESP_LOGI(LOG_TAG, "remove: %d, GATT role %s", conn_id, _client?"client":"server");
log_i("remove: %d, GATT role %s", conn_id, _client?"client":"server");
if(m_connectedClientsMap.find(conn_id) != m_connectedClientsMap.end())
m_connectedClientsMap.erase(conn_id);
}

View File

@ -8,7 +8,7 @@
#if defined(CONFIG_BT_ENABLED)
#include <string.h>
#include <sstream>
#include <esp_log.h>
#include "esp32-hal-log.h"
#include "BLEEddystoneTLM.h"
static const char LOG_TAG[] = "BLEEddystoneTLM";
@ -117,7 +117,7 @@ std::string BLEEddystoneTLM::toString() {
*/
void BLEEddystoneTLM::setData(std::string data) {
if (data.length() != sizeof(m_eddystoneData)) {
ESP_LOGE(LOG_TAG, "Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_eddystoneData));
log_e("Unable to set the data ... length passed in was %d and expected %d", data.length(), sizeof(m_eddystoneData));
return;
}
memcpy(&m_eddystoneData, data.data(), data.length());

View File

@ -7,7 +7,7 @@
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include <string.h>
#include <esp_log.h>
#include "esp32-hal-log.h"
#include "BLEEddystoneURL.h"
static const char LOG_TAG[] = "BLEEddystoneURL";
@ -118,7 +118,7 @@ std::string BLEEddystoneURL::getDecodedURL() {
*/
void BLEEddystoneURL::setData(std::string data) {
if (data.length() > sizeof(m_eddystoneData)) {
ESP_LOGE(LOG_TAG, "Unable to set the data ... length passed in was %d and max expected %d", data.length(), sizeof(m_eddystoneData));
log_e("Unable to set the data ... length passed in was %d and max expected %d", data.length(), sizeof(m_eddystoneData));
return;
}
memset(&m_eddystoneData, 0, sizeof(m_eddystoneData));
@ -136,7 +136,7 @@ void BLEEddystoneURL::setPower(int8_t advertisedTxPower) {
void BLEEddystoneURL::setURL(std::string url) {
if (url.length() > sizeof(m_eddystoneData.url)) {
ESP_LOGE(LOG_TAG, "Unable to set the url ... length passed in was %d and max expected %d", url.length(), sizeof(m_eddystoneData.url));
log_e("Unable to set the url ... length passed in was %d and max expected %d", url.length(), sizeof(m_eddystoneData.url));
return;
}
memset(m_eddystoneData.url, 0, sizeof(m_eddystoneData.url));

View File

@ -18,14 +18,7 @@
#include "BLEUtils.h"
#include "GeneralUtils.h"
#include "BLERemoteDescriptor.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLERemoteCharacteristic"; // The logging tag for this class.
#endif
/**
@ -40,7 +33,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
BLEUUID uuid,
esp_gatt_char_prop_t charProp,
BLERemoteService* pRemoteService) {
ESP_LOGD(LOG_TAG, ">> BLERemoteCharacteristic: handle: %d 0x%d, uuid: %s", handle, handle, uuid.toString().c_str());
log_v(">> BLERemoteCharacteristic: handle: %d 0x%d, uuid: %s", handle, handle, uuid.toString().c_str());
m_handle = handle;
m_uuid = uuid;
m_charProp = charProp;
@ -48,7 +41,7 @@ BLERemoteCharacteristic::BLERemoteCharacteristic(
m_notifyCallback = nullptr;
retrieveDescriptors(); // Get the descriptors for this characteristic
ESP_LOGD(LOG_TAG, "<< BLERemoteCharacteristic");
log_v("<< BLERemoteCharacteristic");
} // BLERemoteCharacteristic
@ -166,7 +159,7 @@ void BLERemoteCharacteristic::gattClientEventHandler(esp_gattc_cb_event_t event,
case ESP_GATTC_NOTIFY_EVT: {
if (evtParam->notify.handle != getHandle()) break;
if (m_notifyCallback != nullptr) {
ESP_LOGD(LOG_TAG, "Invoking callback for notification on characteristic %s", toString().c_str());
log_d("Invoking callback for notification on characteristic %s", toString().c_str());
m_notifyCallback(this, evtParam->notify.value, evtParam->notify.value_len, evtParam->notify.is_notify);
} // End we have a callback function ...
break;
@ -253,7 +246,7 @@ void BLERemoteCharacteristic::gattClientEventHandler(esp_gattc_cb_event_t event,
* @brief Populate the descriptors (if any) for this characteristic.
*/
void BLERemoteCharacteristic::retrieveDescriptors() {
ESP_LOGD(LOG_TAG, ">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str());
log_v(">> retrieveDescriptors() for characteristic: %s", getUUID().toString().c_str());
removeDescriptors(); // Remove any existing descriptors.
@ -277,13 +270,13 @@ void BLERemoteCharacteristic::retrieveDescriptors() {
}
if (status != ESP_GATT_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_get_all_descr: %s", BLEUtils::gattStatusToString(status).c_str());
log_e("esp_ble_gattc_get_all_descr: %s", BLEUtils::gattStatusToString(status).c_str());
break;
}
if (count == 0) break;
ESP_LOGD(LOG_TAG, "Found a descriptor: Handle: %d, UUID: %s", result.handle, BLEUUID(result.uuid).toString().c_str());
log_d("Found a descriptor: Handle: %d, UUID: %s", result.handle, BLEUUID(result.uuid).toString().c_str());
// We now have a new characteristic ... let us add that to our set of known characteristics
BLERemoteDescriptor* pNewRemoteDescriptor = new BLERemoteDescriptor(
@ -297,7 +290,7 @@ void BLERemoteCharacteristic::retrieveDescriptors() {
offset++;
} // while true
//m_haveCharacteristics = true; // Remember that we have received the characteristics.
ESP_LOGD(LOG_TAG, "<< retrieveDescriptors(): Found %d descriptors.", offset);
log_v("<< retrieveDescriptors(): Found %d descriptors.", offset);
} // getDescriptors
@ -314,8 +307,8 @@ std::map<std::string, BLERemoteDescriptor*>* BLERemoteCharacteristic::getDescrip
* @return The handle for this characteristic.
*/
uint16_t BLERemoteCharacteristic::getHandle() {
//ESP_LOGD(LOG_TAG, ">> getHandle: Characteristic: %s", getUUID().toString().c_str());
//ESP_LOGD(LOG_TAG, "<< getHandle: %d 0x%.2x", m_handle, m_handle);
//log_v(">> getHandle: Characteristic: %s", getUUID().toString().c_str());
//log_v("<< getHandle: %d 0x%.2x", m_handle, m_handle);
return m_handle;
} // getHandle
@ -326,15 +319,15 @@ uint16_t BLERemoteCharacteristic::getHandle() {
* @return The Remote descriptor (if present) or null if not present.
*/
BLERemoteDescriptor* BLERemoteCharacteristic::getDescriptor(BLEUUID uuid) {
ESP_LOGD(LOG_TAG, ">> getDescriptor: uuid: %s", uuid.toString().c_str());
log_v(">> getDescriptor: uuid: %s", uuid.toString().c_str());
std::string v = uuid.toString();
for (auto &myPair : m_descriptorMap) {
if (myPair.first == v) {
ESP_LOGD(LOG_TAG, "<< getDescriptor: found");
log_v("<< getDescriptor: found");
return myPair.second;
}
}
ESP_LOGD(LOG_TAG, "<< getDescriptor: Not found");
log_v("<< getDescriptor: Not found");
return nullptr;
} // getDescriptor
@ -401,11 +394,11 @@ uint8_t BLERemoteCharacteristic::readUInt8() {
* @return The value of the remote characteristic.
*/
std::string BLERemoteCharacteristic::readValue() {
ESP_LOGD(LOG_TAG, ">> readValue(): uuid: %s, handle: %d 0x%.2x", getUUID().toString().c_str(), getHandle(), getHandle());
log_v(">> readValue(): uuid: %s, handle: %d 0x%.2x", getUUID().toString().c_str(), getHandle(), getHandle());
// Check to see that we are connected.
if (!getRemoteService()->getClient()->isConnected()) {
ESP_LOGE(LOG_TAG, "Disconnected");
log_e("Disconnected");
throw BLEDisconnectedException();
}
@ -421,7 +414,7 @@ std::string BLERemoteCharacteristic::readValue() {
ESP_GATT_AUTH_REQ_NONE); // Security
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return "";
}
@ -429,7 +422,7 @@ std::string BLERemoteCharacteristic::readValue() {
// in m_value will contain our data.
m_semaphoreReadCharEvt.wait("readValue");
ESP_LOGD(LOG_TAG, "<< readValue(): length: %d", m_value.length());
log_v("<< readValue(): length: %d", m_value.length());
return m_value;
} // readValue
@ -441,7 +434,7 @@ std::string BLERemoteCharacteristic::readValue() {
* @return N/A.
*/
void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback, bool notifications) {
ESP_LOGD(LOG_TAG, ">> registerForNotify(): %s", toString().c_str());
log_v(">> registerForNotify(): %s", toString().c_str());
m_notifyCallback = notifyCallback; // Save the notification callback.
@ -455,7 +448,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback,
);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_register_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_register_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
uint8_t val[] = {0x01, 0x00};
@ -471,7 +464,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback,
);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_unregister_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_unregister_for_notify: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
}
uint8_t val[] = {0x00, 0x00};
@ -481,7 +474,7 @@ void BLERemoteCharacteristic::registerForNotify(notify_callback notifyCallback,
m_semaphoreRegForNotifyEvt.wait("registerForNotify");
ESP_LOGD(LOG_TAG, "<< registerForNotify()");
log_v("<< registerForNotify()");
} // registerForNotify
@ -547,11 +540,11 @@ void BLERemoteCharacteristic::writeValue(uint8_t newValue, bool response) {
*/
void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool response) {
// writeValue(std::string((char*)data, length), response);
ESP_LOGD(LOG_TAG, ">> writeValue(), length: %d", length);
log_v(">> writeValue(), length: %d", length);
// Check to see that we are connected.
if (!getRemoteService()->getClient()->isConnected()) {
ESP_LOGE(LOG_TAG, "Disconnected");
log_e("Disconnected");
throw BLEDisconnectedException();
}
@ -568,13 +561,13 @@ void BLERemoteCharacteristic::writeValue(uint8_t* data, size_t length, bool resp
);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_write_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_write_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
m_semaphoreWriteCharEvt.wait("writeValue");
ESP_LOGD(LOG_TAG, "<< writeValue");
log_v("<< writeValue");
} // writeValue
/**

View File

@ -9,16 +9,7 @@
#include <sstream>
#include "BLERemoteDescriptor.h"
#include "GeneralUtils.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLERemoteDescriptor";
#endif
BLERemoteDescriptor::BLERemoteDescriptor(
uint16_t handle,
@ -59,11 +50,11 @@ BLEUUID BLERemoteDescriptor::getUUID() {
std::string BLERemoteDescriptor::readValue() {
ESP_LOGD(LOG_TAG, ">> readValue: %s", toString().c_str());
log_v(">> readValue: %s", toString().c_str());
// Check to see that we are connected.
if (!getRemoteCharacteristic()->getRemoteService()->getClient()->isConnected()) {
ESP_LOGE(LOG_TAG, "Disconnected");
log_e("Disconnected");
throw BLEDisconnectedException();
}
@ -77,7 +68,7 @@ std::string BLERemoteDescriptor::readValue() {
ESP_GATT_AUTH_REQ_NONE); // Security
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_read_char: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return "";
}
@ -85,7 +76,7 @@ std::string BLERemoteDescriptor::readValue() {
// in m_value will contain our data.
m_semaphoreReadDescrEvt.wait("readValue");
ESP_LOGD(LOG_TAG, "<< readValue(): length: %d", m_value.length());
log_v("<< readValue(): length: %d", m_value.length());
return m_value;
} // readValue
@ -135,10 +126,10 @@ std::string BLERemoteDescriptor::toString() {
* @param [in] response True if we expect a response.
*/
void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response) {
ESP_LOGD(LOG_TAG, ">> writeValue: %s", toString().c_str());
log_v(">> writeValue: %s", toString().c_str());
// Check to see that we are connected.
if (!getRemoteCharacteristic()->getRemoteService()->getClient()->isConnected()) {
ESP_LOGE(LOG_TAG, "Disconnected");
log_e("Disconnected");
throw BLEDisconnectedException();
}
@ -152,9 +143,9 @@ void BLERemoteDescriptor::writeValue(uint8_t* data, size_t length, bool response
ESP_GATT_AUTH_REQ_NONE
);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_write_char_descr: %d", errRc);
log_e("esp_ble_gattc_write_char_descr: %d", errRc);
}
ESP_LOGD(LOG_TAG, "<< writeValue");
log_v("<< writeValue");
} // writeValue

View File

@ -12,15 +12,7 @@
#include "BLEUtils.h"
#include "GeneralUtils.h"
#include <esp_err.h>
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLERemoteService";
#endif
BLERemoteService::BLERemoteService(
esp_gatt_id_t srvcId,
@ -29,7 +21,7 @@ BLERemoteService::BLERemoteService(
uint16_t endHandle
) {
ESP_LOGD(LOG_TAG, ">> BLERemoteService()");
log_v(">> BLERemoteService()");
m_srvcId = srvcId;
m_pClient = pClient;
m_uuid = BLEUUID(m_srvcId);
@ -37,7 +29,7 @@ BLERemoteService::BLERemoteService(
m_startHandle = startHandle;
m_endHandle = endHandle;
ESP_LOGD(LOG_TAG, "<< BLERemoteService()");
log_v("<< BLERemoteService()");
}
@ -103,7 +95,7 @@ void BLERemoteService::gattClientEventHandler(
&m_srvcId,
&evtParam->get_char.char_id);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_get_characteristic: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_get_characteristic: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
break;
}
@ -165,7 +157,7 @@ BLERemoteCharacteristic* BLERemoteService::getCharacteristic(BLEUUID uuid) {
* @return N/A
*/
void BLERemoteService::retrieveCharacteristics() {
ESP_LOGD(LOG_TAG, ">> getCharacteristics() for service: %s", getUUID().toString().c_str());
log_v(">> getCharacteristics() for service: %s", getUUID().toString().c_str());
removeCharacteristics(); // Forget any previous characteristics.
@ -188,7 +180,7 @@ void BLERemoteService::retrieveCharacteristics() {
}
if (status != ESP_GATT_OK) { // If we got an error, end.
ESP_LOGE(LOG_TAG, "esp_ble_gattc_get_all_char: %s", BLEUtils::gattStatusToString(status).c_str());
log_e("esp_ble_gattc_get_all_char: %s", BLEUtils::gattStatusToString(status).c_str());
break;
}
@ -196,7 +188,7 @@ void BLERemoteService::retrieveCharacteristics() {
break;
}
ESP_LOGD(LOG_TAG, "Found a characteristic: Handle: %d, UUID: %s", result.char_handle, BLEUUID(result.uuid).toString().c_str());
log_d("Found a characteristic: Handle: %d, UUID: %s", result.char_handle, BLEUUID(result.uuid).toString().c_str());
// We now have a new characteristic ... let us add that to our set of known characteristics
BLERemoteCharacteristic *pNewRemoteCharacteristic = new BLERemoteCharacteristic(
@ -212,7 +204,7 @@ void BLERemoteService::retrieveCharacteristics() {
} // Loop forever (until we break inside the loop).
m_haveCharacteristics = true; // Remember that we have received the characteristics.
ESP_LOGD(LOG_TAG, "<< getCharacteristics()");
log_v("<< getCharacteristics()");
} // getCharacteristics
@ -221,14 +213,14 @@ void BLERemoteService::retrieveCharacteristics() {
* @return A map of all the characteristics of this service.
*/
std::map<std::string, BLERemoteCharacteristic*>* BLERemoteService::getCharacteristics() {
ESP_LOGD(LOG_TAG, ">> getCharacteristics() for service: %s", getUUID().toString().c_str());
log_v(">> getCharacteristics() for service: %s", getUUID().toString().c_str());
// If is possible that we have not read the characteristics associated with the service so do that
// now. The request to retrieve the characteristics by calling "retrieveCharacteristics" is a blocking
// call and does not return until all the characteristics are available.
if (!m_haveCharacteristics) {
retrieveCharacteristics();
}
ESP_LOGD(LOG_TAG, "<< getCharacteristics() for service: %s", getUUID().toString().c_str());
log_v("<< getCharacteristics() for service: %s", getUUID().toString().c_str());
return &m_characteristicMap;
} // getCharacteristics
@ -265,8 +257,8 @@ uint16_t BLERemoteService::getStartHandle() {
uint16_t BLERemoteService::getHandle() {
ESP_LOGD(LOG_TAG, ">> getHandle: service: %s", getUUID().toString().c_str());
ESP_LOGD(LOG_TAG, "<< getHandle: %d 0x%.2x", getStartHandle(), getStartHandle());
log_v(">> getHandle: service: %s", getUUID().toString().c_str());
log_v("<< getHandle: %d 0x%.2x", getStartHandle(), getStartHandle());
return getStartHandle();
} // getHandle
@ -279,9 +271,9 @@ BLEUUID BLERemoteService::getUUID() {
* @brief Read the value of a characteristic associated with this service.
*/
std::string BLERemoteService::getValue(BLEUUID characteristicUuid) {
ESP_LOGD(LOG_TAG, ">> readValue: uuid: %s", characteristicUuid.toString().c_str());
log_v(">> readValue: uuid: %s", characteristicUuid.toString().c_str());
std::string ret = getCharacteristic(characteristicUuid)->readValue();
ESP_LOGD(LOG_TAG, "<< readValue");
log_v("<< readValue");
return ret;
} // readValue
@ -314,9 +306,9 @@ void BLERemoteService::removeCharacteristics() {
* @throws BLEUuidNotFound
*/
void BLERemoteService::setValue(BLEUUID characteristicUuid, std::string value) {
ESP_LOGD(LOG_TAG, ">> setValue: uuid: %s", characteristicUuid.toString().c_str());
log_v(">> setValue: uuid: %s", characteristicUuid.toString().c_str());
getCharacteristic(characteristicUuid)->writeValue(value);
ESP_LOGD(LOG_TAG, "<< setValue");
log_v("<< setValue");
} // setValue

View File

@ -16,16 +16,7 @@
#include "BLEScan.h"
#include "BLEUtils.h"
#include "GeneralUtils.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEScan";
#endif
/**
* Constructor
@ -75,7 +66,7 @@ void BLEScan::handleGAPEvent(
// Event that indicates that the duration allowed for the search has completed or that we have been
// asked to stop.
case ESP_GAP_SEARCH_INQ_CMPL_EVT: {
ESP_LOGW(LOG_TAG, "ESP_GAP_SEARCH_INQ_CMPL_EVT");
log_w("ESP_GAP_SEARCH_INQ_CMPL_EVT");
m_stopped = true;
m_semaphoreScanEnd.give();
if (m_scanCompleteCB != nullptr) {
@ -103,15 +94,15 @@ void BLEScan::handleGAPEvent(
}
if (found && !m_wantDuplicates) { // If we found a previous entry AND we don't want duplicates, then we are done.
ESP_LOGD(LOG_TAG, "Ignoring %s, already seen it.", advertisedAddress.toString().c_str());
log_d("Ignoring %s, already seen it.", advertisedAddress.toString().c_str());
vTaskDelay(1); // <--- allow to switch task in case we scan infinity and dont have new devices to report, or we are blocked here
break;
}
// We now construct a model of the advertised device that we have just found for the first
// time.
// ESP_LOG_BUFFER_HEXDUMP(LOG_TAG, (uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len, ESP_LOG_DEBUG);
// ESP_LOGW(LOG_TAG, "bytes length: %d + %d, addr type: %d", param->scan_rst.adv_data_len, param->scan_rst.scan_rsp_len, param->scan_rst.ble_addr_type);
// ESP_LOG_BUFFER_HEXDUMP((uint8_t*)param->scan_rst.ble_adv, param->scan_rst.adv_data_len + param->scan_rst.scan_rsp_len, ESP_LOG_DEBUG);
// log_w("bytes length: %d + %d, addr type: %d", param->scan_rst.adv_data_len, param->scan_rst.scan_rsp_len, param->scan_rst.ble_addr_type);
BLEAdvertisedDevice *advertisedDevice = new BLEAdvertisedDevice();
advertisedDevice->setAddress(advertisedAddress);
advertisedDevice->setRSSI(param->scan_rst.rssi);
@ -201,7 +192,7 @@ void BLEScan::setWindow(uint16_t windowMSecs) {
* @return True if scan started or false if there was an error.
*/
bool BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), bool is_continue) {
ESP_LOGD(LOG_TAG, ">> start(duration=%d)", duration);
log_v(">> start(duration=%d)", duration);
m_semaphoreScanEnd.take(std::string("start"));
m_scanCompleteCB = scanCompleteCB; // Save the callback to be invoked when the scan completes.
@ -218,7 +209,7 @@ bool BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), b
esp_err_t errRc = ::esp_ble_gap_set_scan_params(&m_scan_params);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_set_scan_params: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_set_scan_params: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc));
m_semaphoreScanEnd.give();
return false;
}
@ -226,14 +217,14 @@ bool BLEScan::start(uint32_t duration, void (*scanCompleteCB)(BLEScanResults), b
errRc = ::esp_ble_gap_start_scanning(duration);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_start_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_start_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc));
m_semaphoreScanEnd.give();
return false;
}
m_stopped = false;
ESP_LOGD(LOG_TAG, "<< start()");
log_v("<< start()");
return true;
} // start
@ -256,7 +247,7 @@ BLEScanResults BLEScan::start(uint32_t duration, bool is_continue) {
* @return N/A.
*/
void BLEScan::stop() {
ESP_LOGD(LOG_TAG, ">> stop()");
log_v(">> stop()");
esp_err_t errRc = ::esp_ble_gap_stop_scanning();
@ -264,16 +255,16 @@ void BLEScan::stop() {
m_semaphoreScanEnd.give();
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gap_stop_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gap_stop_scanning: err: %d, text: %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
ESP_LOGD(LOG_TAG, "<< stop()");
log_v("<< stop()");
} // stop
// delete peer device from cache after disconnecting, it is required in case we are connecting to devices with not public address
void BLEScan::erase(BLEAddress address) {
ESP_LOGI(LOG_TAG, "erase device: %s", address.toString().c_str());
log_i("erase device: %s", address.toString().c_str());
BLEAdvertisedDevice *advertisedDevice = m_scanResults.m_vectorAdvertisedDevices.find(address.toString())->second;
m_scanResults.m_vectorAdvertisedDevices.erase(address.toString());
delete advertisedDevice;
@ -284,9 +275,9 @@ void BLEScan::erase(BLEAddress address) {
* @brief Dump the scan results to the log.
*/
void BLEScanResults::dump() {
ESP_LOGD(LOG_TAG, ">> Dump scan results:");
log_v(">> Dump scan results:");
for (int i=0; i<getCount(); i++) {
ESP_LOGD(LOG_TAG, "- %s", getDevice(i).toString().c_str());
log_d("- %s", getDevice(i).toString().c_str());
}
} // dump

View File

@ -17,16 +17,7 @@
#include <string.h>
#include <string>
#include <unordered_set>
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEServer";
#endif
/**
* @brief Construct a %BLE Server
@ -73,12 +64,12 @@ BLEService* BLEServer::createService(const char* uuid) {
* @return A reference to the new service object.
*/
BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles, uint8_t inst_id) {
ESP_LOGD(LOG_TAG, ">> createService - %s", uuid.toString().c_str());
log_v(">> createService - %s", uuid.toString().c_str());
m_semaphoreCreateEvt.take("createService");
// Check that a service with the supplied UUID does not already exist.
if (m_serviceMap.getByUUID(uuid) != nullptr) {
ESP_LOGW(LOG_TAG, "<< Attempt to create a new service with uuid %s but a service with that UUID already exists.",
log_w("<< Attempt to create a new service with uuid %s but a service with that UUID already exists.",
uuid.toString().c_str());
}
@ -89,7 +80,7 @@ BLEService* BLEServer::createService(BLEUUID uuid, uint32_t numHandles, uint8_t
m_semaphoreCreateEvt.wait("createService");
ESP_LOGD(LOG_TAG, "<< createService");
log_v("<< createService");
return pService;
} // createService
@ -149,7 +140,7 @@ uint16_t BLEServer::getGattsIf() {
*
*/
void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t gatts_if, esp_ble_gatts_cb_param_t* param) {
ESP_LOGD(LOG_TAG, ">> handleGATTServerEvent: %s",
log_v(">> handleGATTServerEvent: %s",
BLEUtils::gattServerEventTypeToString(event).c_str());
switch(event) {
@ -277,7 +268,7 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t
// Invoke the handler for every Service we have.
m_serviceMap.handleGATTServerEvent(event, gatts_if, param);
ESP_LOGD(LOG_TAG, "<< handleGATTServerEvent");
log_v("<< handleGATTServerEvent");
} // handleGATTServerEvent
@ -287,11 +278,11 @@ void BLEServer::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t
* @return N/A
*/
void BLEServer::registerApp(uint16_t m_appId) {
ESP_LOGD(LOG_TAG, ">> registerApp - %d", m_appId);
log_v(">> registerApp - %d", m_appId);
m_semaphoreRegisterAppEvt.take("registerApp"); // Take the mutex, will be released by ESP_GATTS_REG_EVT event.
::esp_ble_gatts_app_register(m_appId);
m_semaphoreRegisterAppEvt.wait("registerApp");
ESP_LOGD(LOG_TAG, "<< registerApp");
log_v("<< registerApp");
} // registerApp
@ -324,9 +315,9 @@ void BLEServer::removeService(BLEService* service) {
* retrieving the advertising object and invoking start upon it.
*/
void BLEServer::startAdvertising() {
ESP_LOGD(LOG_TAG, ">> startAdvertising");
log_v(">> startAdvertising");
BLEDevice::startAdvertising();
ESP_LOGD(LOG_TAG, "<< startAdvertising");
log_v("<< startAdvertising");
} // startAdvertising
/**
@ -344,34 +335,34 @@ bool BLEServer::connect(BLEAddress address) {
1 // direct connection
);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gattc_open: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return false;
}
uint32_t rc = m_semaphoreOpenEvt.wait("connect"); // Wait for the connection to complete.
ESP_LOGD(LOG_TAG, "<< connect(), rc=%d", rc==ESP_GATT_OK);
log_v("<< connect(), rc=%d", rc==ESP_GATT_OK);
return rc == ESP_GATT_OK;
} // connect
void BLEServerCallbacks::onConnect(BLEServer* pServer) {
ESP_LOGD("BLEServerCallbacks", ">> onConnect(): Default");
ESP_LOGD("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str());
ESP_LOGD("BLEServerCallbacks", "<< onConnect()");
log_d("BLEServerCallbacks", ">> onConnect(): Default");
log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str());
log_d("BLEServerCallbacks", "<< onConnect()");
} // onConnect
void BLEServerCallbacks::onConnect(BLEServer* pServer, esp_ble_gatts_cb_param_t* param) {
ESP_LOGD("BLEServerCallbacks", ">> onConnect(): Default");
ESP_LOGD("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str());
ESP_LOGD("BLEServerCallbacks", "<< onConnect()");
log_d("BLEServerCallbacks", ">> onConnect(): Default");
log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str());
log_d("BLEServerCallbacks", "<< onConnect()");
} // onConnect
void BLEServerCallbacks::onDisconnect(BLEServer* pServer) {
ESP_LOGD("BLEServerCallbacks", ">> onDisconnect(): Default");
ESP_LOGD("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str());
ESP_LOGD("BLEServerCallbacks", "<< onDisconnect()");
log_d("BLEServerCallbacks", ">> onDisconnect(): Default");
log_d("BLEServerCallbacks", "Device: %s", BLEDevice::toString().c_str());
log_d("BLEServerCallbacks", "<< onDisconnect()");
} // onDisconnect
/* multi connect support */

View File

@ -20,14 +20,7 @@
#include "BLEService.h"
#include "BLEUtils.h"
#include "GeneralUtils.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEService"; // Tag for logging.
#endif
#define NULL_HANDLE (0xffff)
@ -64,7 +57,7 @@ BLEService::BLEService(BLEUUID uuid, uint16_t numHandles) {
*/
void BLEService::executeCreate(BLEServer* pServer) {
ESP_LOGD(LOG_TAG, ">> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: %s", getUUID().toString().c_str());
log_v(">> executeCreate() - Creating service (esp_ble_gatts_create_service) service uuid: %s", getUUID().toString().c_str());
m_pServer = pServer;
m_semaphoreCreateEvt.take("executeCreate"); // Take the mutex and release at event ESP_GATTS_CREATE_EVT
@ -75,12 +68,12 @@ void BLEService::executeCreate(BLEServer* pServer) {
esp_err_t errRc = ::esp_ble_gatts_create_service(getServer()->getGattsIf(), &srvc_id, m_numHandles); // The maximum number of handles associated with the service.
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gatts_create_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gatts_create_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
m_semaphoreCreateEvt.wait("executeCreate");
ESP_LOGD(LOG_TAG, "<< executeCreate");
log_v("<< executeCreate");
} // executeCreate
@ -91,18 +84,18 @@ void BLEService::executeCreate(BLEServer* pServer) {
*/
void BLEService::executeDelete() {
ESP_LOGD(LOG_TAG, ">> executeDelete()");
log_v(">> executeDelete()");
m_semaphoreDeleteEvt.take("executeDelete"); // Take the mutex and release at event ESP_GATTS_DELETE_EVT
esp_err_t errRc = ::esp_ble_gatts_delete_service(getHandle());
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "esp_ble_gatts_delete_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("esp_ble_gatts_delete_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
m_semaphoreDeleteEvt.wait("executeDelete");
ESP_LOGD(LOG_TAG, "<< executeDelete");
log_v("<< executeDelete");
} // executeDelete
@ -111,10 +104,10 @@ void BLEService::executeDelete() {
* @return N/A.
*/
void BLEService::dump() {
ESP_LOGD(LOG_TAG, "Service: uuid:%s, handle: 0x%.2x",
log_d("Service: uuid:%s, handle: 0x%.2x",
m_uuid.toString().c_str(),
m_handle);
ESP_LOGD(LOG_TAG, "Characteristics:\n%s", m_characteristicMap.toString().c_str());
log_d("Characteristics:\n%s", m_characteristicMap.toString().c_str());
} // dump
@ -138,9 +131,9 @@ void BLEService::start() {
// We start the service through its local handle which was returned in the ESP_GATTS_CREATE_EVT event
// obtained as a result of calling esp_ble_gatts_create_service().
//
ESP_LOGD(LOG_TAG, ">> start(): Starting service (esp_ble_gatts_start_service): %s", toString().c_str());
log_v(">> start(): Starting service (esp_ble_gatts_start_service): %s", toString().c_str());
if (m_handle == NULL_HANDLE) {
ESP_LOGE(LOG_TAG, "<< !!! We attempted to start a service but don't know its handle!");
log_e("<< !!! We attempted to start a service but don't know its handle!");
return;
}
@ -158,12 +151,12 @@ void BLEService::start() {
esp_err_t errRc = ::esp_ble_gatts_start_service(m_handle);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_start_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("<< esp_ble_gatts_start_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
m_semaphoreStartEvt.wait("start");
ESP_LOGD(LOG_TAG, "<< start()");
log_v("<< start()");
} // start
@ -174,9 +167,9 @@ void BLEService::stop() {
// We ask the BLE runtime to start the service and then create each of the characteristics.
// We start the service through its local handle which was returned in the ESP_GATTS_CREATE_EVT event
// obtained as a result of calling esp_ble_gatts_create_service().
ESP_LOGD(LOG_TAG, ">> stop(): Stopping service (esp_ble_gatts_stop_service): %s", toString().c_str());
log_v(">> stop(): Stopping service (esp_ble_gatts_stop_service): %s", toString().c_str());
if (m_handle == NULL_HANDLE) {
ESP_LOGE(LOG_TAG, "<< !!! We attempted to stop a service but don't know its handle!");
log_e("<< !!! We attempted to stop a service but don't know its handle!");
return;
}
@ -184,12 +177,12 @@ void BLEService::stop() {
esp_err_t errRc = ::esp_ble_gatts_stop_service(m_handle);
if (errRc != ESP_OK) {
ESP_LOGE(LOG_TAG, "<< esp_ble_gatts_stop_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
log_e("<< esp_ble_gatts_stop_service: rc=%d %s", errRc, GeneralUtils::errorToString(errRc));
return;
}
m_semaphoreStopEvt.wait("stop");
ESP_LOGD(LOG_TAG, "<< stop()");
log_v("<< stop()");
} // start
@ -198,13 +191,13 @@ void BLEService::stop() {
* @param [in] handle The handle associated with the service.
*/
void BLEService::setHandle(uint16_t handle) {
ESP_LOGD(LOG_TAG, ">> setHandle - Handle=0x%.2x, service UUID=%s)", handle, getUUID().toString().c_str());
log_v(">> setHandle - Handle=0x%.2x, service UUID=%s)", handle, getUUID().toString().c_str());
if (m_handle != NULL_HANDLE) {
ESP_LOGE(LOG_TAG, "!!! Handle is already set %.2x", m_handle);
log_e("!!! Handle is already set %.2x", m_handle);
return;
}
m_handle = handle;
ESP_LOGD(LOG_TAG, "<< setHandle");
log_v("<< setHandle");
} // setHandle
@ -226,14 +219,14 @@ void BLEService::addCharacteristic(BLECharacteristic* pCharacteristic) {
// BLECharacteristicMap class instance found in m_characteristicMap. We add the characteristic
// to the map and then ask the service to add the characteristic at the BLE level (ESP-IDF).
ESP_LOGD(LOG_TAG, ">> addCharacteristic()");
ESP_LOGD(LOG_TAG, "Adding characteristic: uuid=%s to service: %s",
log_v(">> addCharacteristic()");
log_d("Adding characteristic: uuid=%s to service: %s",
pCharacteristic->getUUID().toString().c_str(),
toString().c_str());
// Check that we don't add the same characteristic twice.
if (m_characteristicMap.getByUUID(pCharacteristic->getUUID()) != nullptr) {
ESP_LOGW(LOG_TAG, "<< Adding a new characteristic with the same UUID as a previous one");
log_w("<< Adding a new characteristic with the same UUID as a previous one");
//return;
}
@ -241,7 +234,7 @@ void BLEService::addCharacteristic(BLECharacteristic* pCharacteristic) {
// but not by handle. The handle is allocated to us on the ESP_GATTS_ADD_CHAR_EVT.
m_characteristicMap.setByUUID(pCharacteristic, pCharacteristic->getUUID());
ESP_LOGD(LOG_TAG, "<< addCharacteristic()");
log_v("<< addCharacteristic()");
} // addCharacteristic
@ -287,7 +280,7 @@ void BLEService::handleGATTServerEvent(esp_gatts_cb_event_t event, esp_gatt_if_t
if (m_handle == param->add_char.service_handle) {
BLECharacteristic *pCharacteristic = getLastCreatedCharacteristic();
if (pCharacteristic == nullptr) {
ESP_LOGE(LOG_TAG, "Expected to find characteristic with UUID: %s, but didnt!",
log_e("Expected to find characteristic with UUID: %s, but didnt!",
BLEUUID(param->add_char.char_uuid).toString().c_str());
dump();
break;

View File

@ -13,15 +13,7 @@
#include <assert.h>
#include <stdlib.h>
#include "BLEUUID.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEUUID";
#endif
/**
* @brief Copy memory from source to target but in reverse order.
@ -121,7 +113,7 @@ BLEUUID::BLEUUID(std::string value) {
}
}
else {
ESP_LOGE(LOG_TAG, "ERROR: UUID value not 2, 4, 16 or 36 bytes");
log_e("ERROR: UUID value not 2, 4, 16 or 36 bytes");
m_valueSet = false;
}
} //BLEUUID(std::string)
@ -136,7 +128,7 @@ BLEUUID::BLEUUID(std::string value) {
*/
BLEUUID::BLEUUID(uint8_t* pData, size_t size, bool msbFirst) {
if (size != 16) {
ESP_LOGE(LOG_TAG, "ERROR: UUID length not 16 bytes");
log_e("ERROR: UUID length not 16 bytes");
return;
}
m_uuid.len = ESP_UUID_LEN_128;
@ -212,7 +204,7 @@ uint8_t BLEUUID::bitSize() {
case ESP_UUID_LEN_128:
return 128;
default:
ESP_LOGE(LOG_TAG, "Unknown UUID length: %d", m_uuid.len);
log_e("Unknown UUID length: %d", m_uuid.len);
return 0;
} // End of switch
} // bitSize
@ -225,7 +217,7 @@ uint8_t BLEUUID::bitSize() {
* @return True if the UUIDs are equal and false otherwise.
*/
bool BLEUUID::equals(BLEUUID uuid) {
//ESP_LOGD(TAG, "Comparing: %s to %s", toString().c_str(), uuid.toString().c_str());
//log_d("Comparing: %s to %s", toString().c_str(), uuid.toString().c_str());
if (!m_valueSet || !uuid.m_valueSet) return false;
if (uuid.m_uuid.len != m_uuid.len) {
@ -279,12 +271,12 @@ BLEUUID BLEUUID::fromString(std::string _uuid) {
* @return The native UUID value or NULL if not set.
*/
esp_bt_uuid_t* BLEUUID::getNative() {
//ESP_LOGD(TAG, ">> getNative()")
//log_d(">> getNative()")
if (m_valueSet == false) {
ESP_LOGD(LOG_TAG, "<< Return of un-initialized UUID!");
log_v("<< Return of un-initialized UUID!");
return nullptr;
}
//ESP_LOGD(TAG, "<< getNative()");
//log_d("<< getNative()");
return &m_uuid;
} // getNative
@ -296,7 +288,7 @@ esp_bt_uuid_t* BLEUUID::getNative() {
* will convert 16 or 32 bit representations to the full 128bit.
*/
BLEUUID BLEUUID::to128() {
//ESP_LOGD(LOG_TAG, ">> toFull() - %s", toString().c_str());
//log_v(">> toFull() - %s", toString().c_str());
// If we either don't have a value or are already a 128 bit UUID, nothing further to do.
if (!m_valueSet || m_uuid.len == ESP_UUID_LEN_128) {
@ -338,7 +330,7 @@ BLEUUID BLEUUID::to128() {
m_uuid.uuid.uuid128[0] = 0xfb;
m_uuid.len = ESP_UUID_LEN_128;
//ESP_LOGD(TAG, "<< toFull <- %s", toString().c_str());
//log_d("<< toFull <- %s", toString().c_str());
return *this;
} // to128

View File

@ -23,14 +23,7 @@
#include <sstream>
#include <iomanip>
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "BLEUtils"; // Tag for logging.
#endif
/*
static std::map<std::string, BLEClient*> g_addressMap;
@ -744,7 +737,7 @@ const char* BLEUtils::advTypeToString(uint8_t advType) {
return "ESP_BLE_AD_MANUFACTURER_SPECIFIC_TYPE";
#endif
default:
ESP_LOGV(LOG_TAG, " adv data type: 0x%x", advType);
log_v(" adv data type: 0x%x", advType);
return "";
} // End switch
} // advTypeToString
@ -779,7 +772,7 @@ char* BLEUtils::buildHexData(uint8_t* target, uint8_t* source, uint8_t length) {
if (target == nullptr) {
target = (uint8_t*) malloc(length * 2 + 1);
if (target == nullptr) {
ESP_LOGE(LOG_TAG, "buildHexData: malloc failed");
log_e("buildHexData: malloc failed");
return nullptr;
}
}
@ -949,7 +942,7 @@ std::string BLEUtils::gattClientEventTypeToString(esp_gattc_cb_event_t eventType
return "ESP_GATTC_WRITE_DESCR_EVT";
#endif
default:
ESP_LOGV(LOG_TAG, "Unknown GATT Client event type: %d", eventType);
log_v("Unknown GATT Client event type: %d", eventType);
return "Unknown";
}
} // gattClientEventTypeToString
@ -1047,14 +1040,14 @@ const char* BLEUtils::devTypeToString(esp_bt_dev_type_t type) {
void BLEUtils::dumpGapEvent(
esp_gap_ble_cb_event_t event,
esp_ble_gap_cb_param_t* param) {
ESP_LOGV(LOG_TAG, "Received a GAP event: %s", gapEventToString(event));
log_v("Received a GAP event: %s", gapEventToString(event));
switch (event) {
#if CONFIG_LOG_DEFAULT_LEVEL > 4
// ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
// adv_data_cmpl
// - esp_bt_status_t
case ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->adv_data_cmpl.status);
log_v("[status: %d]", param->adv_data_cmpl.status);
break;
} // ESP_GAP_BLE_ADV_DATA_SET_COMPLETE_EVT
@ -1063,7 +1056,7 @@ void BLEUtils::dumpGapEvent(
// adv_data_raw_cmpl
// - esp_bt_status_t status
case ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->adv_data_raw_cmpl.status);
log_v("[status: %d]", param->adv_data_raw_cmpl.status);
break;
} // ESP_GAP_BLE_ADV_DATA_RAW_SET_COMPLETE_EVT
@ -1072,7 +1065,7 @@ void BLEUtils::dumpGapEvent(
// adv_start_cmpl
// - esp_bt_status_t status
case ESP_GAP_BLE_ADV_START_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->adv_start_cmpl.status);
log_v("[status: %d]", param->adv_start_cmpl.status);
break;
} // ESP_GAP_BLE_ADV_START_COMPLETE_EVT
@ -1081,7 +1074,7 @@ void BLEUtils::dumpGapEvent(
// adv_stop_cmpl
// - esp_bt_status_t status
case ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->adv_stop_cmpl.status);
log_v("[status: %d]", param->adv_stop_cmpl.status);
break;
} // ESP_GAP_BLE_ADV_STOP_COMPLETE_EVT
@ -1096,7 +1089,7 @@ void BLEUtils::dumpGapEvent(
// - esp_bd_addr_type_t addr_type
// - esp_bt_dev_type_t dev_type
case ESP_GAP_BLE_AUTH_CMPL_EVT: {
ESP_LOGV(LOG_TAG, "[bd_addr: %s, key_present: %d, key: ***, key_type: %d, success: %d, fail_reason: %d, addr_type: ***, dev_type: %s]",
log_v("[bd_addr: %s, key_present: %d, key: ***, key_type: %d, success: %d, fail_reason: %d, addr_type: ***, dev_type: %s]",
BLEAddress(param->ble_security.auth_cmpl.bd_addr).toString().c_str(),
param->ble_security.auth_cmpl.key_present,
param->ble_security.auth_cmpl.key_type,
@ -1112,7 +1105,7 @@ void BLEUtils::dumpGapEvent(
// clear_bond_dev_cmpl
// - esp_bt_status_t status
case ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->clear_bond_dev_cmpl.status);
log_v("[status: %d]", param->clear_bond_dev_cmpl.status);
break;
} // ESP_GAP_BLE_CLEAR_BOND_DEV_COMPLETE_EVT
@ -1128,7 +1121,7 @@ void BLEUtils::dumpGapEvent(
// ESP_GAP_BLE_NC_REQ_EVT
case ESP_GAP_BLE_NC_REQ_EVT: {
ESP_LOGV(LOG_TAG, "[bd_addr: %s, passkey: %d]",
log_v("[bd_addr: %s, passkey: %d]",
BLEAddress(param->ble_security.key_notif.bd_addr).toString().c_str(),
param->ble_security.key_notif.passkey);
break;
@ -1141,7 +1134,7 @@ void BLEUtils::dumpGapEvent(
// - int8_t rssi
// - esp_bd_addr_t remote_addr
case ESP_GAP_BLE_READ_RSSI_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d, rssi: %d, remote_addr: %s]",
log_v("[status: %d, rssi: %d, remote_addr: %s]",
param->read_rssi_cmpl.status,
param->read_rssi_cmpl.rssi,
BLEAddress(param->read_rssi_cmpl.remote_addr).toString().c_str()
@ -1154,7 +1147,7 @@ void BLEUtils::dumpGapEvent(
// scan_param_cmpl.
// - esp_bt_status_t status
case ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_param_cmpl.status);
log_v("[status: %d]", param->scan_param_cmpl.status);
break;
} // ESP_GAP_BLE_SCAN_PARAM_SET_COMPLETE_EVT
@ -1175,7 +1168,7 @@ void BLEUtils::dumpGapEvent(
case ESP_GAP_BLE_SCAN_RESULT_EVT: {
switch (param->scan_rst.search_evt) {
case ESP_GAP_SEARCH_INQ_RES_EVT: {
ESP_LOGV(LOG_TAG, "search_evt: %s, bda: %s, dev_type: %s, ble_addr_type: %s, ble_evt_type: %s, rssi: %d, ble_adv: ??, flag: %d (%s), num_resps: %d, adv_data_len: %d, scan_rsp_len: %d",
log_v("search_evt: %s, bda: %s, dev_type: %s, ble_addr_type: %s, ble_evt_type: %s, rssi: %d, ble_adv: ??, flag: %d (%s), num_resps: %d, adv_data_len: %d, scan_rsp_len: %d",
searchEventTypeToString(param->scan_rst.search_evt),
BLEAddress(param->scan_rst.bda).toString().c_str(),
devTypeToString(param->scan_rst.dev_type),
@ -1192,7 +1185,7 @@ void BLEUtils::dumpGapEvent(
} // ESP_GAP_SEARCH_INQ_RES_EVT
default: {
ESP_LOGV(LOG_TAG, "search_evt: %s",searchEventTypeToString(param->scan_rst.search_evt));
log_v("search_evt: %s",searchEventTypeToString(param->scan_rst.search_evt));
break;
}
}
@ -1204,13 +1197,13 @@ void BLEUtils::dumpGapEvent(
// scan_rsp_data_cmpl
// - esp_bt_status_t status
case ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_rsp_data_cmpl.status);
log_v("[status: %d]", param->scan_rsp_data_cmpl.status);
break;
} // ESP_GAP_BLE_SCAN_RSP_DATA_SET_COMPLETE_EVT
// ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT
case ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_rsp_data_raw_cmpl.status);
log_v("[status: %d]", param->scan_rsp_data_raw_cmpl.status);
break;
} // ESP_GAP_BLE_SCAN_RSP_DATA_RAW_SET_COMPLETE_EVT
@ -1219,7 +1212,7 @@ void BLEUtils::dumpGapEvent(
// scan_start_cmpl
// - esp_bt_status_t status
case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_start_cmpl.status);
log_v("[status: %d]", param->scan_start_cmpl.status);
break;
} // ESP_GAP_BLE_SCAN_START_COMPLETE_EVT
@ -1228,7 +1221,7 @@ void BLEUtils::dumpGapEvent(
// scan_stop_cmpl
// - esp_bt_status_t status
case ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d]", param->scan_stop_cmpl.status);
log_v("[status: %d]", param->scan_stop_cmpl.status);
break;
} // ESP_GAP_BLE_SCAN_STOP_COMPLETE_EVT
@ -1243,7 +1236,7 @@ void BLEUtils::dumpGapEvent(
// - uint16_t conn_int
// - uint16_t timeout
case ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT: {
ESP_LOGV(LOG_TAG, "[status: %d, bd_addr: %s, min_int: %d, max_int: %d, latency: %d, conn_int: %d, timeout: %d]",
log_v("[status: %d, bd_addr: %s, min_int: %d, max_int: %d, latency: %d, conn_int: %d, timeout: %d]",
param->update_conn_params.status,
BLEAddress(param->update_conn_params.bda).toString().c_str(),
param->update_conn_params.min_int,
@ -1257,12 +1250,12 @@ void BLEUtils::dumpGapEvent(
// ESP_GAP_BLE_SEC_REQ_EVT
case ESP_GAP_BLE_SEC_REQ_EVT: {
ESP_LOGV(LOG_TAG, "[bd_addr: %s]", BLEAddress(param->ble_security.ble_req.bd_addr).toString().c_str());
log_v("[bd_addr: %s]", BLEAddress(param->ble_security.ble_req.bd_addr).toString().c_str());
break;
} // ESP_GAP_BLE_SEC_REQ_EVT
#endif
default: {
ESP_LOGV(LOG_TAG, "*** dumpGapEvent: Logger not coded ***");
log_v("*** dumpGapEvent: Logger not coded ***");
break;
} // default
} // switch
@ -1281,7 +1274,7 @@ void BLEUtils::dumpGattClientEvent(
esp_ble_gattc_cb_param_t* evtParam) {
//esp_ble_gattc_cb_param_t* evtParam = (esp_ble_gattc_cb_param_t*) param;
ESP_LOGV(LOG_TAG, "GATT Event: %s", BLEUtils::gattClientEventTypeToString(event).c_str());
log_v("GATT Event: %s", BLEUtils::gattClientEventTypeToString(event).c_str());
switch (event) {
#if CONFIG_LOG_DEFAULT_LEVEL > 4
// ESP_GATTC_CLOSE_EVT
@ -1292,7 +1285,7 @@ void BLEUtils::dumpGattClientEvent(
// - esp_bd_addr_t remote_bda
// - esp_gatt_conn_reason_t reason
case ESP_GATTC_CLOSE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, reason:%s, conn_id: %d]",
log_v("[status: %s, reason:%s, conn_id: %d]",
BLEUtils::gattStatusToString(evtParam->close.status).c_str(),
BLEUtils::gattCloseReasonToString(evtParam->close.reason).c_str(),
evtParam->close.conn_id);
@ -1306,7 +1299,7 @@ void BLEUtils::dumpGattClientEvent(
// - uint16_t conn_id
// - esp_bd_addr_t remote_bda
case ESP_GATTC_CONNECT_EVT: {
ESP_LOGV(LOG_TAG, "[conn_id: %d, remote_bda: %s]",
log_v("[conn_id: %d, remote_bda: %s]",
evtParam->connect.conn_id,
BLEAddress(evtParam->connect.remote_bda).toString().c_str()
);
@ -1320,7 +1313,7 @@ void BLEUtils::dumpGattClientEvent(
// - uint16_t conn_id
// - esp_bd_addr_t remote_bda
case ESP_GATTC_DISCONNECT_EVT: {
ESP_LOGV(LOG_TAG, "[reason: %s, conn_id: %d, remote_bda: %s]",
log_v("[reason: %s, conn_id: %d, remote_bda: %s]",
BLEUtils::gattCloseReasonToString(evtParam->disconnect.reason).c_str(),
evtParam->disconnect.conn_id,
BLEAddress(evtParam->disconnect.remote_bda).toString().c_str()
@ -1346,7 +1339,7 @@ void BLEUtils::dumpGattClientEvent(
if (evtParam->get_char.char_id.uuid.len == ESP_UUID_LEN_16) {
description = BLEUtils::gattCharacteristicUUIDToString(evtParam->get_char.char_id.uuid.uuid.uuid16);
}
ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, srvc_id: %s, char_id: %s [description: %s]\nchar_prop: %s]",
log_v("[status: %s, conn_id: %d, srvc_id: %s, char_id: %s [description: %s]\nchar_prop: %s]",
BLEUtils::gattStatusToString(evtParam->get_char.status).c_str(),
evtParam->get_char.conn_id,
BLEUtils::gattServiceIdToString(evtParam->get_char.srvc_id).c_str(),
@ -1355,7 +1348,7 @@ void BLEUtils::dumpGattClientEvent(
BLEUtils::characteristicPropertiesToString(evtParam->get_char.char_prop).c_str()
);
} else {
ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, srvc_id: %s]",
log_v("[status: %s, conn_id: %d, srvc_id: %s]",
BLEUtils::gattStatusToString(evtParam->get_char.status).c_str(),
evtParam->get_char.conn_id,
BLEUtils::gattServiceIdToString(evtParam->get_char.srvc_id).c_str()
@ -1376,7 +1369,7 @@ void BLEUtils::dumpGattClientEvent(
// bool is_notify
//
case ESP_GATTC_NOTIFY_EVT: {
ESP_LOGV(LOG_TAG, "[conn_id: %d, remote_bda: %s, handle: %d 0x%.2x, value_len: %d, is_notify: %d]",
log_v("[conn_id: %d, remote_bda: %s, handle: %d 0x%.2x, value_len: %d, is_notify: %d]",
evtParam->notify.conn_id,
BLEAddress(evtParam->notify.remote_bda).toString().c_str(),
evtParam->notify.handle,
@ -1396,7 +1389,7 @@ void BLEUtils::dumpGattClientEvent(
// - uint16_t mtu
//
case ESP_GATTC_OPEN_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, remote_bda: %s, mtu: %d]",
log_v("[status: %s, conn_id: %d, remote_bda: %s, mtu: %d]",
BLEUtils::gattStatusToString(evtParam->open.status).c_str(),
evtParam->open.conn_id,
BLEAddress(evtParam->open.remote_bda).toString().c_str(),
@ -1416,7 +1409,7 @@ void BLEUtils::dumpGattClientEvent(
// uint16_t value_type
// uint16_t value_len
case ESP_GATTC_READ_CHAR_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, handle: %d 0x%.2x, value_len: %d]",
log_v("[status: %s, conn_id: %d, handle: %d 0x%.2x, value_len: %d]",
BLEUtils::gattStatusToString(evtParam->read.status).c_str(),
evtParam->read.conn_id,
evtParam->read.handle,
@ -1427,7 +1420,7 @@ void BLEUtils::dumpGattClientEvent(
GeneralUtils::hexDump(evtParam->read.value, evtParam->read.value_len);
/*
char* pHexData = BLEUtils::buildHexData(nullptr, evtParam->read.value, evtParam->read.value_len);
ESP_LOGV(LOG_TAG, "value: %s \"%s\"", pHexData, BLEUtils::buildPrintData(evtParam->read.value, evtParam->read.value_len).c_str());
log_v("value: %s \"%s\"", pHexData, BLEUtils::buildPrintData(evtParam->read.value, evtParam->read.value_len).c_str());
free(pHexData);
*/
}
@ -1440,7 +1433,7 @@ void BLEUtils::dumpGattClientEvent(
// - esp_gatt_status_t status
// - uint16_t app_id
case ESP_GATTC_REG_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, app_id: 0x%x]",
log_v("[status: %s, app_id: 0x%x]",
BLEUtils::gattStatusToString(evtParam->reg.status).c_str(),
evtParam->reg.app_id);
break;
@ -1452,7 +1445,7 @@ void BLEUtils::dumpGattClientEvent(
// - esp_gatt_status_t status
// - uint16_t handle
case ESP_GATTC_REG_FOR_NOTIFY_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, handle: %d 0x%.2x]",
log_v("[status: %s, handle: %d 0x%.2x]",
BLEUtils::gattStatusToString(evtParam->reg_for_notify.status).c_str(),
evtParam->reg_for_notify.handle,
evtParam->reg_for_notify.handle
@ -1466,7 +1459,7 @@ void BLEUtils::dumpGattClientEvent(
// - esp_gatt_status_t status
// - uint16_t conn_id
case ESP_GATTC_SEARCH_CMPL_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d]",
log_v("[status: %s, conn_id: %d]",
BLEUtils::gattStatusToString(evtParam->search_cmpl.status).c_str(),
evtParam->search_cmpl.conn_id);
break;
@ -1480,7 +1473,7 @@ void BLEUtils::dumpGattClientEvent(
// - uint16_t end_handle
// - esp_gatt_id_t srvc_id
case ESP_GATTC_SEARCH_RES_EVT: {
ESP_LOGV(LOG_TAG, "[conn_id: %d, start_handle: %d 0x%.2x, end_handle: %d 0x%.2x, srvc_id: %s",
log_v("[conn_id: %d, start_handle: %d 0x%.2x, end_handle: %d 0x%.2x, srvc_id: %s",
evtParam->search_res.conn_id,
evtParam->search_res.start_handle,
evtParam->search_res.start_handle,
@ -1498,7 +1491,7 @@ void BLEUtils::dumpGattClientEvent(
// - uint16_t handle
// - uint16_t offset
case ESP_GATTC_WRITE_CHAR_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, conn_id: %d, handle: %d 0x%.2x, offset: %d]",
log_v("[status: %s, conn_id: %d, handle: %d 0x%.2x, offset: %d]",
BLEUtils::gattStatusToString(evtParam->write.status).c_str(),
evtParam->write.conn_id,
evtParam->write.handle,
@ -1528,12 +1521,12 @@ void BLEUtils::dumpGattServerEvent(
esp_gatts_cb_event_t event,
esp_gatt_if_t gatts_if,
esp_ble_gatts_cb_param_t* evtParam) {
ESP_LOGV(LOG_TAG, "GATT ServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str());
log_v("GATT ServerEvent: %s", BLEUtils::gattServerEventTypeToString(event).c_str());
switch (event) {
#if CONFIG_LOG_DEFAULT_LEVEL > 4
case ESP_GATTS_ADD_CHAR_DESCR_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
log_v("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
gattStatusToString(evtParam->add_char_descr.status).c_str(),
evtParam->add_char_descr.attr_handle,
evtParam->add_char_descr.attr_handle,
@ -1545,7 +1538,7 @@ void BLEUtils::dumpGattServerEvent(
case ESP_GATTS_ADD_CHAR_EVT: {
if (evtParam->add_char.status == ESP_GATT_OK) {
ESP_LOGV(LOG_TAG, "[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
log_v("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
gattStatusToString(evtParam->add_char.status).c_str(),
evtParam->add_char.attr_handle,
evtParam->add_char.attr_handle,
@ -1553,7 +1546,7 @@ void BLEUtils::dumpGattServerEvent(
evtParam->add_char.service_handle,
BLEUUID(evtParam->add_char.char_uuid).toString().c_str());
} else {
ESP_LOGE(LOG_TAG, "[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
log_e("[status: %s, attr_handle: %d 0x%.2x, service_handle: %d 0x%.2x, char_uuid: %s]",
gattStatusToString(evtParam->add_char.status).c_str(),
evtParam->add_char.attr_handle,
evtParam->add_char.attr_handle,
@ -1571,7 +1564,7 @@ void BLEUtils::dumpGattServerEvent(
// - esp_gatt_status_t status The status code.
// - uint16_t conn_id The connection used.
case ESP_GATTS_CONF_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, conn_id: 0x%.2x]",
log_v("[status: %s, conn_id: 0x%.2x]",
gattStatusToString(evtParam->conf.status).c_str(),
evtParam->conf.conn_id);
break;
@ -1579,21 +1572,21 @@ void BLEUtils::dumpGattServerEvent(
case ESP_GATTS_CONGEST_EVT: {
ESP_LOGV(LOG_TAG, "[conn_id: %d, congested: %d]",
log_v("[conn_id: %d, congested: %d]",
evtParam->congest.conn_id,
evtParam->congest.congested);
break;
} // ESP_GATTS_CONGEST_EVT
case ESP_GATTS_CONNECT_EVT: {
ESP_LOGV(LOG_TAG, "[conn_id: %d, remote_bda: %s]",
log_v("[conn_id: %d, remote_bda: %s]",
evtParam->connect.conn_id,
BLEAddress(evtParam->connect.remote_bda).toString().c_str());
break;
} // ESP_GATTS_CONNECT_EVT
case ESP_GATTS_CREATE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, service_handle: %d 0x%.2x, service_id: [%s]]",
log_v("[status: %s, service_handle: %d 0x%.2x, service_id: [%s]]",
gattStatusToString(evtParam->create.status).c_str(),
evtParam->create.service_handle,
evtParam->create.service_handle,
@ -1602,7 +1595,7 @@ void BLEUtils::dumpGattServerEvent(
} // ESP_GATTS_CREATE_EVT
case ESP_GATTS_DISCONNECT_EVT: {
ESP_LOGV(LOG_TAG, "[conn_id: %d, remote_bda: %s]",
log_v("[conn_id: %d, remote_bda: %s]",
evtParam->connect.conn_id,
BLEAddress(evtParam->connect.remote_bda).toString().c_str());
break;
@ -1633,7 +1626,7 @@ void BLEUtils::dumpGattServerEvent(
break;
}
ESP_LOGV(LOG_TAG, "[conn_id: %d, trans_id: %d, bda: %s, exec_write_flag: 0x%.2x=%s]",
log_v("[conn_id: %d, trans_id: %d, bda: %s, exec_write_flag: 0x%.2x=%s]",
evtParam->exec_write.conn_id,
evtParam->exec_write.trans_id,
BLEAddress(evtParam->exec_write.bda).toString().c_str(),
@ -1644,14 +1637,14 @@ void BLEUtils::dumpGattServerEvent(
case ESP_GATTS_MTU_EVT: {
ESP_LOGV(LOG_TAG, "[conn_id: %d, mtu: %d]",
log_v("[conn_id: %d, mtu: %d]",
evtParam->mtu.conn_id,
evtParam->mtu.mtu);
break;
} // ESP_GATTS_MTU_EVT
case ESP_GATTS_READ_EVT: {
ESP_LOGV(LOG_TAG, "[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, is_long: %d, need_rsp:%d]",
log_v("[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, is_long: %d, need_rsp:%d]",
evtParam->read.conn_id,
evtParam->read.trans_id,
BLEAddress(evtParam->read.bda).toString().c_str(),
@ -1662,14 +1655,14 @@ void BLEUtils::dumpGattServerEvent(
} // ESP_GATTS_READ_EVT
case ESP_GATTS_RESPONSE_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, handle: 0x%.2x]",
log_v("[status: %s, handle: 0x%.2x]",
gattStatusToString(evtParam->rsp.status).c_str(),
evtParam->rsp.handle);
break;
} // ESP_GATTS_RESPONSE_EVT
case ESP_GATTS_REG_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, app_id: %d]",
log_v("[status: %s, app_id: %d]",
gattStatusToString(evtParam->reg.status).c_str(),
evtParam->reg.app_id);
break;
@ -1682,7 +1675,7 @@ void BLEUtils::dumpGattServerEvent(
// - esp_gatt_status_t status
// - uint16_t service_handle
case ESP_GATTS_START_EVT: {
ESP_LOGV(LOG_TAG, "[status: %s, service_handle: 0x%.2x]",
log_v("[status: %s, service_handle: 0x%.2x]",
gattStatusToString(evtParam->start.status).c_str(),
evtParam->start.service_handle);
break;
@ -1702,7 +1695,7 @@ void BLEUtils::dumpGattServerEvent(
// - uint16_t len The length of the incoming value part.
// - uint8_t* value The data for this value part.
case ESP_GATTS_WRITE_EVT: {
ESP_LOGV(LOG_TAG, "[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, offset: %d, need_rsp: %d, is_prep: %d, len: %d]",
log_v("[conn_id: %d, trans_id: %d, bda: %s, handle: 0x%.2x, offset: %d, need_rsp: %d, is_prep: %d, len: %d]",
evtParam->write.conn_id,
evtParam->write.trans_id,
BLEAddress(evtParam->write.bda).toString().c_str(),
@ -1712,13 +1705,13 @@ void BLEUtils::dumpGattServerEvent(
evtParam->write.is_prep,
evtParam->write.len);
char* pHex = buildHexData(nullptr, evtParam->write.value, evtParam->write.len);
ESP_LOGV(LOG_TAG, "[Data: %s]", pHex);
log_v("[Data: %s]", pHex);
free(pHex);
break;
} // ESP_GATTS_WRITE_EVT
#endif
default:
ESP_LOGV(LOG_TAG, "dumpGattServerEvent: *** NOT CODED ***");
log_v("dumpGattServerEvent: *** NOT CODED ***");
break;
}
} // dumpGattServerEvent
@ -1744,7 +1737,7 @@ const char* BLEUtils::eventTypeToString(esp_ble_evt_type_t eventType) {
return "ESP_BLE_EVT_SCAN_RSP";
#endif
default:
ESP_LOGV(LOG_TAG, "Unknown esp_ble_evt_type_t: %d (0x%.2x)", eventType, eventType);
log_v("Unknown esp_ble_evt_type_t: %d (0x%.2x)", eventType, eventType);
return "*** Unknown ***";
}
} // eventTypeToString
@ -1815,7 +1808,7 @@ const char* BLEUtils::gapEventToString(uint32_t eventType) {
return "ESP_GAP_BLE_UPDATE_CONN_PARAMS_EVT";
#endif
default:
ESP_LOGV(LOG_TAG, "gapEventToString: Unknown event type %d 0x%.2x", eventType, eventType);
log_v("gapEventToString: Unknown event type %d 0x%.2x", eventType, eventType);
return "Unknown event type";
}
} // gapEventToString
@ -2025,7 +2018,7 @@ const char* BLEUtils::searchEventTypeToString(esp_gap_search_evt_t searchEvt) {
return "ESP_GAP_SEARCH_SEARCH_CANCEL_CMPL_EVT";
#endif
default:
ESP_LOGV(LOG_TAG, "Unknown event type: 0x%x", searchEvt);
log_v("Unknown event type: 0x%x", searchEvt);
return "Unknown event type";
}
} // searchEventTypeToString

View File

@ -7,16 +7,7 @@
#include "sdkconfig.h"
#if defined(CONFIG_BT_ENABLED)
#include "BLEValue.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG="BLEValue";
#endif
BLEValue::BLEValue() {
m_accumulation = "";
@ -31,7 +22,7 @@ BLEValue::BLEValue() {
* @param [in] part A message part being added.
*/
void BLEValue::addPart(std::string part) {
ESP_LOGD(LOG_TAG, ">> addPart: length=%d", part.length());
log_v(">> addPart: length=%d", part.length());
m_accumulation += part;
} // addPart
@ -43,7 +34,7 @@ void BLEValue::addPart(std::string part) {
* @param [in] length The number of bytes being added.
*/
void BLEValue::addPart(uint8_t* pData, size_t length) {
ESP_LOGD(LOG_TAG, ">> addPart: length=%d", length);
log_v(">> addPart: length=%d", length);
m_accumulation += std::string((char*) pData, length);
} // addPart
@ -52,7 +43,7 @@ void BLEValue::addPart(uint8_t* pData, size_t length) {
* @brief Cancel the current accumulation.
*/
void BLEValue::cancel() {
ESP_LOGD(LOG_TAG, ">> cancel");
log_v(">> cancel");
m_accumulation = "";
m_readOffset = 0;
} // cancel
@ -65,7 +56,7 @@ void BLEValue::cancel() {
* we now have the complete message and commit the change as a unit.
*/
void BLEValue::commit() {
ESP_LOGD(LOG_TAG, ">> commit");
log_v(">> commit");
// If there is nothing to commit, do nothing.
if (m_accumulation.length() == 0) return;
setValue(m_accumulation);

View File

@ -12,14 +12,7 @@
#include <iomanip>
#include "FreeRTOS.h"
#include "sdkconfig.h"
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "FreeRTOS";
#endif
/**
* Sleep for the specified number of milliseconds.
@ -67,7 +60,7 @@ uint32_t FreeRTOS::getTimeSinceStart() {
* @return The value associated with the semaphore.
*/
uint32_t FreeRTOS::Semaphore::wait(std::string owner) {
ESP_LOGV(LOG_TAG, ">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str());
log_v(">> wait: Semaphore waiting: %s for %s", toString().c_str(), owner.c_str());
if (m_usePthreads) {
pthread_mutex_lock(&m_pthread_mutex);
@ -83,7 +76,7 @@ uint32_t FreeRTOS::Semaphore::wait(std::string owner) {
xSemaphoreGive(m_semaphore);
}
ESP_LOGV(LOG_TAG, "<< wait: Semaphore released: %s", toString().c_str());
log_v("<< wait: Semaphore released: %s", toString().c_str());
m_owner = std::string("<N/A>");
return m_value;
} // wait
@ -117,7 +110,7 @@ FreeRTOS::Semaphore::~Semaphore() {
* The Semaphore is given.
*/
void FreeRTOS::Semaphore::give() {
ESP_LOGV(LOG_TAG, "Semaphore giving: %s", toString().c_str());
log_v("Semaphore giving: %s", toString().c_str());
if (m_usePthreads) {
pthread_mutex_unlock(&m_pthread_mutex);
} else {
@ -162,7 +155,7 @@ void FreeRTOS::Semaphore::giveFromISR() {
* @return True if we took the semaphore.
*/
bool FreeRTOS::Semaphore::take(std::string owner) {
ESP_LOGD(LOG_TAG, "Semaphore taking: %s for %s", toString().c_str(), owner.c_str());
log_d("Semaphore taking: %s for %s", toString().c_str(), owner.c_str());
bool rc = false;
if (m_usePthreads) {
pthread_mutex_lock(&m_pthread_mutex);
@ -171,9 +164,9 @@ bool FreeRTOS::Semaphore::take(std::string owner) {
}
m_owner = owner;
if (rc) {
ESP_LOGD(LOG_TAG, "Semaphore taken: %s", toString().c_str());
log_d("Semaphore taken: %s", toString().c_str());
} else {
ESP_LOGE(LOG_TAG, "Semaphore NOT taken: %s", toString().c_str());
log_e("Semaphore NOT taken: %s", toString().c_str());
}
return rc;
} // Semaphore::take
@ -187,7 +180,7 @@ bool FreeRTOS::Semaphore::take(std::string owner) {
* @return True if we took the semaphore.
*/
bool FreeRTOS::Semaphore::take(uint32_t timeoutMs, std::string owner) {
ESP_LOGV(LOG_TAG, "Semaphore taking: %s for %s", toString().c_str(), owner.c_str());
log_v("Semaphore taking: %s for %s", toString().c_str(), owner.c_str());
bool rc = false;
if (m_usePthreads) {
assert(false); // We apparently don't have a timed wait for pthreads.
@ -196,9 +189,9 @@ bool FreeRTOS::Semaphore::take(uint32_t timeoutMs, std::string owner) {
}
m_owner = owner;
if (rc) {
ESP_LOGV(LOG_TAG, "Semaphore taken: %s", toString().c_str());
log_v("Semaphore taken: %s", toString().c_str());
} else {
ESP_LOGE(LOG_TAG, "Semaphore NOT taken: %s", toString().c_str());
log_e("Semaphore NOT taken: %s", toString().c_str());
}
return rc;
} // Semaphore::take

View File

@ -18,15 +18,7 @@
#include <esp_wifi.h>
#include <esp_heap_caps.h>
#include <esp_system.h>
#if defined(ARDUINO_ARCH_ESP32) && defined(CONFIG_ARDUHAL_ESP_LOG)
#include "esp32-hal-log.h"
#define LOG_TAG ""
#else
#include "esp_log.h"
static const char* LOG_TAG = "GeneralUtils";
#endif
static const char kBase64Alphabet[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
@ -115,11 +107,11 @@ void GeneralUtils::dumpInfo() {
size_t freeHeap = heap_caps_get_free_size(MALLOC_CAP_8BIT);
esp_chip_info_t chipInfo;
esp_chip_info(&chipInfo);
ESP_LOGV(LOG_TAG, "--- dumpInfo ---");
ESP_LOGV(LOG_TAG, "Free heap: %d", freeHeap);
ESP_LOGV(LOG_TAG, "Chip Info: Model: %d, cores: %d, revision: %d", chipInfo.model, chipInfo.cores, chipInfo.revision);
ESP_LOGV(LOG_TAG, "ESP-IDF version: %s", esp_get_idf_version());
ESP_LOGV(LOG_TAG, "---");
log_v("--- dumpInfo ---");
log_v("Free heap: %d", freeHeap);
log_v("Chip Info: Model: %d, cores: %d, revision: %d", chipInfo.model, chipInfo.cores, chipInfo.revision);
log_v("ESP-IDF version: %s", esp_get_idf_version());
log_v("---");
} // dumpInfo
@ -237,7 +229,7 @@ void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) {
if (index % 16 == 0) {
strcpy(hexBuf, hex.str().c_str());
strcpy(asciiBuf, ascii.str().c_str());
ESP_LOGV(tag, "%s %s", hexBuf, asciiBuf);
log_v("%s %s", hexBuf, asciiBuf);
hex.str("");
ascii.str("");
}
@ -249,8 +241,8 @@ void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) {
}
strcpy(hexBuf, hex.str().c_str());
strcpy(asciiBuf, ascii.str().c_str());
ESP_LOGV(tag, "%s %s", hexBuf, asciiBuf);
//ESP_LOGV(tag, "%s %s", hex.str().c_str(), ascii.str().c_str());
log_v("%s %s", hexBuf, asciiBuf);
//log_v("%s %s", hex.str().c_str(), ascii.str().c_str());
}
FreeRTOS::sleep(1000);
}
@ -272,7 +264,7 @@ void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) {
}
index++;
if (index % 16 == 0) {
ESP_LOGV(tag, "%s %s", hex.str().c_str(), ascii.str().c_str());
log_v("%s %s", hex.str().c_str(), ascii.str().c_str());
hex.str("");
ascii.str("");
}
@ -282,7 +274,7 @@ void GeneralUtils::hexDump(uint8_t* pData, uint32_t length) {
hex << " ";
index++;
}
ESP_LOGV(tag, "%s %s", hex.str().c_str(), ascii.str().c_str());
log_v("%s %s", hex.str().c_str(), ascii.str().c_str());
}
FreeRTOS::sleep(1000);
}
@ -302,8 +294,8 @@ void GeneralUtils::hexDump(const uint8_t* pData, uint32_t length) {
char tempBuf[80];
uint32_t lineNumber = 0;
ESP_LOGV(LOG_TAG, " 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f");
ESP_LOGV(LOG_TAG, " -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
log_v(" 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f");
log_v(" -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --");
strcpy(ascii, "");
strcpy(hex, "");
uint32_t index = 0;
@ -318,7 +310,7 @@ void GeneralUtils::hexDump(const uint8_t* pData, uint32_t length) {
strcat(ascii, tempBuf);
index++;
if (index % 16 == 0) {
ESP_LOGV(LOG_TAG, "%.4x %s %s", lineNumber * 16, hex, ascii);
log_v("%.4x %s %s", lineNumber * 16, hex, ascii);
strcpy(ascii, "");
strcpy(hex, "");
lineNumber++;
@ -329,7 +321,7 @@ void GeneralUtils::hexDump(const uint8_t* pData, uint32_t length) {
strcat(hex, " ");
index++;
}
ESP_LOGV(LOG_TAG, "%.4x %s %s", lineNumber * 16, hex, ascii);
log_v("%.4x %s %s", lineNumber * 16, hex, ascii);
}
} // hexDump

View File

@ -286,7 +286,7 @@ size_t EEPROMClass::readString (int address, char* value, size_t maxLen)
String EEPROMClass::readString (int address)
{
if (address < 0 || address > _size)
return String(0);
return String();
uint16_t len;
for (len = 0; len <= _size; len++)
@ -294,7 +294,7 @@ String EEPROMClass::readString (int address)
break;
if (address + len > _size)
return String(0);
return String();
char value[len];
memcpy((uint8_t*) value, _data + address, len);

View File

@ -291,7 +291,7 @@ int8_t Preferences::getChar(const char* key, const int8_t defaultValue){
}
esp_err_t err = nvs_get_i8(_handle, key, &value);
if(err){
log_e("nvs_get_i8 fail: %s %s", key, nvs_error(err));
log_v("nvs_get_i8 fail: %s %s", key, nvs_error(err));
}
return value;
}
@ -303,7 +303,7 @@ uint8_t Preferences::getUChar(const char* key, const uint8_t defaultValue){
}
esp_err_t err = nvs_get_u8(_handle, key, &value);
if(err){
log_e("nvs_get_u8 fail: %s %s", key, nvs_error(err));
log_v("nvs_get_u8 fail: %s %s", key, nvs_error(err));
}
return value;
}
@ -315,7 +315,7 @@ int16_t Preferences::getShort(const char* key, const int16_t defaultValue){
}
esp_err_t err = nvs_get_i16(_handle, key, &value);
if(err){
log_e("nvs_get_i16 fail: %s %s", key, nvs_error(err));
log_v("nvs_get_i16 fail: %s %s", key, nvs_error(err));
}
return value;
}
@ -327,7 +327,7 @@ uint16_t Preferences::getUShort(const char* key, const uint16_t defaultValue){
}
esp_err_t err = nvs_get_u16(_handle, key, &value);
if(err){
log_e("nvs_get_u16 fail: %s %s", key, nvs_error(err));
log_v("nvs_get_u16 fail: %s %s", key, nvs_error(err));
}
return value;
}
@ -339,7 +339,7 @@ int32_t Preferences::getInt(const char* key, const int32_t defaultValue){
}
esp_err_t err = nvs_get_i32(_handle, key, &value);
if(err){
log_e("nvs_get_i32 fail: %s %s", key, nvs_error(err));
log_v("nvs_get_i32 fail: %s %s", key, nvs_error(err));
}
return value;
}
@ -351,7 +351,7 @@ uint32_t Preferences::getUInt(const char* key, const uint32_t defaultValue){
}
esp_err_t err = nvs_get_u32(_handle, key, &value);
if(err){
log_e("nvs_get_u32 fail: %s %s", key, nvs_error(err));
log_v("nvs_get_u32 fail: %s %s", key, nvs_error(err));
}
return value;
}
@ -371,7 +371,7 @@ int64_t Preferences::getLong64(const char* key, const int64_t defaultValue){
}
esp_err_t err = nvs_get_i64(_handle, key, &value);
if(err){
log_e("nvs_get_i64 fail: %s %s", key, nvs_error(err));
log_v("nvs_get_i64 fail: %s %s", key, nvs_error(err));
}
return value;
}
@ -383,7 +383,7 @@ uint64_t Preferences::getULong64(const char* key, const uint64_t defaultValue){
}
esp_err_t err = nvs_get_u64(_handle, key, &value);
if(err){
log_e("nvs_get_u64 fail: %s %s", key, nvs_error(err));
log_v("nvs_get_u64 fail: %s %s", key, nvs_error(err));
}
return value;
}

View File

@ -50,12 +50,6 @@ extern "C" {
#include "sdkconfig.h"
#if CONFIG_FREERTOS_UNICORE
#define ARDUINO_RUNNING_CORE 0
#else
#define ARDUINO_RUNNING_CORE 1
#endif
static xQueueHandle _network_event_queue;
static TaskHandle_t _network_event_task_handle = NULL;
static EventGroupHandle_t _network_event_group = NULL;
@ -96,7 +90,7 @@ static bool _start_network_event_task(){
}
}
if(!_network_event_task_handle){
xTaskCreatePinnedToCore(_network_event_task, "network_event", 4096, NULL, ESP_TASKD_EVENT_PRIO - 1, &_network_event_task_handle, ARDUINO_RUNNING_CORE);
xTaskCreateUniversal(_network_event_task, "network_event", 4096, NULL, ESP_TASKD_EVENT_PRIO - 1, &_network_event_task_handle, CONFIG_ARDUINO_EVENT_RUNNING_CORE);
if(!_network_event_task_handle){
log_e("Network Event Task Start Failed!");
return false;

View File

@ -194,6 +194,8 @@ bool WiFiMulti::APlistAdd(const char* ssid, const char *passphrase)
free(newAP.ssid);
return false;
}
} else {
newAP.passphrase = NULL;
}
APlist.push_back(newAP);

View File

@ -48,6 +48,7 @@ WiFiClientSecure::WiFiClientSecure()
WiFiClientSecure::WiFiClientSecure(int sock)
{
_connected = false;
_timeout = 0;
sslclient = new sslclient_context;
ssl_init(sslclient);
@ -98,6 +99,11 @@ int WiFiClientSecure::connect(IPAddress ip, uint16_t port)
return connect(ip, port, _CA_cert, _cert, _private_key);
}
int WiFiClientSecure::connect(IPAddress ip, uint16_t port, int32_t timeout){
_timeout = timeout;
return connect(ip, port);
}
int WiFiClientSecure::connect(const char *host, uint16_t port)
{
if (_pskIdent && _psKey)
@ -105,6 +111,11 @@ int WiFiClientSecure::connect(const char *host, uint16_t port)
return connect(host, port, _CA_cert, _cert, _private_key);
}
int WiFiClientSecure::connect(const char *host, uint16_t port, int32_t timeout){
_timeout = timeout;
return connect(host, port);
}
int WiFiClientSecure::connect(IPAddress ip, uint16_t port, const char *_CA_cert, const char *_cert, const char *_private_key)
{
return connect(ip.toString().c_str(), port, _CA_cert, _cert, _private_key);
@ -112,7 +123,10 @@ int WiFiClientSecure::connect(IPAddress ip, uint16_t port, const char *_CA_cert,
int WiFiClientSecure::connect(const char *host, uint16_t port, const char *_CA_cert, const char *_cert, const char *_private_key)
{
int ret = start_ssl_client(sslclient, host, port, _CA_cert, _cert, _private_key, NULL, NULL);
if(_timeout > 0){
sslclient->handshake_timeout = _timeout;
}
int ret = start_ssl_client(sslclient, host, port, _timeout, _CA_cert, _cert, _private_key, NULL, NULL);
_lastError = ret;
if (ret < 0) {
log_e("start_ssl_client: %d", ret);
@ -129,7 +143,10 @@ int WiFiClientSecure::connect(IPAddress ip, uint16_t port, const char *pskIdent,
int WiFiClientSecure::connect(const char *host, uint16_t port, const char *pskIdent, const char *psKey) {
log_v("start_ssl_client with PSK");
int ret = start_ssl_client(sslclient, host, port, NULL, NULL, NULL, _pskIdent, _psKey);
if(_timeout > 0){
sslclient->handshake_timeout = _timeout;
}
int ret = start_ssl_client(sslclient, host, port, _timeout, NULL, NULL, NULL, _pskIdent, _psKey);
_lastError = ret;
if (ret < 0) {
log_e("start_ssl_client: %d", ret);

View File

@ -32,6 +32,7 @@ protected:
int _lastError = 0;
int _peek = -1;
int _timeout = 0;
const char *_CA_cert;
const char *_cert;
const char *_private_key;
@ -44,7 +45,9 @@ public:
WiFiClientSecure(int socket);
~WiFiClientSecure();
int connect(IPAddress ip, uint16_t port);
int connect(IPAddress ip, uint16_t port, int32_t timeout);
int connect(const char *host, uint16_t port);
int connect(const char *host, uint16_t port, int32_t timeout);
int connect(IPAddress ip, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key);
int connect(const char *host, uint16_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key);
int connect(IPAddress ip, uint16_t port, const char *pskIdent, const char *psKey);

View File

@ -45,10 +45,10 @@ void ssl_init(sslclient_context *ssl_client)
}
int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey)
int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey)
{
char buf[512];
int ret, flags, timeout;
int ret, flags;
int enable = 1;
log_v("Free internal heap before TLS %u", ESP.getFreeHeap());
@ -73,7 +73,9 @@ int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t p
serv_addr.sin_port = htons(port);
if (lwip_connect(ssl_client->socket, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == 0) {
if(timeout <= 0){
timeout = 30000;
}
lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout));
lwip_setsockopt(ssl_client->socket, SOL_SOCKET, SO_SNDTIMEO, &timeout, sizeof(timeout));
lwip_setsockopt(ssl_client->socket, IPPROTO_TCP, TCP_NODELAY, &enable, sizeof(enable));

View File

@ -29,7 +29,7 @@ typedef struct sslclient_context {
void ssl_init(sslclient_context *ssl_client);
int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey);
int start_ssl_client(sslclient_context *ssl_client, const char *host, uint32_t port, int timeout, const char *rootCABuff, const char *cli_cert, const char *cli_key, const char *pskIdent, const char *psKey);
void stop_ssl_socket(sslclient_context *ssl_client, const char *rootCABuff, const char *cli_cert, const char *cli_key);
int data_to_read(sslclient_context *ssl_client);
int send_ssl_data(sslclient_context *ssl_client, const uint8_t *data, uint16_t len);

View File

@ -100,6 +100,7 @@
#define CONFIG_MBEDTLS_RC4_DISABLED 1
#define CONFIG_FATFS_LFN_STACK 1
#define CONFIG_CONSOLE_UART_NUM 0
#define CONFIG_ARDUINO_EVENT_RUNNING_CORE 1
#define CONFIG_ESP32_APPTRACE_LOCK_ENABLE 1
#define CONFIG_PTHREAD_STACK_MIN 768
#define CONFIG_ESP32_RTC_CLOCK_SOURCE_INTERNAL_RC 1
@ -111,6 +112,7 @@
#define CONFIG_NUMBER_OF_UNIVERSAL_MAC_ADDRESS 4
#define CONFIG_ESPTOOLPY_FLASHSIZE_DETECT 1
#define CONFIG_AUTOSTART_ARDUINO 1
#define CONFIG_ARDUINO_RUNNING_CORE 1
#define CONFIG_PPP_CHAP_SUPPORT 1
#define CONFIG_LOG_DEFAULT_LEVEL_ERROR 1
#define CONFIG_TIMER_TASK_STACK_SIZE 4096
@ -134,6 +136,7 @@
#define CONFIG_TASK_WDT_TIMEOUT_S 5
#define CONFIG_INT_WDT_TIMEOUT_MS 300
#define CONFIG_SCCB_HARDWARE_I2C 1
#define CONFIG_ARDUINO_EVENT_RUN_CORE1 1
#define CONFIG_ESPTOOLPY_FLASHMODE "dio"
#define CONFIG_BTC_TASK_STACK_SIZE 8192
#define CONFIG_BLUEDROID_ENABLED 1
@ -211,6 +214,7 @@
#define CONFIG_BROWNOUT_DET_LVL 0
#define CONFIG_MBEDTLS_PEM_PARSE_C 1
#define CONFIG_SPIFFS_GC_MAX_RUNS 10
#define CONFIG_ARDUINO_RUN_CORE1 1
#define CONFIG_ESP32_APPTRACE_DEST_NONE 1
#define CONFIG_MBEDTLS_INTERNAL_MEM_ALLOC 1
#define CONFIG_MBEDTLS_SSL_PROTO_TLS1_2 1
@ -258,6 +262,7 @@
#define CONFIG_ESPTOOLPY_AFTER "hard_reset"
#define CONFIG_TCPIP_TASK_AFFINITY 0x0
#define CONFIG_LWIP_SO_REUSE 1
#define CONFIG_ARDUINO_UDP_RUN_CORE1 1
#define CONFIG_DMA_TX_BUF_NUM 10
#define CONFIG_LWIP_MAX_LISTENING_TCP 16
#define CONFIG_FREERTOS_INTERRUPT_BACKTRACE 1
@ -325,6 +330,7 @@
#define CONFIG_LWIP_SO_RCVBUF 1
#define CONFIG_MB_TIMER_PORT_ENABLED 1
#define CONFIG_DUPLICATE_SCAN_CACHE_SIZE 20
#define CONFIG_ARDUINO_UDP_RUNNING_CORE 1
#define CONFIG_MONITOR_BAUD_OTHER_VAL 115200
#define CONFIG_NEWLIB_STDOUT_LINE_ENDING_CRLF 1
#define CONFIG_ESPTOOLPY_PORT "/dev/cu.usbserial-DO00EAB0"

Binary file not shown.

View File

@ -15,6 +15,18 @@ CONFIG_MAKE_WARN_UNDEFINED_VARIABLES=y
#
CONFIG_ENABLE_ARDUINO_DEPENDS=y
CONFIG_AUTOSTART_ARDUINO=y
CONFIG_ARDUINO_RUN_CORE0=
CONFIG_ARDUINO_RUN_CORE1=y
CONFIG_ARDUINO_RUN_NO_AFFINITY=
CONFIG_ARDUINO_RUNNING_CORE=1
CONFIG_ARDUINO_EVENT_RUN_CORE0=
CONFIG_ARDUINO_EVENT_RUN_CORE1=y
CONFIG_ARDUINO_EVENT_RUN_NO_AFFINITY=
CONFIG_ARDUINO_EVENT_RUNNING_CORE=1
CONFIG_ARDUINO_UDP_RUN_CORE0=
CONFIG_ARDUINO_UDP_RUN_CORE1=y
CONFIG_ARDUINO_UDP_RUN_NO_AFFINITY=
CONFIG_ARDUINO_UDP_RUNNING_CORE=1
CONFIG_DISABLE_HAL_LOCKS=
#

View File

@ -17,6 +17,9 @@ static const uint8_t LED_BUILTIN = 13;
static const uint8_t TX = 17;
static const uint8_t RX = 16;
#define TX1 TX
#define RX1 RX
static const uint8_t SDA = 23;
static const uint8_t SCL = 22;

View File

@ -0,0 +1,58 @@
#ifndef Pins_Arduino_h
#define Pins_Arduino_h
#include <stdint.h>
#define EXTERNAL_NUM_INTERRUPTS 16
#define NUM_DIGITAL_PINS 40
#define NUM_ANALOG_INPUTS 16
#define analogInputToDigitalPin(p) (((p)<20)?(esp32_adc2gpio[(p)]):-1)
#define digitalPinToInterrupt(p) (((p)<40)?(p):-1)
#define digitalPinHasPWM(p) (p < 34)
static const int LED_BUILTIN = 17;
static const uint8_t TX = 1;
static const uint8_t RX = 3;
static const uint8_t SDA = 21;
static const uint8_t SCL = 22;
static const uint8_t SS = 16;
static const uint8_t MOSI = 13;
static const uint8_t MISO = 12;
static const uint8_t SCK = 14;
static const uint8_t A0 = 36;
static const uint8_t A3 = 39;
static const uint8_t A4 = 32;
static const uint8_t A5 = 33;
static const uint8_t A6 = 34;
static const uint8_t A7 = 35;
static const uint8_t A10 = 4;
static const uint8_t A11 = 0;
static const uint8_t A12 = 2;
static const uint8_t A13 = 15;
static const uint8_t A14 = 13;
static const uint8_t A15 = 12;
static const uint8_t A16 = 14;
static const uint8_t A17 = 27;
static const uint8_t A18 = 25;
static const uint8_t A19 = 26;
static const uint8_t T0 = 4;
static const uint8_t T1 = 0;
static const uint8_t T2 = 2;
static const uint8_t T3 = 15;
static const uint8_t T4 = 13;
static const uint8_t T5 = 12;
static const uint8_t T6 = 14;
static const uint8_t T7 = 27;
static const uint8_t T8 = 33;
static const uint8_t T9 = 32;
static const uint8_t DAC1 = 25;
static const uint8_t DAC2 = 26;
#endif /* Pins_Arduino_h */