convert received serial to IEEE 754 Single Precision 32-bit

hello everybody!

i’m using my arduino to send data from an energy meter to mqtt server, from my energy meter i received a decimal number. i want to convert it to IEEE 754 single precision 32-bit.

For example : when i received 67 84 0 0, the conversion to IEEE 754 is 212 when i using excel

The published massage :

67
84
0
0

i need it to display :

212

here is the code i wrote :

#include <SoftwareSerial.h>
#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#define X2 1024

byte mac = { 0x90, 0xA2, 0xDA, 0x0E, 0xA1, 0x1B };
byte server = { 192, 168, 0, 12 };
byte ip = { 192, 168, 0, 15 };

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

}

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);

#define rxPin 0
#define txPin 1
byte req= {0x01, 0x04, 0x00, 0x10, 0x00, 0x02, 0x70, 0x0E};
byte req2 = 04;
byte inByte = 0;

void setup()
{
Serial.begin(1200, SERIAL_8E1);
pinMode(txPin, OUTPUT);
pinMode(rxPin, INPUT);
Serial.write(req, 8);

Ethernet.begin(mac, ip);
if (client.connect(“arduinoClient”))
{
client.publish(“outTopic”,“ENERGY_METER_CONNECTED”);
}

}

void loop()
{

Serial.write(req, 8);
delay(500);

{
while (Serial.available()>0)
{
for (int x =0; x < 9 ; x++)
{
int inbyte ;
char message_buff[9];
String str;
inByte = Serial.read() ;

if (x > 2 && x < 7)
{
str = String(inByte) ;
str.toCharArray(message_buff, 9);

client.publish(“outTopic”,message_buff);
}
}
}
}
client.publish(“outTopic”,"---------");
delay(9000);

}

Thanks. Rey

Sounds like a job for Unions.

A working example

void setup() {
  Serial.begin(115200);  
  byte array[4] = {67,84,0,0};
  Serial.print(convert(array));
}

void loop(){}

typedef union {
  byte array[4];
  float value;
} ByteToFloat;

float convert(byte* data) {
  ByteToFloat converter;
  for (byte i = 0; i < 4; i++){
    converter.array[3-i] = data[i]; //or converter.array[i] = data[i]; depending on endianness 
  }
  return converter.value;
}

It works! thank you