This is a custom fork - original library is available at https://github.com/JoaoLopesF/RemoteDebug!
A fork of library for Arduino to debug projects over WiFi, with web app or telnet client, with Print commands like Serial Monitor.
RemoteDebug setup a TCP/IP server, that you connect to debugging, as an alternative to the serial connection
- About
- How it looks
- Github
- News
- Benefits
- Telnet client
- Wishlist
- Install
- Using
- Known issues
- Releases
- Thanks
By default the Arduino only has as debug possibility via the Serial port. This has a few disadvantages:
- requires a physical cable to the Arduino device (if the device is far away or in a remote location this is not easy)
- debugging multiple Arduinos at the same time requires many serial ports and a lot of cables
With the ESP8266 (NodeMCU) or ESP32 we now have network connectivity (WiFi) which can be used for streaming debugging information in real-time.
This library is good for IoT projects, home automation, mobile robots (can debug it in moviment with a cable ?) or another WiFi projects.
In fact, this library was born of a need to debug an IoT project of home automation. In this project there was a central module and three auxiliary modules, and these were far from each other. One was hard to reach, under the roof of the house. To debug this project, accompanying the exchange of messages in realtime, is impossible to do with traditional way, by USB cable.
The MiP_ESP8266_Library and my ESP32 WiFi robot are example of projects that uses RemoteDebug. See it in: MiP_ESP8266_Library and ESPlorer_v1
RemoteDebug is improved with client buffering (is last send is <= 10ms), to avoid mysterious delays of WiFi networking on ESP32 and ESP8266 boards
Note: If your project not use WiFi, you can use my another library, the SerialDebug library, this library works with any Arduino board.
Note II: RemoteDebug library is now only to Espressif boards, as ESP32 and ESP8266, If need for another WiFi boards, please add an issue about this and we will see if it is possible made the port for your board.
Image: In telnet client
Youtube (RemoteDebug v2):
Youtube (3 telnet connections with RemoteDebug) v1:
Contribute to this library development by creating an account on GitHub.
Please give a star, if you find this library useful, this help an another people, discover it too.
Please add an issue for problems or suggestion.
SerialDebug is better than Arduino default debugging by Serial.print commands:
Being or not debugging via USB cable, the Serial.print command allways is processed, waste CPU time on microcontroller. In other words, the debug commands are processed, with someone connected in the serial or not.
With RemoteDebug, all debug output is processed only if exists anyone debugging via telnet or web app connection.
And with the debug levels of resource, the volume displayed of messages are reduced for higher levels. For example, only process all messages, if the level is the lowest, the verbose,
RemoteDebug is otimized to reduce overheads, in CPU and memory and include client buffering feature.
During the development, we can put a lot of debug messages...
But with RemoteDebug, we can put a level in each one.
For all messages (except levels always (debugA) or error (debugE), the message only is processed and showed, if debug level is equal or higher than it level
RemoteDebug have 6 debug levels, in order of priority:
Alway showed:
Error: Critical errors
Always: Important messages
Another levels (showed if level is equal or higher that actual one):
Warning: Error conditions but not critical
Info: Information messages
Debug: Extra information
Verbose: More information than the usual
So We can change the level to verbose, to see all messages. Or to debug to see only debug or higher level, etc.
Is very good to reduce a quantity of messages that a project can generate, to help debugging.
RemoteDebug have a converter to help migrate your Arduino codes, from Serial.prints to this library.
Even if you want to do this manually, it's very simple. Please see topic Using above.
A simple debug:
debugV("* Run time: %02u:%02u:%02u (VERBOSE)", mRunHours, mRunMinutes, mRunSeconds);
Can generate this output in serial monitor:
(V p:3065 loop C1) * Run time: 00:41:23 (VERBOSE)
Where: V: is the level
p: is a profiler time, elased, between this and previous debug
loop: is a function name, that executed this debug
C1: is a core that executed this debug (and a function of this) (only for ESP32)
The remaining is the message formatted (printf)
For ESP32, the core id in each debug is very good to optimizer multicore programming.
For example:
-
Show help (?)
-
Change the level of debug (v,d,i,w,e), to show less or more messages.
-
See memory (m)
-
Reset the board (reset)
See about RemoteDebug commands below.
You can add your own commands, see the examples please
If your project have RemoteDebugger installed, have a new commands, e.g. call a function, see/change variables, ...
Now RemoteDebug (version >= 2.0.0), have an simple software debuggger, based in codes of SerialDebug library.
This is another library, that act as an addon to RemoteDebug.
Please acess the RemoteDebugger repository to more informations: RemoteDebugger
For release your device, just uncomment DEBUG_DISABLED in your project
Done this, and no more debug processing.
And better for DEBUG_DISABLED, __RemoteDebug__ have ZERO overhead,
due is nothing of this is compiled.
Telnet is a standard way of remotely connecting to a server and is supported on all operating systems (Windows, Mac, Linux...).
MacOSx and Linux have a native telnet client.
For Windows, a typical telnet client is the Putty: putty .
Have a good tool for mobiles: the Fing, please find it in your mobile store. Its show all devices in local network (WiFi), show ports opened and can execute the telnet client too (external App)
RemoteDebug sets-up a telnet server which is listening to any telnet client that wants to connect. After connection, logging is streamed to the telnet client.
RemoteDebug is very simple to use, after a few lines of initialization code, you can use the well-known "print" commands to stream your logging to the remote client.
RemoteDebug supports the filtering of logging based on debug levels:
Only show for it actual debug level:
- Verbose
- Debug
- Info
- Warnings
Note: These levels are in the order of most-logging -> least-logging.
Or for always show (not depends of actual debug level):
- Any
- Errors
Note: All debugs is processed and showed only if have a client connection.
The telnet client or web app can set the debug level by typing a few simple commands.
RemoteDebug includes a simple profiler. It can be enabled by the connected client (telnet or web app) or the Arduino code itself.
When enabled, it shows the time between 2 debug statements, using different colors depending on the elapsed time.
A typical example would be to insert logging just before and after a function after which you can see how much the is spent in the function.
RemoteDebug is designed to give minimal overhead (connected or not) and only process debugs,if there is a client (telnet or web app) connected.
RemoteDebug supports custom commands that can be entered in the client (telnet or web app). These trigger the execution of a custom function in the Arduino code. For example this can be used to send back a status on request of the client.
The current version of RemoteDebug does not yet include any encrypted authentication, only plain text and is intended only for development, not use in production/release.
Future versions, if is possible, will include a secure way for authentication and further testing to support production environments.
- An app to RemoteDebug like SerialDebug have.
- Http page to begin/stop the telnet server or websocket server.
- Authentication as telnet support (kerberos, etc.) to support production environment
Just download or clone this repository.
Or for Arduino IDE, you can use the library manager to install and update the library.
For install help, please click on this:
For another IDE, or not using the library manager of Arduino IDE, I suggest you use a Github Desktop app to clone,it help to keep updated.
Please open the projects in example folder, to see it working.
#include "RemoteDebug.h" //https://github.com/JoaoLopesF/RemoteDebug
RemoteDebug Debug;
In the setup function after WiFi initialization
// Initialize the server (telnet or web socket) of RemoteDebug
Debug.begin(HOST_NAME);
// OR
Debug.begin(HOST_NAME, startingDebugLevel);
// Options
Debug.setResetCmdEnabled(true); // Enable the reset command
// Debug.showProfiler(true); // To show profiler - time between messages of Debug
Note: to enable the debugger, by RemoteDebugger, please acess this github repository: RemoteDebugger
In the tail of loop function
// Remote debug over WiFi
Debug.handle();
// Or
debugHandle(); // Equal to SerialDebug
In any place of you code:
#ifndef DEBUG_DISABLED
if (Debug.isActive(Debug.<level>)) {
Debug.printf("bla bla bla: %d %s", number, str); // OR
Debug.printf("bla bla bla: %d %s", number, str.c_str()); // Note: if type is String need c_str() // OR
Debug.println("bla bla bla 2 ln");
Debug.printf("float: %f\n", value); // Not works in ESP8266 :-(
// Note: to show floats with printf (ESP8266 only),
// you can use my ArduinoUtil library -> https://github.com/JoaoLopesF/ArduinoUtil
Debug.printf("float: %s\n", Util.formatFloat(value, 0, 5).c_str());
}
#endif
Note: Using isActive, you need surround the code by DEBUG_DISABLE precompile condition, to avoid compile it for production/release
Or short way (equal to SerialDebug) (prefered if only one debug at time):
debugA("This is a any (always showed) - var %d", var);
debugV("This is a verbose - var %d", var);
debugD("This is a debug - var %d", var);
debugI("This is a information - var %d", var);
debugW("This is a warning - var %d", var);
debugE("This is a error - var %d", var);
debugV("This is a println");
Or if your project uses several Serial.print commands to generate a single debug message for example:
Serial.print("a = ");
Serial.print(a);
Serial.print(" b = ");
Serial.print(b);
Serial.print(" c = ");
Serial.println(c);
can be use rdebug* macros:
rdebugV("a = ");
rdebugV(a);
rdebugV(" b = ");
rdebugV(b);
rdebugV(" c = ");
rdebugVln(c);
Note: in future, I suggest that you migrate this to a single debug command:
debugV(a = %d b = %d c = %d", a, b, c);
An example of use debug levels: (supposing the data is a lot of characters)
if (Debug.isActive(Debug.VERBOSE)) { // Debug message long
Debug.printf("routine: data received: %s\n", data.c_str()); // Note: if type is String need c_str()
} else if (Debug.isActive(Debug.DEBUG)) { // Debug message short
Debug.printf("routine: data received: %s ...\n", data.substring(0, 20).c_str()); // %.20s not working :-|
}
Starting at version 1.5.0, debug macros (debug* and rdebug*), automatically put the name of function that called the macro, and core id (core id only for ESP32).
So:
void foo() {
uint8_t var = 1;
debugV("this is a debug - var %u", var);
}
It will show in client (telnet or web app):
(V p:^0000ms) (foo)(C1) this is a debug - var 1
Where:
V -> verbose
p -> profiler time
(foo) -> this is a function name that calls the debug macro
(C1) -> It is running it Core 1 (only for ESP32)
An example of use debug with serial enabled
Useful to see messages if setup or
in cause the ESP8266/ESP32 is rebooting (client connection stop before received all messages)
Only for this purposes I suggest it
// Setup after Debug.begin
Debug.setSerialEnabled(true); // All messages too send to serial too, and can be see in serial monitor
For reduce overheads RemoteDebug is disconnect the client (telnet or web app), if it not active.
- Please press enter or any key if you need keep the connection
- The default is 5 minutes (You can change it in RemoteDebug.h)
- You can use mDNS to register each node with different name, it helps to connect without know the IP.
Please not forget to use if clause with Debug.isActive (if not using debug macros)
---> This is very important to reduce overheads and work of debug levels
Please see the samples, basic or advanced, to learn how to use
In advanced sample, I used WifiManager library, ArduinoOTA and mDNS, please see it.
- Ajustment on debugA macro, thanks @jetpax and @cmidgley to add this issue.
- All public configurations (#defines) have moved to RemoteDebugCfg.h, to facilitate changes for anybody.
- Changed examples, with warnings on change any #define in project,
with workarounds if it not work. (thanks to @22MarioZ for added this issue)
- Adjustments if web socket is disabled
- Adjustments in examples, added one for debugger
- Adjustments in silente mode
- Commands from RemoteDebugApp now is treated
- Adjusts to RemoteDebugger support connection by web sockets
- If not disabled, add a web socket server to comunicate with RemoteDebugApp (HTML5 web app)
- The standard telnet still working, to debug with internet offline
- Ajustment on debugA macro, thanks @jetpax to add this issue
- Add empty rprint* macros, if debug is disabled
- Create option DEBUG_DISABLE_AUTO_FUNC
- Create macros to be used for code converter: rprint and rprintln
RemoteDebug now have an code converters to help migrate codes
- Create precompiler DEBUG_DISABLED to compile for production/release,
equal that have in SerialDebug
- Adjustments in examples
- Adjustments for the debugger: it still disable until dbg command, equal to SerialDebug
- The callback will to be called before print debug messages now
- And only if debugger is enabled in RemoteDebugger (command dbg)
- Changed handle debugger logic
- Added support to RemoteDebug addon library: the RemoteDebugger, an simple software debugger, based on SerialDebug
- New color system
- Bug -> sometimes the command is process twice
- Workaround -> check time
- New macros to compatibility with SerialDebug (can use RemoteDebug or SerialDebug) thanks to @phrxmd
- Fixed bug for MAX_TIME_INACTIVE, thanks to @achuchev to add this issue
- Adjustments based on pull request from @jeroenst (to allow serial output with telnet password and setPassword method)
- Serial output is now not allowed if telnet password is enabled
- Few adjustments
- Few adjustment in write logic
- Serial output adjustments (due bug in password logic)
- Correct rdebug macro (thanks @stritti)
- New silent mode (command s)
- Auto function name and ESP32 core id for rdebug* macros
- begin method have a option for port number
- Few adjustments
- Added new rdebug?ln to put auto new line
- Simple text password request feature (disabled by default)
Notes:
It is very simple feature, only text, no cryptography,
and the password is echoed in screen (I not discovery yet how disable it)
telnet use advanced authentication (kerberos, etc.)
Such as now RemoteDebug is not for production (releases),
this kind of authentication will not be done now.
- Adjustments in precompiler macros
- Bug in write with latest ESP8266 SDK
- Port number can be modified in project Arduino (.ino file)
- Few adjustments as ESP32 includes
- Adjustments, as avoid ESP32 include errors
- Telnet port of server can be modified by project
Just put it in your .ino, before the include:
- Shortcuts and client buffering to avoid mysterious delay of ESP networking
- Adjustments and now runs in Esp32 too.
- Adjustments and improvements from Beta versions.
New features:
- Filter
- Colors
- Support to Windows telnet client
- First Beta
- Sometimes (rarely) the connection over telnet becomes very slow.
Especially right after uploading firmware.
Reset command in telnet connection or turn off/on can be resolve it.
But I need find why it occurs
First thanks a lot for Igrr for bring to us the Arduino ESP8266 and to Espressif to Arduino ESP32
Thanks to Links2004 for a good web server socket, used for web app connection.
For the logo: thanks to a freepik and pngtree sites for free icons that have in logo
Resources:
- Example of TelnetServer code in http://www.rudiswiki.de/wiki9/WiFiTelnetServer
- arduinoWebSockets library in https://github.com/Links2004/arduinoWebSockets