Send data in HEX using PubSubClient MQTT library (ESP8266)

hello i recently tried the code below to make a “network remote” with an old remote and an ir receiver(which both work and the ir reiciver works ond the esp8266) I previously got the codes from the remote using a script and wrote them down.Then I uploaded the code below to the ESP8266 and it worked…Only problem is it looked different this is the response from the Serial Monitor:

A9DE0
Receive value: 695776

The first part was correct, but the other part was the part I got in my mqtt broker. After trying to “convert it” so it would say only the hex I was greeted with this error:

invalid conversion from 'uint64_t {aka long long unsigned int}' to 'const char*' [-fpermissive]

Full Error:

Arduino: 1.8.12 (Windows 10), Board: "Generic ESP8266 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

C:\Users\Admin\Desktop\sketch_jun22b\sketch_jun22b.ino: In function 'void loop()':

sketch_jun22b:110:49: error: invalid conversion from 'uint64_t {aka long long unsigned int}' to 'const char*' [-fpermissive]

       client.publish("OsoyooData", results.value);

                                                 ^

In file included from C:\Users\Admin\Desktop\sketch_jun22b\sketch_jun22b.ino:11:0:

C:\Users\Admin\Documents\Arduino\libraries\pubsubclient\src/PubSubClient.h:130:12: error:   initializing argument 2 of 'boolean PubSubClient::publish(const char*, const char*)' [-fpermissive]

    boolean publish(const char* topic, const char* payload);

            ^

exit status 1
invalid conversion from 'uint64_t {aka long long unsigned int}' to 'const char*' [-fpermissive]

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

and finally the full code:

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <IRremoteESP8266.h>
#include <IRsend.h>
#include <IRrecv.h>

int modem = 2; //an IR detector/demodulatord is connected to GPIO pin D4
// Update these with values suitable for your network.
const char* ssid = "Fsociety";
const char* password = "0911BraunWFIWI";
const char* mqtt_server = "192.168.0.2";
const char* userName = "admin";
const char* passWord = "test";

WiFiClient espClient;
PubSubClient client(espClient);
IRrecv irrecv(modem);
decode_results results;

long lastMsg = 0;
char msg[50];
int value = 0;

void setup_wifi() {
   delay(100);
  // We start by connecting to a WiFi network
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) 
    {
      delay(500);
      Serial.print(".");
    }
  randomSeed(micros());
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) 
{
  
} //end callback

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) 
  {
    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "ESP8266Client-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
    //if you MQTT broker has clientID,username and password
    //please change following line to    if (client.connect(clientId,userName,passWord))
    if (client.connect(clientId.c_str(), "admin", "test"))
    {
      Serial.println("connected");
     //once connected to MQTT broker, subscribe command if any
      client.subscribe("OsoyooCommand");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
  }
} //end reconnect()

void setup() {
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1884);
  client.setCallback(callback);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();
  long now = millis();
  //每隔6S发送一次数据
  if (now - lastMsg > 2000) {
     lastMsg = now;
    if (irrecv.decode(&results)) 
    {
      Serial.println((long)results.value, HEX);
      irrecv.resume(); // Receive the next value
      String msg="Receive value: ";
      msg= msg+ (long)results.value;
      char message[58];
      msg.toCharArray(message,58);
      Serial.println(message);
       //publish sensor data to MQTT broker
      client.publish("OsoyooData", results.value);
     }
  }
}

Did you mean

client.publish("OsoyooData", message);

Thanks for taking your time to answer, no the message is what sends the number in the format I don't want, the result.value is the variable I want but can't get because of the error

Here are the function prototypes for the PubSubClient publish() function

   boolean publish(const char* topic, const char* payload);
   boolean publish(const char* topic, const char* payload, boolean retained);
   boolean publish(const char* topic, const uint8_t * payload, unsigned int plength);
   boolean publish(const char* topic, const uint8_t * payload, unsigned int plength, boolean retained);

Which of them does your
client.publish("OsoyooData", results.value);match ?

What data type is results.value ?

What you might want to do is to read up on the PubSubClient library and pay particular attention as to how to use the publish method. Take a special note of the argument parameter types. You'll find the parameters being passed to the function do NOT match the expected argument types.

It is the boolean publish(const char* topic, const char* payload);
I don't know that is why I gave the error in the description. From the error is this a possible data type?
long long unsigned int

Erikthegamer:
It is the boolean publish(const char* topic, const char* payload);
I don't know that is why I gave the error in the description. From the error is this a possible data type?
long long unsigned int

What argument types does this want publish(const char* topic, const char* payload);?

What argument types are you passing?

Idahowalker:
What you might want to do is to read up on the PubSubClient library and pay particular attention as to how to use the publish method. Take a special note of the argument parameter types. You'll find the parameters being passed to the function do NOT match the expected argument types.

I know it doesn't match. From the error I can see I need to convert from long long unisinged int to const char*
my question is how should I do that?

Another failed internet search.

Anyways, I use: MQTTclient.publish( topicInsideTemp, String(ePtr[0]).c_str() );

My thingy do may not match your thingy do and, so, my thing do may not work with your thing to do.