Problem displaying uint8* to client.

Hi, im trying to print the value of my DFRobot Heartrate sensor, i'm using mosquitto mqtt broker with node-red and an esp8266 as client. I can't print out the variable because it doesn't follow the parameters in the pubsub client. How can I make a way to print this? I've searched for quite awhile but ended up with nothing, Im fairly new to arduino and programming so please help me.

This is the code that i'm working on

/*****
 
 
*****/

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#define heartratePin A0
#include "DFRobot_Heartrate.h"
DFRobot_Heartrate heartrate(DIGITAL_MODE); ///< ANALOG_MODE or DIGITAL_MODE



// Change the credentials below, so your ESP8266 connects to your router
const char* ssid = "Tenda_FE2038";
const char* password = "huertas032793";

// Change the variable to your Raspberry Pi IP address, so it connects to your MQTT broker
const char* mqtt_server = "192.168.1.14";

// Initializes the espClient. You should change the espClient name if you have multiple ESPs running in your home automation system
WiFiClient espClient;
PubSubClient client(espClient);




// Timers auxiliar variables
long now = millis();
long lastMeasure = 0;

// Don't change the function below. This functions connects your ESP8266 to your router
void setup_wifi() {
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.print("WiFi connected - ESP IP address: ");
  Serial.println(WiFi.localIP());
}

// This functions is executed when some device publishes a message to a topic that your ESP8266 is subscribed to
// Change the function below to add logic to your program, so when a device publishes a message to a topic that 
// your ESP8266 is subscribed you can actually do something
void callback(String topic, byte* message, unsigned int length) {
  Serial.print("Message arrived on topic: ");
  Serial.print(topic);
  Serial.print(". Message: ");
  String messageTemp;
  
  for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
    messageTemp += (char)message[i];
  }
  Serial.println();


  Serial.println();
}

// This functions reconnects your ESP8266 to your MQTT broker
// Change the function below if you want to subscribe to more topics with your ESP8266 
void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
  
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");  
      // Subscribe or resubscribe to a topic
      // You can subscribe to more topics (to control more LEDs in this example)
      client.subscribe("bpm/test");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
}

// The setup function sets your ESP GPIOs to Outputs, starts the serial communication at a baud rate of 115200
// Sets your mqtt broker and sets the callback function
// The callback function is what receives messages and actually controls the LEDs
void setup() {

  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);

}

// For this project, you don't need to change anything in the loop function. Basically it ensures that you ESP is connected to your broker
void loop() {

  if (!client.connected()) {
    reconnect();
  }
  if(!client.loop())
    client.connect("ESP8266Client");

  now = millis();
  // Publishes new temperature and humidity every 30 seconds
  if (now - lastMeasure > 200) {
    lastMeasure = now;
   
  

  uint8_t rateValue;
  heartrate.getValue(heartratePin); ///< A1 foot sampled values
  rateValue = heartrate.getRate(); ///< Get heart rate value 

  if(rateValue)  {
    Serial.println(rateValue);
  }
  delay(20);
  
   client.publish("bpm/test", rateValue);


  }
}

This is where the compiler is pointing to in the error

uint8_t rateValue;
  heartrate.getValue(heartratePin); ///< A1 foot sampled values
  rateValue = heartrate.getRate(); ///< Get heart rate value 

  if(rateValue)  {
    Serial.println(rateValue);
  }
  delay(20);
  
   client.publish("bpm/test", rateValue);

this the error that im getting

thank you in advance!

"rateValue" has to be converted to a string:

char numstr[4];
itoa(rateValue, numstr, 10);
client.publish("bpm/test", numstr);

The program now compiles, but i get 0 value now

Danois90:
"rateValue" has to be converted to a string:

char numstr[4];

itoa(rateValue, numstr, 10);
client.publish("bpm/test", numstr);

i've also tried to make the array size a bit larger but still getting 0 values on serial monitor and on the client.

Check your connections, heartratePin is A0.

Danois90:
Check your connections, heartratePin is A0.

it is on A0, that is the default comment i just forgot to change