Now I managed to include some sort of "STARTING-check":
Basically every correctly transfered float now has a "89" infront of it, so e.g. "8912.34" or "-8926.78". Then the receiving arduino subtracts or adds 8900 to that float.
"END-check" isn't as "easy" as that because Arduinos (at least the UNO) only allows for 2 digits after the comma to be transfered over the serial. And adding a char to the end wasn't as easy as I thought (....try to convert a float with no special length to a char array/String... frustrating...). So I gave up on the "End-check".
The good part:
Now my sketch recognizes if the beginning of a float is missing.
The sad part:
My new code is still not reliable
The worst part
Now the communication is so slow, that it takes 2-4 sec to transfer and then 1 sec to process every float... !
ARDUINO UNO:
#include <SoftwareSerial.h>// import the serial library
#include <DHT.h> // weisser Temp-/Feuchtigkeitssensor
SoftwareSerial mySerial(9, 10); // DTX Pin of HC-05 to Pin 9 (=SoftSerial RX) of UNO and DRX to Pin 10 (=SoftSerial TX)
DHT dht; // fuer weissen Temp+Feuchtsensor
unsigned long time; // Um delays zu ersetzen
char c;
void setup() {
mySerial.begin(9600);
dht.setup(7);
}
void loop() {
delay(dht.getMinimumSamplingPeriod());
float temperaturCsensorDHT = dht.getTemperature();
mySerial.print(temperaturCsensorDHTtransfer);
delay(350);
}
ARDUINO YUN:
#include <AltSoftSerial.h> // Forced to use Pins 5 and 13 on the Yun/Leonardo
AltSoftSerial mySerial;
void setup(){
mySerial.begin(9600);
}
void loop() {
float temperaturBLUETOOTH_1 = 0.00;
int i2 = 0;
char char_arr[10];
// YUN LOOKS EVERY LOOP FOR INCOMING BLUETOOTH. IF THERE IS INCOMING DATA;
if (mySerial.available() > 0) {
while (mySerial.available() > 0) {
char c = mySerial.read();
char_arr[i2] = c;
i2++;
}
// ++++++ Successfull transfers need to start with "89" or "-89" +++++
// if positive float
if (char_arr[0] == 56 && char_arr[1] == 57) {
mySerial.print("3"); // Says "THANKS I GOT IT" to the UNO over bluetooth by sending a "3"
float temperaturBLUETOOTH_1_with89 = atof(char_arr);
temperaturBLUETOOTH_1 = temperaturBLUETOOTH_1_with89 - 8900;
}
// if negative float:
if (char_arr[0] == 45 && char_arr[1] == 56 && char_arr[2] == 57) {
mySerial.print("3"); // Says "THANKS I GOT IT" to the UNO over bluetooth by sending a "3"
float temperaturBLUETOOTH_1_with89 = atof(char_arr);
temperaturBLUETOOTH_1 = temperaturBLUETOOTH_1_with89 + 8900;
}
}
}