Converting 4 bytes to integer

It is correct - it is not the C/C++ String Lib, it is the built-in Arduino String Lib and you can cast an int to a string in that way.....

Yes i understand , but the characteristic is being initialized as IntCharacterisitc so it expects only Int values and thats probably why it gives me compile errors . here : BLEIntCharacteristic ECGchar(CHARACTERISTIC_UUID_TX, BLERead | BLENotify);

There is no String Characteristic in Ble Library , only Char . Thats why i belive it needs a dtostrf conversion but when i try to dtostrf seems i am missing a lib that i cant find .

..... Technically, you don't need to invoke the Characteristic UUID, it's your Hardware communicating with your App. You can generate your own UUID.......

https://www.uuidgenerator.net

1 Like

thats the site i used to generate my Version 4 UUID
for both service and Characteristic uuid , so i dont understand the point here .

Using a generic UUID for characteristics does not tie-in the use of specific data types.

See the links on my site:
https://www.professorcad.co.uk/appinventortips#TipsBluetooth

So this means that with a generic uuid and initializing it as just BLECharacteristic , i can put whatever datatype i like in there , in this case String .
In other examples that i found , they were all using the dtostrf method and char Arrays to send their data though , nobody used Strings

Yes. The point of specific characteristic UUIDs (of which one device can have many) is that they can be effectively anonymous - i.e. a BLE device can find another BLE device and find out, via the advertised characteristics, what it does.

It's worth having a coffee break and reading-up about it. In your case, you are specifying the BLE Phone App and the BLE Device, so you know everything already - you can choose not to use any UUIDs if you do not need the security that a Service UUID brings to the table.

The string Lib was introduced in Arduino v19 - hence most examples predate it. You can of course read the reference on their website.

.... I'm going out in a minute :owl:

i understand what you are trying to say Chris i know i am sending a 4 byte value to my mobile app .
Thats what i managed so far i think the last step is to convert via the APP this 4 bytes to a 32bit integer like the original value it was . Converting it to a string in arduino theoretically would solve the issue but if it can be done in app inventor i ll do it here .

Did it , i was right about the Lib ,so i went back to my esp32 , i transformed the values into a char array and then passed it to phone .

*/
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEClient.h>
#include <BLEUtils.h>
#include <BLE2902.h>



BLECharacteristic *pCharacteristic;
bool deviceConnected = false;
float txValue = 0;
const int readPin = 32; // Use GPIO number. See ESP32 board pinouts



// See the following for generating UUIDs:
// https://www.uuidgenerator.net/

#define SERVICE_UUID           "" // UART service UUID
#define CHARACTERISTIC_UUID_TX ""


class MyServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      deviceConnected = true;
    };

    void onDisconnect(BLEServer* pServer) {
      deviceConnected = false;
    }
};



void setup() {
  Serial.begin(115200);


  // Create the BLE Device
  BLEDevice::init("EcgRose"); // Name of BleDevice

  // Create the BLE Server
  BLEServer *pServer = BLEDevice::createServer();
  pServer->setCallbacks(new MyServerCallbacks());

  // Create the BLE Service
  BLEService *pService = pServer->createService(SERVICE_UUID);

  // Create a BLE Characteristic
  pCharacteristic = pService->createCharacteristic(
                      CHARACTERISTIC_UUID_TX,
                      BLECharacteristic::PROPERTY_READ   |
                      BLECharacteristic::PROPERTY_NOTIFY
                    );
                      
  pCharacteristic->addDescriptor(new BLE2902());


  // Start the service
  pService->start();

  // Start advertising
  pServer->getAdvertising()->start();
  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  BLEDevice::startAdvertising();

  Serial.println("Waiting a client connection to notify...");
  
}


void loop() {
  if (deviceConnected) {
//    SubmitWiFi();
    // Fabricate some arbitrary junk for now...
    txValue = analogRead(readPin) ;
    // Let's convert the value to a char array:
    char txString[8]; // make sure this is big enuffz
    dtostrf(txValue, 1, 2, txString); // float_val, min_width, digits_after_decimal, char_buffer
    
//    pCharacteristic->setValue(&txValue, 1); // To send the integer value
//    pCharacteristic->setValue("Hello!"); // Sending a test message
    pCharacteristic->setValue(txString);
    
    pCharacteristic->notify(); // Send the value to the app!
    Serial.print("*** Sent Value: ");
    Serial.print(txValue);
    Serial.println(" ***");


  delay(1000);
  }
}

Thats the Code , now Label Shows i am receiving number "44.00" and still doesnt upload right to my channel , i need to remove the strings . is there any int x= Integer.ParseInt(ThingspeakList) in app inventor?

So you are now sending a double, as a string, rather than an integer but that part is successful.

Your URL, including the received value, is a string, so why would you need to convert the string (double) value to integer?

i am not i am only trying to remove the " " so it can be read as a normal number and not a string .

You could have said that before.......

Do the quote marks get shown by DoIt also? If so, simply use the "replace all text" function and replace with nothing.

Thats what i was talking bout all this time ,maybe i am really bad at trying to pass my point .
Yes the quote marks get shown in the labels, so it means that the value i pass is still A string .
Point is not to just remove " " from the label Text while the actual value is still a String.
Point is to make the string value an int , so that the text doesnt display " " .
i dont want to just remove " " from the label text just to fool myself.

.... where is that int going?

The cycle of Life of the Integer Value is :stuck_out_tongue:
Arduino Reads an analog Value which is an Integer(fixed the float in the code sketch), it then Transform the int into a char array in order to send it to the phone app > The phone app Takes this array and converts back to the number it was > Then the phone app Sends this number to my Thingspeak Channel.

And how is the number sent to ThingsSpeak?

automatically if the phone has wifi ,or mb , since i am using Web connectivity feature in app inventor and i am giving my channels API which i only have 1 field on purpose