Getting App Inventor to work with BLE and Seeeduino ESP32C3

Hi, Chris

I seem to be getting further and further away. While the first BME_SensorObject file uploaded, this .ino file gives the following error messages:

C:\Users\baran\Downloads\BME_SensorObject2\BME_SensorObject2.ino: In function 'void updateValues()':
C:\Users\baran\Downloads\BME_SensorObject2\BME_SensorObject2.ino:69:24: error: cannot convert 'char*' to 'double'
dtostrf(sTemperature,8,2,Temperature);
^~~~~~~~~~~~
In file included from C:\Users\baran\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32/Arduino.h:40,
from C:\Users\baran\AppData\Local\Temp\arduino\sketches\87EF2D283F16D9ED935333F8DDBBE296\sketch\BME_SensorObject2.ino.cpp:1:
C:\Users\baran\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32/stdlib_noniso.h:46:23: note: initializing argument 1 of 'char* dtostrf(double, int, unsigned int, char*)'
char* dtostrf (double val, signed int width, unsigned int prec, char s);
~~~~~^
C:\Users\baran\Downloads\BME_SensorObject2\BME_SensorObject2.ino:70:24: error: cannot convert 'char
' to 'double'
dtostrf(sHumidity,8,2,Humidity);
^~~~~~~~~
In file included from C:\Users\baran\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32/Arduino.h:40,
from C:\Users\baran\AppData\Local\Temp\arduino\sketches\87EF2D283F16D9ED935333F8DDBBE296\sketch\BME_SensorObject2.ino.cpp:1:
C:\Users\baran\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32/stdlib_noniso.h:46:23: note: initializing argument 1 of 'char* dtostrf(double, int, unsigned int, char*)'
char* dtostrf (double val, signed int width, unsigned int prec, char s);
~~~~~^
C:\Users\baran\Downloads\BME_SensorObject2\BME_SensorObject2.ino:71:24: error: cannot convert 'char
' to 'double'
dtostrf(sPressure,8,2,Pressure);
^~~~~~~~~
In file included from C:\Users\baran\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32/Arduino.h:40,
from C:\Users\baran\AppData\Local\Temp\arduino\sketches\87EF2D283F16D9ED935333F8DDBBE296\sketch\BME_SensorObject2.ino.cpp:1:
C:\Users\baran\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.16\cores\esp32/stdlib_noniso.h:46:23: note: initializing argument 1 of 'char* dtostrf(double, int, unsigned int, char*)'
char* dtostrf (double val, signed int width, unsigned int prec, char *s);
~~~~~^

exit status 1

Compilation error: cannot convert 'char*' to 'double'

I guess I could just fall back onto the 0x181A series of environmental codes (0x2A6D, 0x2A6E, and 0x2A6F) for pressure, temperature, and humidity respectively, and calculate everything else on the app side. Of course, if I go the calc on the app route, I would be just as happy using the clocked (3) characteristics app that you modified for me.

Regarding the psychrometer app, it shuts down pretty much as soon as I press the connect button. I press connect, the serial monitor starts generating data, and the app disconnects.

Hi Baran

That was a bug in the first upload of the Sketch, as per my edit note! The note says:

EDIT: This is the second upload of BME_SensorObject2.ino, delete the first upload if you have downloaded it.

...and the log file says the App is connected, so the issue is it is not receiving data or receiving something unexpected that causes a crash - that is what the two file 2's are looking at :innocent:

I think you might be juxtaposing .ala files? I am attaching two .ala files. The one called Psychrometer2 from last night has the same error as the original. It also shows the .txt file and does not find the psychrometer, much less connect.
The other .ala is the one you sent a while back that does not disconnect but goes to a blank screen that eventually times out.

BME_SensorObject2.ino (4.2 KB)

BME_SensorObject.ino (4.0 KB)

The following .ala does connect with the BME_SensorObject but leads to the blank screen previously described.

Psychrometer_2.aia (246.2 KB)

I cannot think of anything else to report. The .ala you sent last night would not connect (it wouldn't even find the psychrometer).

So far, the only set of sketches (.ino and .apk) that don't fight and seem to want to connect are the BME_SensorObject.ino and the Psychrometer2_apk, as built from the Psychrometer_2.ala.

If this is becoming tedious for you, I understand and I will allow you to attend to some other events in your life besides my two poor sketches. It is just that I am flying blindly on your knowledge and experience without the ability to contribute much except sketch evaluation. I really appreciate your help but I don't want you burning out on me.

If we (and by we, I mean you;) are done with this, I can always go back to the three UUID characteristic .ala and do my calculations in the app. It would be crowded, but functional.

Hi Baran - and there I was trying to reduce confusion :joy:

The point about project files for Bluetooth communication is that they must be matched - each is dependent on the other.

I'm going to send a new pair of files to you tonight. They are designed to work only together, they shouldn't be changed or replaced. They should represent a "clean slate", just report back on those with the built-in log file, don't try to change anything.

Thank you so much, Chris. I won't change a thing. I certainly appreciate your time and energy helping me here. I take some home-cooked food on my e-bike, once a day, to an 83-year-old woman who broke her hip a year ago May and has been bedridden ever since. I just can't imagine being there all alone, so I have been "paying it forward," so to speak, for a year now. I feel as though you are creating a surplus of credit on your "Master" card by helping me, and others, here and I am grateful for your knowledge and perseverance helping me to achieve my objective..

.... it's why the "Power Users" are here - we enjoy helping and we enjoy the challenge.

Hi Baran.

The two attached files have been modified to be more robust. The .aia (App as an APK) runs well on Android 12. The .ino (Sketch) fully compiles without error. However if there are issues, post the data from the Arduino Serial Monitor and the log file (/Documents/PsychrometerBLE_01.txt) from the App here for me to study.

The App does a bit more of the work, for example checking the phone's Bluetooth. It also prevents the use of a button if the process is not ready, for example if connection has failed, the disconnect button is not enabled. When closing the App, always use the red button as it performs a vital cleanup.

PsychrometerBLE_01.aia (223.2 KB)

PsychrometerBLE_01.ino (4 KB)

Hi Chris,

I really appreciate all of the time you have put into this, but the results are the same with different sketches. The .ala does fine up to finding the .ino sketch. Both times that the Serial Monitor began recording data, I had hit the "Connect" button on the .ala app but as you can see, the app quits (and disconnects).

I don't know if I am beating a dead horse here. You speak of connecting with strings instead of individual characteristics but can the core structure of the attached .ino and .aka files be modified for strings, instead of characteristics? The attached pair of files do connect and update regularly (since you added a clock block . . OK, timer module;)-.

I looked over the mathematics blocks and they seem quite complete - enough to replicate my formulas on the device side without having to transmit multiple stringy things. I am thinking of providing a list of the calculated aspects, each a label in a switch that calls up the particular calculated aspect (density, pressure, enthalpy, etc.) or allows the desired functions to be ticked and recorded at a desired interval.

Anyway, I seek your expert advice, here. If sending multiple data via strings is more efficient, or if you have a never-say-die attitude, I am here for the duration. If you are tired/frustrated/ready to move on, I am game with that, as the attached file set works like a charm with three characteristics.

Again, thank you for your time and mentoring. I am attaching all requested files, except for /Documents/PsychrometerBLE_01.txt which was never created. There is only a txt file from four days ago.

This_Sketch_Connects.aia (995.3 KB)

BME280_All_3_Functions.ino (2.4 KB)

Hi Baran

Do you mean how quickly the connection to central is lost? That is not the App failing, it's a hardware failure - but I don't know why or what.

/Documents/PsychrometerBLE_01.txt should be there though, thoroughly tested here on Android 12. Note that for some strange reason it takes a bit of time for Android to present small files like that, which is why I gave the Google Play link for File Manager Plus, which is better than the default Android file manager :slight_smile:

Still, the Android Serial Monitor is seeing sensor results. I will update the Sketch to show us what it is really trying to send to the App, since if the format is incorrect or packet too large, that would be an issue.

BLE categorises data with it's characteristics system, so no matter what type of data you have, it has a characteristic.

So are you saying the App receives regular updates of the 3 values and on the ESP the central does not disconnect itself after a short while?

It's me again, determined to make your hair more grey than mine.

Awaiting your answer to:

Given that the App (.aia) is waiting for strings and the Sketch (.ino) is sending floats, data should not be arriving in the App........

I noticed a strange thing in the results on the Arduino Serial Monitor you have screen capped - the values are to two decimal places.

Hi, Chris

Yep, that's exactly what I am saying. I am attaching three screenshots from the outputs. The data updates every two seconds. If I cover the BME280 with my finger, the temp immediately rises. Are you saying that the following .ino lines:

#define BLE_NAME "Psychrometer"

#define SERVICE_UUID "19B10000-E8F2-537E-4F6C-D104768A1214"

#define TEMPERATURE_UUID "19B10001-E8F2-537E-4F6C-D104768A1214"

#define HUMIDITY_UUID "19B10002-E8F2-537E-4F6C-D104768A1214"

#define PRESSURE_UUID "19B10003-E8F2-537E-4F6C-D104768A1214"

// Create BME280 sensor object

Adafruit_BME280 bme;

BLEService bmeService(SERVICE_UUID);

BLEFloatCharacteristic temperatureCharacteristic(TEMPERATURE_UUID, BLERead | BLENotify);

BLEFloatCharacteristic humidityCharacteristic(HUMIDITY_UUID, BLERead | BLENotify);

BLEFloatCharacteristic pressureCharacteristic(PRESSURE_UUID, BLERead | BLENotify);

Should not work with these .ala lines?:

It seems like they are all UUIDs and Floats on both sides?

BTW, here are those output screenshots . . .



:upside_down_face: The aia you uploaded "This_Sketch_Connects.aia" is using Strings Received, which would not work but your Screenshot is using Floats Received, which should work.

Hi Baran

The main interest in using strings:

  1. Send only one or two packets of data at a time
  2. App can check that all values have arrived before processing
  3. Only one or two Characteristics need to be verified by the App

However, if you are totally happy with what you are getting using floats, persevere. If you hit an issue later you can always ask us for help (except concerning your hair going grey).

Too late for the hair, my friend;)-. White as #FFFFFF - I skipped gray!

I am playing with adding pages, making buttons that work and align, etc. I received the following error line when trying to build the app:

ERROR: appinventor/ai_reddingsun/June_6_D_copy/Screen1.yail line 27: call to 'set-and-coerce-property!' has too few arguments (3; must be 4)

OK, somewhere, it wants 3 selections, not 4. But where? Line 27 means nothing to me . . . how do I even locate a line number? Some Internet answers said it was do to an open socket in the blocks section but I already had a couple of open sockets like "When LocaionSensor1. LocationChanged," the "do" socket is empty but it always has been.

OK, I typed a whole bunch of stuff. If I had to condense it to a simple question, it would be "How do I find line 27?"

Use the yellow error arrows in the Blocks Editor and fill those empty sockets.

1 Like

Genius! I always wondered about those arrows but I couldn't figure them out. A couple of questions, if you have the chance.

  1. How can I change the name and icon in the installation screen? I cannot trace that information to any block.

  2. If the first screen is always named "Screen1," what happens when I copy all of the blocks of one .ala and try to insert them in an empty page on another app using the backpack? I never seem to get out what I put in and it is always in shambles. Is there a more/better method of doing this?

I am starting to get a grasp on navigation and assigning pages to buttons. My thought is to have four primary pages, each with their own specifically-related data. This gives a clean 6 outputs per page. At some point, I will want to data-log the information every X minutes but that is still a ways off.

Thanks, again, for your ongoing support. I am beginning to feel less fearful of this architecture;).

1 Like

Canned Response ABG - Project Properties

Project Properties
Project Properties2

..

Thank you! After I learned to click and not try to "drag" blocks out of the backpack, things got much better. I found that the blocks program, with its red X's, guided me perfectly to each error which I only had to click and update to make functional.

1 Like