Dear friends...i am using the bluetooth module JDY-23 to interface with my nano. I would like to utilize one payliad for every serial.println function so as i can handle much better the data in my app inventor. How i can make it please?
What would you like the payload to look like ?
Have you considered using the sprintf() function to format the data in a buffer before "printing" it to Bluetooth ?
You could send data as App Inventor dictionary of key:value, in order to parse data easily.
I don't remember exactly how a dictionary is structured in App Inventor, but it shiuld be something like this:
[elem1:val1, elem2:val2, elem3:val3 ]
Thanks for your reply. Do you have a short example. I am using this format such as...."I890" or "T2567"
Using sprintf or better snprintf() you can build such a string in a memory buffer and send it over
Strictly speaking yesterday i spent hours and still confused. What block i can use in app inventor to sort data?
That’s an appInventor forum question - not really an arduino or C++ question…
I think to remember there is a capability to parse JSON formats easily
It is not clear who you are replying to
What data are you sending and how many data items are there in an output such as "T2567" and are the quotation marks part of the message ?
Give me a minute, i will try to remind and set up a little example
No the quotation marks are not in data. Just to udentify. I am send data to the mobile app and the letter is identifying teh data. Eg. T45 means temperature is 45 degrees. Etc.
Thanks
If you have the temperature in an int then you can format the output like this
char buffer[10];
int temp = 77;
spnrintf(buffer, 8, "T%d",temp); //format the output in the buffer
//then print the buffer to output the formatted data
Why 8? Usually we would pass the sizeof buffer
That was going to be my question...
This is an example, but off course you need to change the way you send data via BT.
The text in variable myJson is intended as the text received from BT module.
Just an arbitrary value less than the size of the buffer but big enough to hold the data as I did not want to introduce any more complications like sizeof()
The spnrintf() is not showing anything. I am using the hardware serial...
on an 16 bit int platform it would indeed be enough for any value. Largest representation would be -32768 (not sure what's the unit for such a temperature ) so 6 chars plus the leading T and trailing null, so 8 is enough indeed.
we end up with two unnecessary bytes in the buffer though
Please post your full sketch that is not working. snprintf() does not actually print anything, rather it formats the data in a buffer and you print that buffer
But these 2 extra bytes are beyond the terminating zero added by snprintf() so are outside of the string because the size parameter is the maximum number of bytes that will be written to the buffer, not the actual number bytes that will be written to it
The buffer has to be large enough to hold the data and needs to be declared before it is used, so using sizeof() would not actually help. If you are careful and declare the buffer just big enough to hold the formatted data then you might just as well use sprintf() anyway.