Text received via bluetooth and compare

I am working on my electronic project which contains an app which receive and transmit bluetooth data.my transmition part is working properly but I am facing problem in receiving section.can any one plz help me to solve the problem.I am sharing the block image of receiving section the global variable used in the codes are already initialised


but not included in the image

Are you setting the DelimiterByte property to 10? Show code from Arduino.

1 Like

I am a beginner in Arduino and mit app inventor.I just made a code to transmit data given in serial monitor of Arduino ide to the hc05.and here is the Arduino code that I am using for testing the app

#include <SoftwareSerial.h>
SoftwareSerial hc05(2, 3);

void setup() {
Serial.begin(9600);
hc05.begin(9600);
}

void loop() {
// Check if data is available from the HC-05 Bluetooth module
if (hc05.available()) {
String receivedData = hc05.readString(); // Read the entire string from Bluetooth
Serial.print(receivedData); // Print the received data to the Serial Monitor
}

// Check if data is available from the Serial Monitor
if (Serial.available()) {
String inputData = Serial.readString(); // Read the entire string from Serial Monitor
hc05.print(inputData); // Send the entire string over Bluetooth
}
}

Dear @EDWIN_JAMES,
as @Patryk_F has already said, your Arduino code is missing the correct string terminator (i.e. the ASCII character "linefeed", 0x0A, or decimal 10). To obtain this your last sending to the app via BT shall be made by using a hc05.println(); and not just with a .print();
You can refer to very detailed instructions by reading the FAQ from @ABG :

Moreover, to be sure that your Arduino is sending data correctly, you could, at the beginning, use a ready made app, like Serial Bluetooth Terminal that you can download free from Google Appstore. Once you are sure that the communication from Arduino to your Android device is working fine, then you can go on with your app. Last, but not least, remember that you shall cross Tx and Rx piins between HC05 and Arduino CPU board.
Best wishes

EDIT here below a super simple example :
BT_to_Arduino.aia (26.3 KB)

BT_Send_Monitor.ino (2.3 KB)

I will change the code in Arduino.Is my app blocks are right.what is your opinion

You have not shown us the place in your app where you set the BlueTooth Client Delimiter to 10.

Also, you do not show in your sketch any code to decide what to send,, other than copying in what comes in from the serial monitor.

I would have expected to see some code that decides to send '1' , '2', ...

1 Like

Dear @EDWIN_JAMES ,
please pay attention to what @ABG has said about the delimiter (i.e. its settings in your app).
Theoretically your blocks seem correct (but to be 100% sure I should have a hardware 100% equal to yours). Anyway, one additional hint is related to the text comparison: typically it's better not to search for an "exact" equality, because a blank (space) or a hidden character can foolish the comparison, but you can just search for a text contained, like in my example in the aia annexed to my previous post.

image

Moreover, to avoid a mismatch due to lowercase or uppercase characters, I do a conversion in uppercase of everything received via BT.

Have you tried my example (annexed aia and ino) ? Or, at least, have you had a look into them ?

1 Like

I don't know about delimiter.I have not added it in my blocks can you please give an block showing that delimiter

Yes I referred you code but not tried it because I only get my lab facility and equipments Monday,Thursday and friday.I will check it today itself thankyou for helping me

The delimiter is normally set directly in the Designer page:
image
(To this purpose I've added the .aia in my previous post)
Anyway if you want to add it as a block, you could use this one in the Screen1 Initailize event.
image
Best wishes.

1 Like

Thankyou i will try it and will share my output soon

1 Like

:+1: take your time :+1:

I made all the corrections.I tested my bluetooth module with smartphone bluetooth serial communication app.I am sharing both screen shot of my Arduino ide serial monitor and app screen here the communication is perfect.I also changed Arduino code (print to println).Then I connected my app with ai companion and tested it with Arduino ide serial monitor.when i click on data transmit buttons data is reaching in monitor.But when I send data to app nothing is happening.I am sharing my app aia file below.plz help me



Smart_Hydrate.aia (476.6 KB) I also changed the delimiter to 10

Connect to the Companion, then apply Do It to see what is in global Data.

That should help see why none of the if/then comparisons are true.

I right clicked on get global data and select do it option then a comment screen poped from there then I send data through Arduino ide serial monitor after connecting it with companion.nothing is showing in it .Is there any problem cause I am minimizing mit app inventor and sending data through Arduino ide then checking it .

Guys finally it's working.I just replaced the "compare texts" block with logic compare block


Thanks for helping me to figure out my problem.I am really happy to being a small part of this helpful community.Once again thanks for everyone

1 Like

Nice to read that you solved (and sorry by having missed your recent posts).
You've solved by using the boolean equality, but my last hint, anyway, is that the next time you want to compare texts, remember to avoid to search the exact equality but to use the "if contains" block (as I said in one of my previous posts).

And by converting in uppercase anything received, you'll be sure that a mismatch caused by upper/lower cases will be avoided.
Best wishes for your next app !

1 Like

Sure . next time I will consider that in my app.Thankyou

1 Like

When using the text CONTAINS test, be careful that you don't get false positives from testing input '12' if it CONTAINS '1'. You will get a true result, but maybe you also intended to test for '12'. Test for '12' first.

The failure of the text COMPARE tests compared to the success of the green '=' tests bothered me.

I suspect there are invisible characters like \r riding along in the input stream that cause the text COMPARE to fail, but are filtered out by the green '=' test in its numeric conversion.

1 Like

Ok👍🏻