Invalid conversion from 'const char*' to 'unsigned char* on WeMos D1 R1

I am trying to simplify an air quality sensor set up for a schools project by moving it from an Uno board to a WeMos D1 R1 (less wires, easier power, built in wifi).

I'm using the Honeywell HPMA115S0 sensor, and the library at GitHub - felixgalindo/HPMA115S0: Arduino Library for Honeywell's Particle Sensor (HPMA115S0-XXX)

It compiles fine on the Uno, but changing across to the ESP8266 WeMos, I am getting multiple errors all in the format;

\HPMA115S0-master\src\hpma115S0.cpp: In member function 'void HPMA115S0::DisableAutoSend()':

\HPMA115S0-master\src\hpma115S0.cpp:171:17: error: invalid conversion from 'const char*' to 'unsigned char*' [-fpermissive]

SendCmd(cmd, 4);

I am assuming this is due to some variation in the way the code needs compiling for WeMos board, and looking online, have seen discussions about declared constants (but can't see any of this happening in the .h file)

Is there a simple tweak to allow this library to work on the WeMos board?

Thanks

/**
 * @file example.ino
 * @author Felix Galindo
 * @date June 2017
 * @brief Example using HPMA115S0 sensor library on a Feather 32u4
 * @license MIT
 */
#include <hpma115S0.h>
#include <SoftwareSerial.h>

//Create an instance of software serial
SoftwareSerial hpmaSerial(10, 11); // Feather TX, Feather RX

//Create an instance of the hpma115S0 library
HPMA115S0 hpma115S0(hpmaSerial);

void setup() {
  Serial.begin(57600);
  hpmaSerial.begin(9600);
  delay(5000);
  Serial.println("Starting...");
  hpma115S0.Init();
  hpma115S0.StartParticleMeasurement();
}

void loop() {
  unsigned int pm2_5, pm10;
  if (hpma115S0.ReadParticleMeasurement(&pm2_5, &pm10)) {
    Serial.println("PM 2.5: " + String(pm2_5) + " ug/m3" );
    Serial.println("PM 10: " + String(pm10) + " ug/m3" );
  }
  delay(1000);
}

HPMA115S0.h (2.91 KB)

hpma115S0.cpp (5.08 KB)

It looks like the compiler is whining about the inconsistent use of ‘char *’ and ‘unsigned char *’ within the library itself. It could be that different board packages cause the compiler to be invoked with different levels of pickiness.

You might have to go into the library’s .h and .cpp files and enforce some consistency in the use of various char and char * types.

Thanks. Have been through the .h and .cpp and taken out any of the 'unsigned' or 'const' and the sketch is now working.

For my learning, I assume this is because the wemos board has a compiler with a different author than the uno, so they are enforcing different check rules on the way through?

Assume removing the unsigned or const won't cause problems in this case, as I'm not desperate to enforce integer integrity. Is that correct?

Really appreciate the help.

chris_chiswell:
Thanks. Have been through the .h and .cpp and taken out any of the 'unsigned' or 'const' and the sketch is now working.

I would have gone with ‘unsigned char’ because of lines like:

const char cmdBuf[] = {0x68, 0x01, 0x04, 0x93};

The 0x93 sticks out as an issue.

For my learning, I assume this is because the wemos board has a compiler with a different author than the uno, so they are enforcing different check rules on the way through?

More likely it’s invoked with different options.

Assume removing the unsigned or const won't cause problems in this case, as I'm not desperate to enforce integer integrity. Is that correct?

It would be better to use ‘const’ where appropriate, especially in the prototypes and definition of functions that promise not to modify the string being pointed to.

If the function does modify the string, then you shouldn’t be calling it with an argument pointing to a constant value defined at compile time.