Problem compiling CmdMessenger Library for ESP8266

Hey everyone!

I’m trying to make an Arduino Uno talk to an WeMos D1 Mini / ESP8266 over Serial with the CmdMessenger Library. It works fine on the Uno, but I can’t compile any of the examples for the D1.

Here’s the first example code from the library

// *** Receive ***

// This 1st example will make the PC toggle the integrated led on the arduino board. 
// It demonstrates how to:
// - Define commands
// - Set up a serial connection
// - Receive a command with a parameter from the PC

#include <CmdMessenger.h>  // CmdMessenger

// Blinking led variables 
bool ledState                   = 0;   // Current state of Led
const int kBlinkLed             = 13;  // Pin of internal Led

// Attach a new CmdMessenger object to the default Serial port
CmdMessenger cmdMessenger = CmdMessenger(Serial);

// We can define up to a default of 50 cmds total, including both directions (send + receive)
// and including also the first 4 default command codes for the generic error handling.
// If you run out of message slots, then just increase the value of MAXCALLBACKS in CmdMessenger.h

 // This is the list of recognized commands. These can be commands that can either be sent or received. 
 // In order to receive, attach a callback function to these events
 // 
 // Note that commands work both directions:
 // - All commands can be sent
 // - Commands that have callbacks attached can be received
 // 
 // This means that both sides should have an identical command list:
 // both sides can either send it or receive it (or even both)    

// Commands
enum
{
  kSetLed, // Command to request led to be set in specific state
};

// Callbacks define on which received commands we take action 
void attachCommandCallbacks()
{
  cmdMessenger.attach(kSetLed, OnSetLed);
}

// Callback function that sets led on or off
void OnSetLed()
{
  // Read led state argument, interpret string as boolean
  ledState = cmdMessenger.readBoolArg();
  // Set led
  digitalWrite(kBlinkLed, ledState?HIGH:LOW);
}

// Setup function
void setup() 
{
  // Listen on serial connection for messages from the PC
  // 115200 is the max speed on Arduino Uno, Mega, with AT8u2 USB
  // Use 57600 for the Arduino Duemilanove and others with FTDI Serial
  Serial.begin(115200); 

  // Adds newline to every command
  cmdMessenger.printLfCr();   

  // Attach my application's user-defined callback methods
  attachCommandCallbacks();

  // set pin for blink LED
  pinMode(kBlinkLed, OUTPUT);
}

// Loop function
void loop() 
{
  // Process incoming serial data, and perform callbacks
  cmdMessenger.feedinSerialData();
}

I have attached the full build log I’m getting (verbose).

Here’s the first (I believe) relevant snippet:

/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp: In member function 'void HeaterSim::CalcTemperature()':
/home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp:73:72: error: no matching function for call to 'max(long unsigned int, int)'
  if (currentTime >= _lastTime) _deltams = max(currentTime - _lastTime,1);

Is it possible that the library won’t work with the ES8266? Or am I just missing something?
Other sketches not including this library work just fine.

Thank in advance

d1_cmd_compile_error.txt (14.1 KB)

The recent versions of the ESP8266 core for Arduino changed to a max() function that requires the arguments to have the same type. You would need to edit the library as follows:

  • Open /home/anselm/Arduino/libraries/CmdMessenger/utility/HeaterSim.cpp in a text editor.
  • Change line 73 from:
if (currentTime >= _lastTime) _deltams = max(currentTime - _lastTime,1);

to:

if (currentTime >= _lastTime) _deltams = max(currentTime - _lastTime,1UL);
  • Save the file.
  • Try compiling your code again.

I have submitted a pull request to the library with this fix:

Thanks, that fixed it! Hope the owner of the repo merges it soon.