How do you send multiple sensor readings to MIT App from ESP32? Your tutorial shows only one sensor with MIT App receiving data with index of data.
Snip from your code:
// Temperature in Celsius temperature = sensors.getTempCByIndex(0); // Uncomment the next line to set temperature in Fahrenheit // (and comment the previous temperature line) //temperature = sensors.getTempFByIndex(0); // Temperature in Fahrenheit // Convert the value to a char array char txString[8]; dtostrf(temperature, 1, 2, txString); // Set new characteristic value pCharacteristic->setValue(txString); // Send the value to the Android application pCharacteristic->notify(); Serial.print("Sent value: "); Serial.println(txString); } delay(5000); }
Hi Rick.
In your Arduino code, you need to create another characteristic for the temperature value you want to send.
First, generate a new UUID for that characteristic.For example:
#define CHARACTERISTIC_UUID_TEMP2 "XXXXXXXXX-XXXX-XXXXX-XXXXX-XXXXXXXXXXXXXXXX
Then, create the characteristic with the WRITE property as we did for the other characteristic:
BLECharacteristic *pCharacteristic = pService->createCharacteristic( CHARACTERISTIC_UUID_TEMP2, BLECharacteristic::PROPERTY_WRITE);
Then, follow the same steps but using your new characteristic:
// Convert the value to a char array char txString[8]; dtostrf(temperature, 1, 2, txString); // Set new characteristic value pCharacteristic->setValue(txString); // Send the value to the Android application pCharacteristic->notify(); Serial.print("Sent value: "); Serial.println(txString); }
In the MIT app inventor, you need to create the chracteristic UUID:
So, you should have four UUIDs defined here instead of three.
Then, you nee to create a new set of blocks, similar to the next ones to get the new temperature values:
In the designer tab, you also need to create a new label to hold this new temperature value (do this step first).
I hope this helps.
Let me know if you need further help.
Regards,
Sara
Hi Sara,
Thank you very much for your response but where would you place this characteristic code?
I place it after the first temperature sent and when compile I have this error message:
exit status 1
‘pService’ was not declared in this scope
Thanks again,
Rick
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TEMP2,
BLECharacteristic::PROPERTY_WRITE);
Hi Sara,
I finally decided to use only one stream to the android app by combining all the char array.
sprintf(txString, “%s,%s,%s”, temperatureString, humidityString, doorStatus); //CSV format
On the Android:
Use list list item split text at “,”
Thank you,
Rick