• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

ESP32 BLE to MIT App

Q&A Forum › Category: ESP32 › ESP32 BLE to MIT App
0 Vote Up Vote Down
Rick Keerikoolparn asked 6 years ago

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);
}
5 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

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

0 Vote Up Vote Down
Rick Keerikoolparn answered 6 years ago

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

0 Vote Up Vote Down
Rick Keerikoolparn answered 6 years ago

BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID_TEMP2,
BLECharacteristic::PROPERTY_WRITE);

0 Vote Up Vote Down
Rick Keerikoolparn answered 6 years ago

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

0 Vote Up Vote Down
Sara Santos Staff answered 6 years ago

Hi Rick.
Yes, that’s also a good alternative – and easier.
I’ll mark this question as resolved. If you need further help, you just need to open a new question in our forum.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.