No Data Received on Wire.write

I don’t get it how to convert the String SendData, to be able to send it with wire write.
With the code below the master is only receiving 0.
If i send wire.write(“This is a Test”); the data will be sent correct.

#include <Wire.h>
#include <Adafruit_AM2315.h>
#include <OneWire.h> 
#include <DallasTemperature.h>

//I2C Address Raspberry Pi Communitcation
#define MyAddress 0x40
int request = 0;
byte ReceivedData;

// OneWire DS1820B Setup
#define ONE_WIRE_BUS 2 
OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

// SensorData
float AM2315_temperature, AM2315_humidity;
float DS1820B_temperature;
Adafruit_AM2315 am2315;

void setup()
{
    // Serial Setup
    Serial.begin(9600);

    /* Raspberry PI Communication: Initialize I2C Slave & assign call-back function 'onReceive' on 'I2CReceived'*/
    Wire.begin(MyAddress);
    Wire.onReceive(I2CReceived);
    Wire.onRequest(I2CRequest);
    
    // DS1820B
    sensors.begin();

    // AM2315
    while (!Serial) {
      delay(10);
    }
  
    if (! am2315.begin()) {
      Serial.println("Sensor not found, check wiring & pullups!");
      while (1);
    }
  
}

void loop()
{
    
    // Read AM2315
    if (! am2315.readTemperatureAndHumidity(&AM2315_temperature, &AM2315_humidity)) {
      //Serial.println("Failed to read data from AM2315");
      return;
    }
    Serial.print("Temp *C: "); Serial.println(AM2315_temperature); Serial.print("Hum %: "); Serial.println(AM2315_humidity);
    
    // Read DS1820B
    sensors.requestTemperatures();
    DS1820B_temperature = sensors.getTempCByIndex(0);
    Serial.print("Temperature is: "); Serial.println(sensors.getTempCByIndex(0));
  
    delay(1000);
}

/* This function will automatically be called when RPi2 sends data to this I2C slave */
void I2CReceived(int NumberOfBytes)
{
    /* WinIoT have sent data byte; read it */
    ReceivedData = Wire.read();
    // Save to Global variable
    request = ReceivedData;
  
    Serial.print("Received Request:");
    Serial.println(ReceivedData);
}

/* This function will automatically be called when RPi2 requests for data from this I2C slave */
void I2CRequest()
{
    String SendData;
    if (request == 1)
    {
      SendData = ConstructResponse("AM2315","AM2315_01", "TH", AM2315_temperature, AM2315_humidity);
    }
    else
    {
      SendData = ConstructResponse("DS1820B","DS1820B01", "T", DS1820B_temperature, 0);
    }
    
    /*Send data to WinIoT */
    //Wire.write(SendData.c_str());

    char c[100];
    SendData.toCharArray(c, 100);
    
 
    Wire.write(c,100);
    Serial.println("SendData: ");Serial.println(c);
}

String ConstructResponse(String Type, String Name, String Capability, float temperature, float humidity)
{
  return "M:"+Type+",S:"+Name+",C:"+Capability+",T:"+String(temperature)+",H:"+String(humidity)+"\r\n\0";  
  
}
    Wire.write(c,100);

I really don't think you want to send ALL of those bytes...

i was just using 100 in terms of simplicity... I don't think that this would cause any Problems

pardalis:
i was just using 100 in terms of simplicity... I don't think that this would cause any Problems

The computer doesn't care what you think. If you want to play, you have to play by the computer's rules.
Try

    Wire.write(c,strlen(c) + 1);

like i said, this would not cause any Problems, even Wire.write("abc",10); sends the data.
the Problem seems to be in the Arduino library, the buffer size for wire.write() is only 32 bytes.
the two Strings are around 40 Bytes.

Everything after the terminating null in a C string is junk. If you don't mind sending junk over a communications channel, fine. Addressing your problem, the excessive size of your string is apparently due to the text labels. If you send the data as comma delimited fields, and you always transmit the data in the same order, you can send it that way and attach the text labels at the receiving end.

Long strings like, "AM2315_temperature" are a wasteful thing to send if your receiver can identify the data by more efficient means.