Help with sending data from the Arduino to AI

Each time I enable the second (it does the same thing if there is only one BT IsConnected and everything is under the first 'if BluetoothClient1.IsConnected' routine also) block that uses 'if BluetoothClient1.IsConnected' and connect to the HC05 Bluetooth module/Arduino, my app freezes.

I'm trying to send something simple, 2 label=value, delimited by a pipe symbol. What am I doing wrong?

currentTimeStamp = millis(); 
    if ((currentTimeStamp - btLastSendTimeStamp) > 2500)
        btLastSendTimeStamp = millis();
        Serial.println("Sending Bluetooth Data");


You are missing a \n in your BT stream, needed for that numberOfBytes=-1.
Use println instead of write.

Also check that your Bluetooth Client Delimiter = 10

Thanks. I do have it configured to 10. I actually got it working about 5 minutes ago by changing that -1 for acall BluetoothClient1.BytesAvailableToReceive .

Is that an effective way, or should I go back to the -1 and use println? What do you suggest? I'm getting random errors in App Inventor, where it appears that App Inventor is receiving sections of bytes at times, rather than a batch of bytes that would equate to the entire stream I want to send, is this related?

You need a message delimiter to help cut them cleanly at end of message.

Otherwise you will lose alignment in the BT buffer.

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