How do you convert numbers as strings?

Hi all.
I try to use: set global totalChunks to join "" (call TextBox.Text get global totalChunks), seems there is not an event to do it? or other solution?

I've tested: join "" + global totalChunks, still got unable to convert error.

that used in the make a list:

Thanks for help.

Could you show us a screen shot of the error message?

This is unexpected.

1 Like

Sure,
attached blocks and aia.
Thanks.

p110i_esp32_ble_3LED_Tim_M2 (2).aia (316.0 KB)

error:
ssss.PNG

You are sending an App Inventor List when a string is expected?

1 Like

Thanks.

I modified as here, still got error:

modified list as string got error:

3322

I take it you are testing with "Start" and "!00" but you are making a List, not a String.

Same everywhere you are sending data via BLE. remove the "make a list" block and only use the text "join" block.

1 Like

The segment error is because you are trying to send 20 bytes of a short chunk.

1 Like

We probably need to see your Sketch/Script if fixing the Blocks does not fix the data send.

1 Like

Thanks.
I just edit the post, here is the removed list by join one.

Thanks.
is that too long? or how to fix it?

... it might be too long for your receiving code but we have not seen it. It is good practice to keep data as short as possible. For example, you are sending the word "CHUNK" to identify a String - use a single character instead, e.g. "C".

Since you are using BLE, it is possible that the BLE data 'parcel' can be increased in size if necessary - default size is only 20bytes.

ProfessorCad: Tips & Tricks Bluetooth

1 Like

You have to take the length of whatever piece of text you have left near the end of the long string you are cutting into chunks, and do the arithmetic to see how long that final fragment is.

The segment block does not suffer impossible requests, so you have to take care to give it actionable parameters.

2 Likes

I've test it.
another error I got when added a clock to:

the puepose is sending the CHUNKS one by one till end with timeInterval 200. the clock should start AfterResizeImage, but the it started as long as APP run and got error:

rruu

are there other ways to send multi CHUNKS ?

Thanks.

Using a Clock Timer to send the next chunk is like using a machine gun to deliver the mail.

A more robust way would be to send one chunk only after receiving word that the previous chunk arrived okay..

There's also the matter of stopping the sends after the last chunk was sent.

Do you disable that Clock?

1 Like

Thanks.
I've test it.
the clock designed as this way, I am not sure if this disabled the clock maybe at the begining or at end:
kkk

If you are sending 20 byte strings, this is the block to use instead of WriteBytes (which wants a list of numbers 0-255):

  • WriteStringsWithResponse – Writes one or more strings to a connected BluetoothLE device and waits for an acknowledgement via the StringsWritten event. Service Unique ID and Characteristic Unique ID are required. The values parameter can either be a single string or a list of values. If utf16 is true, the string(s) will be sent using UTF-16 little endian encoding. If utf16 is false, the string(s) will be sent using UTF-8 encoding.Parameters:
    • serviceUuid (text) — The unique identifier of the service passed in the read or register call.
    • characteristicUuid (text) — The unique identifier of the characteristic in the read or register call.
    • utf16 (boolean) Send the string encoded as UTF-16 little endian (true) or UTF-8 (false) code points.
    • values (list) — A list of values to write to the device.

call BluetoothLE1 WriteStringsWithResponseserviceUuidcharacteristicUuidutf16values

Notice the mention of the event that fires on successful completion of the Write:

  • StringsWritten – The StringsWritten event is run when one or more strings are written to a connected Bluetooth device. stringValues will be a list of values actually written to the device. This may be different if the original input was too long to fit into a single transmission unit (typically 22 bytes).Parameters:
    • serviceUuid (text) — The unique identifier of the service passed in the read or register call.
    • characteristicUuid (text) — The unique identifier of the characteristic in the read or register call.
    • stringValues (list) — A list of values written to the device.

when BluetoothLE1 StringsWritten serviceUuid characteristicUuid stringValues do

This event block is the place where you look to see how far down that long piece of text you have gotten, and to see if there is enough left to send another chunk. You would send that chunk from here, no Clock Timer needed.

After that chunk is sent, the Event would fire again, with either a shorter remaining global text variable or a higher index into the global text value, depending how you choose to manage traversing the long text.

P.S. These block helps are for the CURRENT BLE extension, which is more recent than you have in your posted aia.

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