What you need:

I discovered this Arduino library a few weeks ago, and was surprised to see that there aren’t more projects that make use of it. I feel that anyone that is using OTA would have a use for this library. So I decided to make a post because I’m thinking that there are many people that don’t know about it. This library was written by JoaoLopesF.

What RemodeDebug does is startup a telnet server on the ESP8266 and allow you to send debug messages via telnet. So if you need to view the debug messages, you can do it remotely instead of having to connect it to your computer. Another nice feature is that it has an option to also send the debug messages out to Serial. It also uses a similar syntax to Serial, which allows you to convert your existing debug commands using a quick find and replace.

The main problem I’ve had since using the library, is that it can only output the debug commands in your own code. Anything that is output by a library that you are using would still only get sent out Serial. Unfortunately, I couldn’t find any solution to this that could be accomplished without editing those libraries. If anyone can think of a way to do this, please let me know.

Another minor thing, which I was able to create a solution for was figuring out how to disable the telnet server ( Since I typically didn’t want the telnet server running all the time). I was basically comment a bunch of code to disable it. But then I realized that I just had to comment the RSerial.handle(); line. This effectively tells the ESP to not process any telnet connections. I then went a step further, and used a boolean and an ‘if’ statement to disable the telnet server.

My code below provides an example of the library in action. This is my ‘base’ code that I have started to use in all my new projects. It uses the WifiManager to make it easy to connect the device and also uses OTA updates over HTTP. It outputs the time along with the amount of memory that is being used. You can see the memory usage go up when you connect, and if you type text into the telnet window.

#include <ESP8266WiFi.h>          //ESP8266 Core WiFi Library (you most likely already have this in your sketch)
#include <DNSServer.h>            //Local DNS Server used for redirecting all requests to the configuration portal
#include <ESP8266WebServer.h>     //Local WebServer used to serve the configuration portal
#include <WiFiManager.h>          //https://github.com/tzapu/WiFiManager WiFi Configuration Magic
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
#include <RemoteDebug.h>

////**********START CUSTOM PARAMS******************//

//Define parameters for the http firmware update
const char* host = "BaseCodeESP";
const char* update_path = "/WebFirmwareUpgrade";
const char* update_username = "admin";
const char* update_password = "espP@ssw0rd";

//Define the pins

//Define MQTT Params
#define mqtt_server "192.168.45.104"
#define sensorTopic "base/code"
const char* mqtt_user = "mqtt_user"; 
const char* mqtt_pass = "mqtt_pass";

bool RemoteSerial = true; //true = Remote and local serial, false = local serial only

//************END CUSTOM PARAMS********************//
 
RemoteDebug RSerial;

const char compile_date[] = __DATE__ " " __TIME__;

ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;

WiFiManager wifiManager;

void setup() {

  Serial.begin(9600);

  RSerial.begin(host); 
  RSerial.setSerialEnabled(true);

  //Set the wifi config portal to only show for 3 minutes, then continue.
  wifiManager.setConfigPortalTimeout(180);
  wifiManager.autoConnect(host);

  //setup http firmware update page.
  MDNS.begin(host);
  httpUpdater.setup(&httpServer, update_path, update_username, update_password);
  httpServer.begin();
  MDNS.addService("http", "tcp", 80);
  RSerial.printf("HTTPUpdateServer ready! Open http://%s.local%s in your browser and login with username '%s' and your password\n", host, update_path, update_username);
}

void loop() {

  httpServer.handleClient(); //handles requests for the firmware update page
  
  if (RemoteSerial) RSerial.handle();
  RSerial.printf( "Time: %ld\n", millis());
  RSerial.printf( "Heap Free: %ld\n", system_get_free_heap_size());
  delay(1000);
}

And in case anyone was going to say it, I know that telnet is not secure. If anyone is planning on using this library, I would suggest you only use it when you need to debug. Once you have done that, just disable it, and re-upload the code. There are also a lot more option available, such as filtering by severity level. Be sure to check out the GitHub page for the library for that.

Leave a Reply