My app crashes when i use Register.integers block in ble

I am making a device in which when the button connected to an Arduino chip is pressed, a message is sent to a person with a custom message and my current location. As I use the register block, my app crashes as I connect with my chip.
I am a beginner with app development, so it would be great if anyone can help me out of this.

Here is the arduino code -
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

BLECharacteristic *pCharacteristic;
bool deviceConnected = false;
const int tactilePin = D1; // Pin connected to tactile sensor

void setup() {
Serial.begin(9600);
pinMode(tactilePin, INPUT);

// Initialize BLE
BLEDevice::init("Tactile Sensor");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService("12345678-1234-1234-1234-123456789abc");
pCharacteristic = pService->createCharacteristic(
"87654321-4321-4321-4321-123456789abc",
BLECharacteristic::PROPERTY_NOTIFY |
BLECharacteristic::PROPERTY_READ
);

pCharacteristic->addDescriptor(new BLE2902()); // Required for notifications
pService->start(); // Start the BLE service

BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID("12345678-1234-1234-1234-123456789abc");
pAdvertising->start();
}

void loop() {
int sensorState = digitalRead(tactilePin);
if (sensorState == HIGH) {
pCharacteristic->setValue("1");
pCharacteristic->notify();
delay(500); // Add debounce delay
}
}

Also post your Arduino code, as well as the version of the BLE extension you are using.

Hello Yash

Credit to you for your effort. As a beginner, part of the problem is you have "bitten off more than you can chew" - in other words, you have not built some simple, tiny Projects first to get an understanding of App Inventor, BLE and Arduino.

It's so difficult to help you because your block code has a lot of errors. We haven't even seen your script (Arduino Sketch) yet :upside_down_face:

However, right at the top of the pile of questions is this: What is the purpose of your App? Is it just to learn more about coding Apps + Hardware or do you want it to be viable, something to at least share with friends and family? I ask because BLE (and Classic Bluetooth) has very limited range - maximum is about 100 metres in a perfect environment. Even at max range, you wouldn't need to send a message to anyone - they will probably see where you are....or perhaps you are riding a bike or driving car or something, the Arduino is an attachment to the vehicle, so you will be close to it, your phone receives the data via BLE and sends an SMS message (not a message via BLE). Yes, that's it?

By the way, your Blocks are reading Bytes, not Integers, but in this scenario text (C String) or Float would be the types to use - depending on the location data i.e. if it is just floats or it's float values embellished with characters..Lat1234.56333 Lng4321.65444

... you will only need to use "When Strings Received" once you have registered a type. Using "Read" is not necessary.

I am using BLE 20240822 version

The purpose of the app is to be an sos message sending app, such that when someone clicks the button on arduino chip, 1 person get the sos message with the location co-ordinates. I have tried using every register block but it always crashes, no matter which one I use.

You can do that with the App alone, you don't need the Arduino......

A post was split to a new topic: My app won't load

Agreed, but i am making a hardware device such that when button is pushed physically, a distress signal is sent

Try removing the ReadIntegers block from the Connected event.

Look in the Play Store for a BLE app like nrfConnect, that you can use to verify your sketch is transmitting without using an AI2 app.

1 Like