Getting App Inventor to work with BLE and Seeeduino ESP32C3

Greetings,

I am so very confused by the block programming method and I am simply trying to get a basic .ala file working. This file is originally someone else's creation and I have had someone help me who really didn't fix anything.

I would like someone to provide me a quote to get the attached .ala file up and running such that it reads the three UUID parameters sent by my .ino sketch that include temperature, humidity, and atmospheric pressure.

The .ala, as provided, can find the .ino sketch but will not activate or connect with it.

The .ino sketch uses a Seeeduino ESP32C3 and it can be started and discovered by "nRF Connect."

Respectfully - Baran
BME_nRF_Good.ino (2.4 KB)
BME_BLE_1_1.aia (915.8 KB)

1 Like

Looking at the files briefly, there is nothing particularly wrong that stands out as a show stopper, but you do not need 3 Characteristic UUIDs, they are all floats and can share one UUID. Also the sketch loop uses a delay(), which can have a detrimental effect on the sensor values - instead an elapsed time method should be used.

So your issue may not be the code but the hardware.

However, you need to decide if your App will only work with the device address embedded in the code (blocks) or with the address the User selects from the list of devices found. At the moment both are present in the aia.

Greetings,

I am floored by your casual review and deep knowledge of the blocks. Given what you said, I will try removing the selection process and try to force the .ala to connect with a matching UUID.

Is there a limit to the number of floats that can share one UUID? I will ultimately be transmitting many calculated values (24, to be exact). Is this something that would still work with one UUID? If I may ask one more question, can you direct me to an example of sharing multiple characteristics in one UUID? Thank you.

The amount of data you can assign to one UUID is determined by the Bluetooth "packet size". Something that every Sketch/Script must do is set the decimal places of the value. Normally two decimal places will suffice, but a sensor could produce as many as 12. The art of Bluetooth communication is to keep it "tight".

See my website about the maximum transmission unit (MTU):
https://www.professorcad.co.uk/appinventortips#TipsBluetooth

24 values? When you say they are calculated, am I right to assume there isn't going to be 24 hardware sensors? If so, I would send the 'raw' values to the App and perform the calculations in the App, thereby keeping the Bluetooth comms tight. Edit: writeValues are correct but the App is bombarded with them.

We share a UUID for any type of value as a string:
Drawing1

1 Like

I have experience with block programming, Seeeduino ESP32C3, and resolving connectivity issues. I can provide a quote to get your .ala file working with your .ino sketch to read temperature, humidity, and atmospheric pressure parameters.

Let's discuss how I can assist you further via jack(at)technogiq(dot)com

//https://www.professorcad.co.uk/appinventortips#BleUuids
#define BLE_SERVICE_UUID "0357A1D0-58C9-48E5-8C81-3DA5D49C5C21"
#define BLE_CHARACTERISTIC_UUID "0357A1D1-58C9-48E5-8C81-3DA5D49C5C21"

// Create BME280 sensor object
Adafruit_BME280 bme;

// Service
BLEService bmeService(BLE_SERVICE_UUID);
// Characteristic
BLEStringCharacteristic bmeCharacteristic(BLE_CHARACTERISTIC_UUID, BLEWrite | BLENotify, 32); 


void updateValues()
{
      char sSensorVals[32]; // Buffer

               // To Serial Monitor
               Serial.print("Temperature: "); Serial.print(Temperature); Serial.println(" °C");
               Serial.print("Humidity: ");    Serial.print(Humidity);    Serial.println(" %");
               Serial.print("Pressure: ");    Serial.print(Pressure);    Serial.println(" hPa");

               sprintf(sSensorVals, "%.2f|%.2f|%.2f\0", Temperature, Humidity, Pressure); 
               bmeCharacteristic.writeValue(sSensorVals); //To App
}

In the Blocks, StringsReceived can be used:

I am grateful for all of the offers to help, as well as the advice. I have already successfully removed the portion of my code that scans and restricted it to just my service UUID. When I did so, the device connected within a few seconds.

As many of you are knowledgeable in Arduino .ino files, as well, might someone have a quick and (relatively) easy answer as to why all 3 data on the .ala appears as "0"? I think it has something to do with the following three lines (43 - 45) of Arduino code, although I am not at all certain what to replace them with . . .

temperatureCharacteristic.writeValue(0);
humidityCharacteristic.writeValue(0);
pressureCharacteristic.writeValue(0);

I am attaching that new, improved (but not at all finished;) .ala file in case the error is on that end, instead.

I now feel as though I might be able to pull this one off with a lot of studying and review, and no small amount of help from the community. I am grateful for all of the advice and I will be incorporating it as soon as I can digest it. Thanks, again.

BME_nRF_Good.ino (2.4 KB)
Almost_Working.aia (915.4 KB)

To make it easier on my M.A.I. friends, here is the image of the existing blocks . . .

I think you can do it Baran. Here is Sketch that shows how multiple values can use the same Characteristic. It is based on a successful project that monitors various car engine temperatures and fan speed so it should work for you (compiles without issue here but I don't have a Seeeduino ESP32C3).

Also attached is a matching App Inventor file. To test it, build as an APK on your device. Again, it is based on a successful project so it should work for you but I can't test it here. The App file makes a list of devices found by scanning -you can of course change that, but at this stage I would stick with scanning - if there is a hardware issue for any reason, a hard coded address does not give as much useful information.

BME_SensorObject.ino (3.8 KB) re-uploaded

Psychrometer.aia (246.2 KB)

I think it's probably because the Characteristics specify BLERead instead of BLEWrite.

I don't think it is necessary to have these lines:

temperatureCharacteristic.writeValue(0);
humidityCharacteristic.writeValue(0);
pressureCharacteristic.writeValue(0);

Hi, Chris

I apologize for being so dense but I hope you know what is going on. According to everything I can find, the .ino code you provided has some stray invisible characters in it that are stoping the compile. I tried copying the code to a forum website using markdown commands and recopying the "cleansed" code but I still get the "stray /277 errors.

Can you see in the following error messages what might be wrong?

C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:1:1: error: stray '\357' in program
#include <ArduinoBLE.h>
^
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:1:2: error: stray '\273' in program
#include <ArduinoBLE.h>
^
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:1:3: error: stray '\277' in program
#include <ArduinoBLE.h>
^
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:1:4: error: stray '#' in program
#include <ArduinoBLE.h>
^
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:1:5: error: 'include' does not name a type
#include <ArduinoBLE.h>
^~~~~~~
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:12:1: error: 'BLEService' does not name a type
BLEService bmeService(BLE_SERVICE_UUID);
^~~~~~~~~~
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:14:1: error: 'BLEStringCharacteristic' does not name a type
BLEStringCharacteristic bmeCharacteristic(BLE_CHARACTERISTIC_UUID, BLEWrite | BLENotify, 32);
^~~~~~~~~~~~~~~~~~~~~~~
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino: In function 'void setup()':
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:29:21: error: 'BLE' was not declared in this scope
if (!BLE.begin())
^~~
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:29:21: note: suggested alternative: 'FILE'
if (!BLE.begin())
^~~
FILE
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:41:16: error: 'BLE' was not declared in this scope
BLE.setLocalName(BLE_NAME);
^~~
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:41:16: note: suggested alternative: 'FILE'
BLE.setLocalName(BLE_NAME);
^~~
FILE
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:42:41: error: 'bmeService' was not declared in this scope
BLE.setAdvertisedService(bmeService);
^~~~~~~~~~
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:42:41: note: suggested alternative: 'rmtSetTick'
BLE.setAdvertisedService(bmeService);
^~~~~~~~~~
rmtSetTick
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:45:45: error: 'bmeCharacteristic' was not declared in this scope
bmeService.addCharacteristic(bmeCharacteristic);
^~~~~~~~~~~~~~~~~
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:45:45: note: suggested alternative: 'Character_h'
bmeService.addCharacteristic(bmeCharacteristic);
^~~~~~~~~~~~~~~~~
Character_h
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino: In function 'void updateValues()':
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:62:16: error: 'bmeCharacteristic' was not declared in this scope
bmeCharacteristic.writeValue(sSensorVals); //To App
^~~~~~~~~~~~~~~~~
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:62:16: note: suggested alternative: 'Character_h'
bmeCharacteristic.writeValue(sSensorVals); //To App
^~~~~~~~~~~~~~~~~
Character_h
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino: In function 'void loop()':
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:67:16: error: 'BLEDevice' was not declared in this scope
BLEDevice central = BLE.central();
^~~~~~~~~
C:\Users\baran\Downloads\BME_SensorObject\BME_SensorObject.ino:69:20: error: 'central' was not declared in this scope
if (central)
^~~~~~~

exit status 1

Compilation error: stray '\357' in program

It compiles perfectly here, Arduino IDE v1.8.18. If I load it into Ultra Edit, there are no stray invisible characters........

Maybe something happened to it during upload or download. It should only ever be opened in either the Arduino IDE or a plain text editor. Try this attachment:

BME_SensorObject.ino (3.8 KB)

Greetings, Chris

I was still having difficulty with the file you provided but I finally have a functioning pair of sketches. Thank you for all of your valuable input. I will be studying sending multiple floats on a single UUID and other information you provided.
BME_nRF_Good.ino (2.4 KB)
Final.aia (1.0 MB)

The .ala block structure looks like this for anyone else interested:

1 Like

I'm going to move your post to the Help category Baran, as you don't need to hire anyone now.

One thing of interest - are you going to display all 24 values on Screen? If so, a ListView would probably be best. To have two columns and alternately coloured rows would need an HTML ListView, which gets built in real time. When/if you get to that stage, open a new Topic for help.

Does your app continue to receive changing readings after that first read?

Usually I see examples where the Register for ... block is used to set up automatic reception of new incoming data.

OMG . . . nope! I currently have to refresh the app and that is a pain. I will have to research what that looks like, as I am pretty raw with this block programming. Thanks for the heads-up!

OK, I am stumped. Would you be able to show me an example of what you are speaking about. Right now, I have to disconnect and reconnect to refresh the data. Thank you so much.

for the docs.

Still looking for good samples.

If you don't mind rummaging, look in

Basically, it all boils down to doing the register for whatever in the connection completed event, with maybe an extra read thrown in. So you're just a block away.

It is used in the example Project that I posted for you Baran. It permits the streaming of data from the ESP32C3 into the App, without you needing to write your own code to check if data is available.

Register

Good Day, Chris

Well . . . after waking up fresh and having some obligatory coffee, I was able to successfully install both files you availed to me. I though I would start with your example and build from it, as you are sending multiple data points on one UUID and I have a separate UUID for each.

I am hoping you might have a deeper understanding of what is happening here than I. Once I press the scan button and, after scanning, I select the psychrometer from the list of scanned devices. When I press the "Connect" button, two things happen. The first is that the .ino file begins printing data in the serial monitor (good!). The second is that the .aka app takes itself offline every time (bad!).

I downloaded the .aka by scanning the QR code presented in the "Build" section but I am not sure which block of code is creating the disconnect. If you have any idea as to why the .aka app disconnects immediately after establishing a connection with the .ino sketch, I am open to it. There is just too much going on in some of those blocks of yours for me to ascertain the issue and determine the problem. Thank you for your patience with me and my glacial learning curve.