BluetoothLE 128bytes String

Old extension that sends the long string

new extension not sending correctly

Some odd things there Dave

  1. The two code sets are different - if the earlier version code worked, why have you changed the MTU in the new version? Note that both devices need to be able to handle the larger data stream.

  2. There is apparently nothing in the code that tests the actual string byte size - so the string could exceed 128 bytes.....

The very latest version of the extension is 20201223, but it is awaiting release.

Maybe something will help here.

Hi Dave

What baud rate have you set in the esp32's Sketch? Has anything been changed in the Sketch since your App Inventor BLE Extension upgrade?

Well idd, something strange happened. First the old version didn't send the long string. I update to get rid of that problem and it worked, but now it the opposite. After changing from BLE to NimBLE in the arduino it appeared it didn't work anymore. So I looked what the problem was. It surely not the program from the esp. So I looked in what I changed and I tried the old extension back and it worked. :confused: I checked with two shetches and I get the same input. for me the latest extension is 08-'20 on the link.

I did a look-up first and watched al the topics about it but it didn't work for me. It's not a serial Bluetooth anymore, it is a secure Bluetooth server that I'm working on.

Ater a night... this morning I checked again my latest version in the ais and now it is Extension Version: 20181124 and version 2.0... I'am sure I imported the 08-'20 version. I have it in my downloads and I checked it yesterday.

When I'm now opening my projects I get this.


The two ais files are scrumbled again. And I did make a save before closing down. I have only problems with this ias
https://community.appinventor.mit.edu/t/ble-esp32-bluetooth-send-receive-arduino-ide/1980/3
App send text to ESP32. Show on the Serial Monitor.

You imported a version that does not have the gray blocks. Remove gray blocks or import the latest version.

Thanks for the reply. I know that. I just maked a new project without updating 2 versions up in once, but I still cann't recieve the whole string on the other side without doing an MTU request in the app.

I did an MTU request like this and I'm now recieving

[/very very very very

this instead of

[/very very very ver

It is still not complete

I don't know what I am doing wrong to make the request and the esp is also set to 255bytes.

Try this. You can install it over the latest release you have, but save a backup first!
Note, it's not an official release (but close I think).

edu.mit.appinventor.ble.aix (178.3 KB)

Dear, I tried it but I it still too short. I have made a new project and I recieve this on the other end.

�Starting NimBLE Server
Advertising Started
Connected
Server PassKeyRequest
Starting BLE work!
[This is a long string
Disconnected
Connected
Starting BLE work!
[This is a long string
Disconnected

Ble_23_04_2021.aia (174.5 KB)

I notest that non ble devices that doesn't Advertising are not displaying the devicename right and are not able too connect too the app.

That is to be expected, the only similarity between Classic and Light Edition is the name.

Can you post your Sketch here?

This is the shetch I made. It's not finished, but it suppose to work on a esp32 lua after installing the board. It probebly will work on other boards to.

/*
Name: ESP32_smallBLE_Bluetooth.ino
Created: 4/22/2021 3:25:21 AM
Author: Dave Moon
/
#include <NimBLEDevice.h>
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
#define PASSKEY 123456
NimBLEServer
pServer = NULL;
NimBLECharacteristic* pCharacteristic = NULL;
bool deviceConnected = false;
bool oldDeviceConnected = false;
String StrRecieved;
class MyServerCallbacks : public NimBLEServerCallbacks {
void onConnect(NimBLEServer* pServer) {
deviceConnected = true;
NimBLEDevice::startAdvertising();
Serial.println("Connected");
};
void onDisconnect(NimBLEServer* pServer) {
deviceConnected = false;
NimBLEDevice::startAdvertising();
Serial.println("Disconnected");
}
uint32_t onPassKeyRequest() {
Serial.println("Server PassKeyRequest");
return PASSKEY;
}
bool onConfirmPIN(uint32_t pass_key) {
Serial.print("The passkey YES/NO number: "); Serial.println(pass_key);
return true;
}
void onAuthenticationComplete(ble_gap_conn_desc* desc) {
if (!desc->sec_state.encrypted) {
NimBLEDevice::getServer()->disconnect(desc->conn_handle);
Serial.println("Encrypt connection failed - disconnecting client");
return;
}
Serial.println("Starting BLE work!");
}
};
class CharacteristicCallbacks : public NimBLECharacteristicCallbacks {
void onWrite(NimBLECharacteristic* pCharacteristic) {
std::string value = pCharacteristic->getValue();
Serial.println(pCharacteristic->getValue().c_str());
}
};
void setup() {
Serial.begin(115200);
Serial.println("Starting NimBLE Server");
NimBLEDevice::init("NimBLE-Arduino");
//NimBLEDevice::setMTU(120);//128bytes
/** Optional: set the transmit power, default is 3db /
NimBLEDevice::setPower(ESP_PWR_LVL_P9); /
* +9db /
NimBLEDevice::setSecurityAuth(true, true, true);
NimBLEDevice::setSecurityPasskey(PASSKEY);
NimBLEDevice::setSecurityIOCap(BLE_HS_IO_DISPLAY_ONLY);
pServer = NimBLEDevice::createServer();
pServer->setCallbacks(new MyServerCallbacks());
NimBLEService
pService = pServer->createService(SERVICE_UUID);
NimBLECharacteristic* pCharacteristic = pService->createCharacteristic(CHARACTERISTIC_UUID, NIMBLE_PROPERTY::WRITE | NIMBLE_PROPERTY::WRITE_ENC | NIMBLE_PROPERTY::WRITE_AUTHEN);
pCharacteristic->setCallbacks(new CharacteristicCallbacks());
pService->start();
NimBLEAdvertising* pAdvertising = NimBLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
//pAdvertising->setScanResponse(true);
pAdvertising->start();
Serial.println("Advertising Started");
//Serial.println(NimBLEDevice::getMTU());
}
void loop() {}

Well, the most important part we cannot see, what happens in the loop() to receive strings? However, the Characteristic UUID has not been defined for read, only write?

They are handled in callbacks, and my code calls further on the library. It simular like and interrupt. When something is received it runs it. And yeah it is strange that it is write, I nothest that to. I will test it with read. I let you know.

Nope, it doesn't work at all on read. I have looked in other examples and they do it the same way.

I looked in they documentation and now I understand. It Allows reading and writing values to the characteristic.

I have done it on an a different esp32 and put a delay in the loop to get more breath for the esp. It diden't change the outcome. On which SDK is this extension based?

The extension is opensource. If you know Jave, you can customize them.

Dave, you are very wishy washy with your information. Effectively, you are telling us that all the code is correct on both sides of the equation, but it fails.

If you were me or Patryk, what would you be thinking? Would you think "I need 100% of the info and all the code to see if I can find the problem cause"?

It would be good to know the exact devices involved too. Make, model, BLE version.