Arduino_byte array einlesen / in Float int oder bool konvertieren

Hallo Kollegen,
habe hier ein problem...

ihabe ein beispiel sketch hier:

#include <SPI.h>
#include <Ethernet.h>
#include <PubSubClient.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>


// Update these with values suitable for your network.
byte mac[]    = {  0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
byte server[] = { 192, 168, 111, 97 };
byte ip[]     = { 192, 168, 111, 99 };


// Temperature (DS18B20) connected to pin 7
//OneWire ds(7);


// MQTT message buffer
char message_buff[30];

// MQTT callback
void callback(char* topic, byte* payload, unsigned int length);

// MQTT PubSub client
EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);

// MQTT callback function
void callback(char* topic, byte* payload, unsigned int length) {
  // Convert payload to string
int i;
  for(i=0; i<length; i++) {
    message_buff[i] = payload[i];
  }
  message_buff[i] = '\0';
  if (message_buff[i]==3.2){Serial.println("float");Serial.println(message_buff);}
  if (message_buff[i]==0){Serial.println("bool");Serial.println(message_buff);}
  String msg = String(message_buff);
  Serial.println(message_buff);
}

// Setup
void setup() {
  // Start the node at the IP address  
  Serial.begin(115200);
  Ethernet.begin(mac, ip);

  // Start MQTT client, 
  // let the home know the office is up

  if (client.connect("office")) {
    client.publish("/home/status/","office up");

  }
}


// Loop
void loop() {
  // Start MQTT client
  client.loop();
  // Read current temperature and 
  // publish it to /home/office/temperature/
  
}


// Temperature reading from DS18B20 module
// Code is from OneWire library example

und möchte den payload was ein byte array ist in int float oder bool konvertieren(kommt drauf an was vom server as payload kommt).

sitze schon seit heute früh ran und ohne erfolg...

Hat jemand einen tipp?

danke!

Am einfachsten ist es du machst eine Union aus dem Byte Array und einem int und einem float. Dann belegen die Variablen den gleichen Speicherplatz. Man kann auch mit Zeigern und Casts arbeiten, aber eine Union ist sauber und leichter lesbar.

Bei bool brauchst du nichts zu konvertieren. 0 ist false und alles andere ist true.

so was?

habe nie damit gearbeitet...

kannst du mir ne hlfestellung geben?

float readFloat(unsigned int addr)
{
 union
 {
  byte b[4];
  float f;
 } data;
 for(int i = 0; i < 4; i++)
 {
  data.b[i] = EEPROM.read(addr+i);
 }
 return data.f;
}

echt keiner ein tipp?