App Inventor unable to display data (string or int) that is read from a BLE sensor device using esp32

The string(received from the esp32) displayed on the app keeps fluctuating between "V" and "U".It should display 2 digit humidity in percentage and 2 digit temperature value with a decimal point of 2. Anyone knows the reason why?

Send the values ​​as a string:
pCharacteristic->setValue(alea.c_str());

2 Likes

Hii. Thank you for the suggestion. I have tried to convert the character buffer (character array) into a string. However, it is still not working. On the display, i could only display the letter A instead of a value. I feel that the problem might lay on the codes on "client" side (the app).

Update: As of now, the app companion is still unable to display the data received through the BLE from the esp32. Even though both timers in the App inventor is working as "Battery Status: connected" and "Sensor Status: connected" could be displayed and sometimes when connected the value displayed becomes the letter A.

Regarding the sending of data from esp32 (Arduino code)

For reading of battery level:

For reading of Sensor Data (humidity reading is of int value which is converted to string) :

App inventor block codes


I am not a BLE expert, but I see two potential problems:

You have a BLE StringsWritten event, but you don't write strings from the app (AFAIK), and you lack the event that receives the Strings requested by the Register For Strings call, the BLE StringsReceived event.

You register for Strings in a Timer event, which is typically a repeating event. But you need to register only once for a data stream, and extra register calls clog memory.

1 Like

@Elaine_Ong

Check this example:

1 Like

Hellooo thanks for the help guys. I managed to receive and display sensor data as well as battery level :smiley: Previously, I have 2 clocks/timers. Removed the timer for the battery service and replace it with a button instead to call for BLE RegisterForShorts instead of ResgisterForInteger.

Here's the updated sensor codes

After testing, I realised a small issue. In my App inventor program, I set blocks to write string to the ESP32. It works, however, it lags a lot. Takes ard 5 to 15 secs for the ESP32 part to respond. Anyone knows the reason why to this issue? and if there is a possible solution to solve it?

Read @ABG's comment on register for Strings in a Timer event.

1 Like

hmm i tried to register for string using a button instead and test it again. The receiving of data is alright. no lag. But when writing to the esp32, the response from the esp32 still lags. I tried to test the program without the ShortsRecieved and StringsRecieved part (receiving of battery level and sensor data), but kept the timer, the repones of the esp32 no longer lags. But when I add those parts back. It lags again. could the lag be cause by me have too many codes/operations on the same screen? :sweat_smile:

Send all variables as String, (battery, temp, humd)

The complete Arduino sketch would be needed along with the complete exported .aia file to answer this.