Accept characters from arduino in the app

Hello everyone, I am currently working on a project on Bluetooth.
I can send any text data from the app to the arduino.
But now I need to send data from arduino to the app. I searched the Internet, but I didn't find anything suitable. Please help me?
Code from arduino:

#include <BluetoothSerial.h>
BluetoothSerial SerialBT;
void setup() {
  pinMode(18, INPUT_PULLUP);
  Serial.begin(9600);
  SerialBT.begin("BluetoothExample"); // change to your desired name
}

void loop() {
  if (digitalRead(18) == LOW) {
    function5();
  }
}

void function5() {
  Serial.println("function5");
  delay(1000); // replace with actual task for mode 5
  SerialBT.write((uint8_t) '!'); // send "!" symbol via Bluetooth
}

The algorithm should be like this:
When the button is pressed, Arduino sends the "!" symbol to the application. The application accepts the symbol, and sends the "|" symbol in response after 10 seconds

Can you help please?

See this ABG answer. Also, don't search the entire internet, search this community first, we also have a search engine here.

2 Likes

Thank you, but before I write here I tried to understand it and look for more information. But unfortunately I don't understand a lot of things. I found very relevant information. Please tell me how to find the block “When BluetoothClient.AfterReceive”

Is this correct information?

To receive the character from the Arduino, use the “When BluetoothClient.AfterReceive” block. This block will trigger when the app receives data via Bluetooth. Inside this block, use the “Set Label1.Text to” block to display the received character on the label.

In the Arduino code, use the “SerialBT.write()” function to send the character to the app via Bluetooth. You can send the character when a certain condition is met or when a button is pressed, for example.

I don't know where you got these instructions but they are not correct. Read what ABG wrote.

In arduino use SerialBT.println("!");
In the app, a ReceiveText block with numbersOfBytes set to -1. The BluetoothClient component has a DelimiterByte property, you need to set it to 10.

You need to use a clock component to make the blocks periodically check if a character has been sent to the app. The BluetootClient component does not have an "afterReceive" event block.

1 Like

See this topic:

1 Like

image

Thank you for the information!
Is there a mistake here?
As I understand it, that is, we can't send symbols via Bluetooth, we can only send numbers?

This should work. Also remember to change the code for arduino: println instead of write.
We can send everything via BT. Bytes, characters, text... it's just a matter of what we expect from the app. Do we want to receive text or its byte representations.

Another question of frequency. If the arduino sends quickly, e.g. every 50ms, and the clock in the app is set to e.g. 500ms, the buffer will fill up quickly and the app will show an error. It's best for the app to receive data with a higher frequency than the arduino sends.

1 Like

App sends A. But you didn't show app blocks.

It turns out to be because of the timer.
The character sends within 2 seconds. Solved the problem. Thank you for your support

1 Like

Hi!
The project now accepts symbols well and sends them.
Now I have added a function, that is, if the application receives the symbol "49", then the application goes to the site and finds out the time and uses html to copy the time and paste it to Label2. But something went wrong here. Can you please help?


The "segment text" block receives the value 0 on the "start" input. In the inventory app, start is at least 1, the first character has an index of 1, so "start" cannot be less than 1.

The "start at text" block returns 0 because it did not find the search text.

What should I do to solve this?

Show what you get in "responseContent". Apparently what you're looking for isn't there.

There's nothing there

So you get nothing from your website. Why do you want to read the time from the website and not from the clock component?

Everything seems to be a mistake in this block
A few months ago, everything worked. It seems that the structure of the site where I take information has changed.
Can you please help?
blocks (4)

The authors of the website have introduced protection and send a message:
"Please do not scrape our pages! Thanks!"
Look for a website that has an API to read the time.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.