I have an App that displays near reatime audio levels in appInventor2 and there
is a data stream coming into the app.
When hit a button a control message is send to the hardware and the hardware returns a packet of data.
the packet somewhere in this stream marked by 4 byte header and 4byte tail for other text data. It’s a list of file names on SD card in my custom hardware.
I can stop the app drawing the incoming audio level data by switching off its clock but the data will still be present since its streaming out over DMA from hardware ( therefore the need to have a packet header and tail ) The packet containing the audio recording names will be of an unknown length so I need to check for the tail. Each filename has a delimiter ‘|’ or 0x7C. I experimented with split message into list at the ‘|’ delimiter with some success.
What’s the best approach for looking for the 4 byte needle in the haystack of bytes and checking for its 4 byte tail ? do I have to load 1 byte at a time from BT ? if so how?
It only needs to scan for the one packet and the other data can be ignored…
It it possible to stop the audio level data stream, but it’s not ideal.
I’d also like to find a way to detect packets so I can have different aspects of the app find relevant data in the one data stream.
If you can post a couple of sample streams, one of my fellow Power Users can show you how best to extract the data you require. Since you mention imposing your own delimiters (’|’, good choice), you could if necessary surround the data of interest with a different character pair.
We basically need to know a lot more about the hardware and the control you have on how the audio data is streamed to advise you.
ABG ! I think it was you that helped get the audio meter levels working !!
by the way , It turned out the glitching I thought existed in the app inventor code was actually drawing non audible noise in the audio tracks So the audio meters work better than my ears !
OK, i’m looking at you code example in app inventor and i’ll try and see how your scanning incoming bytes for a byte pattern
For converting lists of Bytes to text, see the procedures in this project.
(You don’t need the stx and ETX character removal parts.)
Conversion tables are by @Italo. AsciiCHRASCprocedures.aia (4.0 KB)
AI2 value procedures like bytes_to_text are indeed like functions in other languages like C, meant to be reusable with different inputs. You can recognize them by their nipple on the left.
I am suspicious of your global variable names, particularly audioFileNames.
The name implies that it is a list (trailing s in the name), and implies that
each item in that list is an audioFileName. From your incoming bytes stream handling code,
I suspect you need a couple of extra global variables for intermediate values,
like maybe body_bytes for a list of bytes grabbed after the header, and audioFileName
for the text file named value output from a bytes_to_text call against body_bytes, ready for addition to the list audioFileNames.
Notice the difference between audioFileName and audioFileNames, item vs list of items.
Yes , I should build the packet ( the text string of bytes ? )
I called that packet. Then process that with the ‘bytes_to_text’ block
I think I have 2 problems now.
1st is that if I just print all the bytes in the packet I make by using the join block I am getting all the bytes sent from my hardware and there appears to be no filtering of other packets beginning with 88. The packets holding the filename bytes start with 77.
I can see the the correct byte ascii codes for “wav|” arrive this way.
Then if I send these joined bytes in the text variable ‘packet’ to bytes_to_text block I get an error on the app.
I’ll send the screen grab next of the data coming in… not allowed 2 x pics in 1 post!
If you are asking for help, I recommend you to make it as easy for others to be able to help you …
You probably will get more feedback then…
which means in your case post a screenshot of your relevant blocks…
To download the aia file, upload it to App Inventor, open it, do some bug hunting for you, etc… this takes time, and most people will not do that…
Thank you.
Yes agreed, I’m limited to one attachment per post as a new user so forgot to do that.
Can you see anything wrong with the way I’m passing the bytes list ‘packet’ to the TO-RESULT ‘bytes_to_text’ block ? the byte values are ASCII and start with I’d like to just convert them and print them in the app. later I’ll need to split them at ‘|’ into an index-able list.
Also , I’m trying to find a simple way to look for 2 x incoming bytes as a packet header ( id ) I would prefer 3 or 4 byte header to be sure there isn’t by coincidence 2 values the same in the data stream. possible.
My hardware just has one UART IO stream of data ( no BT TCP/IP stack etc ) Its just an HC-06 connected to other hardware.
No, except you could have skipped creating that extra value procedure getAscii and just fed the guts of that procedure into the place you call it. That would have the readability benefit of showing where the Ascii text is coming from.
stream of 8 bytes of audio meter values with 2 bytes 0x08,0x08 header
press button and ascii byte values of 8 bytes with 2 bytes header of 0x07,0x07 header
I’m not sure about how I’m testing getHeaderStart != 0
does a TO-RESULT block return 0 if it has nothing ?