3 weeks ago when i done my training project based on mit app inventor and completed it but for 1.5 weeks my colleague and myself found not connected when in list picker i select the correct bluetooth address and after few seconds the mit compasion forced closed in all andriod, but in another apps like serial bluetooth terminal it works perfectly. so my module is working and codes are working but now the mit app inventor not working my training is freezed because this.
This might be from loss of permission, or a stale Companion app.
I have done everything checking in alternative phones too and the permission reseted also, but not working.
Export the .aia file and post it here.
Also, get the .ino source file and post that here.
https://community.appinventor.mit.edu/uploads/short-url/bUxIEACrytHQHd4EI7yakNpzECC.ino
https://community.appinventor.mit.edu/uploads/short-url/3HsGqibIjsFtxMjIIYnG6bzp5GC.aia
What version of the Companion do you have?
Reviewing your .ino:
char value = 0;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
value = Serial.read();
if (value == '1') { // '1' is the ASCII value of 49
digitalWrite(13, HIGH);
}
else if (value == '0') { // '0' is the ASCII value of 48
digitalWrite(13, LOW);
}
/*else {
digitalWrite(13, HIGH);
delay(100);
digitalWrite(13, LOW);
delay(50);
}*/
}
}
Your blocks:
Your Designer:
I see you also included the BlueTooth Server component.
That's not needed for this type of project.
2.72 mit ai2 compansion andriod
yes sir bluetoothh server is not needed and my colleague have not used it and not working
anyway in my block diagram i have not used it sir so i think it would not be a problem
and this was working 3 weeks ago!!!
Losing permission can happen over time.
If you use the Companion and don't build a. .APK you can fall behind the AI2 server.
(Canned Response ABG - Bluetooth non-BLE SCAN Permission Blocks)
The easiest solution, for immediate relief
(from @Barry_Meaker) ...
I had the same issue. The problem is your app does not have permission to see nearby devices. The solution is to give your app permission on your phone (no code changes in your app).
on your phone,
- goto settings
- search for your app
- in App Info for your app select Permissions
- change Nearby Devices from Not Allowed to Allowed
- Done
By the way, the very first time you run the app, Android will ask if you want to grant the app this permission. If you say no, or ignore the pop-up, the permission will be set as Denied. Android will not ask again.
A more complex approach, for professional app development:
See Bluetooth liste of devices deosn't work anymore - #7 by Anke
Special note for Xiaomi devices:
I have an error with bluetooth on android 12, Xiaomi Poco X3 NFC - #20 by Patryk_F
Check your version
Dear @VIKNESSHWAR_A_B,
@Abg has already told you about permissions and could still be the root cause.
Anyway, here below you can find an Arduino code working for me.
Annexed you can find also a revised version of your .aia .
Both are working together: the .aia, compiled to an .apk and downloaded onto my Lenovo Pad (Android 10), while the Arduino is running on a Mega2560 connected to an HC05 (whose baudrate is 115200 bps). If your HC05 works @9600, you have obviously to change the 115200 value to 9600 (please be aware that sometimes some HC05's have a factory set default baudrate @38400).
My HC05 is connected to pins 0, 1 of my Mega. The pin 0 (Mega Rx pin, is connected to the Tx pin of the HC05, while pin 1, the Tx Mega pin, is connected to the Rx pin of the HC05 by means of a resistors partition, as per the design here below:
And now the Arduino code:
#define LED 13
void setup()
{
Serial.begin(115200); // towards HC05 (mine works at that baudrate)
pinMode(LED, OUTPUT); // LED on board
digitalWrite(LED,LOW); // self test of LED
delay(1000);
digitalWrite(LED,HIGH);
delay(1000);
digitalWrite(LED,LOW);
}
void loop()
{
char Char_In;
if (Serial.available() > 0) // something from APP ?
{
while (Serial.available()) // repeat fetch input char until available
{
Char_In = Serial.read(); // get it
if(Char_In == '1') digitalWrite(LED,HIGH); // set LED on if character received = 1
if(Char_In == '0') digitalWrite(LED,LOW); // set LED to OFF if character received = 0
delay(1); // wait a while
}
}
}
BLUETOOTH_LED.aia (71.5 KB)
The app's blocks (contained in the above.aia) are shown here below:
You'll see that the Screen1.initialize has a commented block (the bluetooth ask for permission. The first time that I run the app on my Lenovo pad, the presence of the two blocks "ask for permission" produce an enquiry by Android, that asks the user to enable, in the Android device settings, the BT comm's and the "fine location". Once given this authorization to the app, it isn't necessary any longer to ask for the same permission: to this purpose I've commented out the relevant block.
Best wishes