How do I convert ascii char to a hex that begins with 0x (16based)?
CRLF.aia (5.2 KB)
There is also a way to encode in a blue number value block, though I am too lazy to look for it at the moment.
And this:
https://community.appinventor.mit.edu/t/how-to-convert-binary-data-to-text-and-text-to-binary-data/
I have it done. But now I can nothing do with it. It has to be a number for me... :-
TextToHex.aia (4.9 KB)
I want to send it over BLE, by using write bytes and get it on the other side as hex 0x... Any ideas?
Want to enter text in an app and pop it to arduino or other device as bytes?
Yeah, that's right.
Now I see ABG once posted this.
Hooray, you found it!
So now you know how to send it.
What else is missing, how to convert text to list of Bytes?
But the SendText component converts text to bytes. On the arduino side, do you get it as text? Why do you want to add 0x?
Yes, it works! Only if it is with one of the characters mentioned below. Decimals 0-31 and 127-255 are not in use... At least not on my setup. The extended characters contain more than one byte. For example: Serial.println('é', DEC); is equal to 15712189. Text shows up in the "Arduino Serial Monitor"!
!"#$%&'()*+,-./0123456789:;<=>?@
ABCDEFGHIJKLMNOPQRSTUVWXYZ
[]^_`abcdefghijklmnopqrstuvwxyz{|}~
Send_Text_With_WriteBytes.aia (3.5 KB)
For multi-byte characters, you can split a text string at '' (the empty text block) to get a list of single symbols.
Then you have the challenge of mapping the symbols into sequences of bytes in UTF-8 code and reassembling them at the other end.
P.S. This thread may be relevant.
I am not sure what you mean by that...
For multi-byte characters, you can split a text string at '' (the empty text block) to get a list of single symbols.
I tried this (see picture)... and I get ["a","b"] Nothing new here, except I was sending numbers before.
I don't know if you are something with this?! It is how it is handled it on the other end.
std::string getValue(time_t *timestamp = nullptr);
#define portMUX_FREE_VAL 0xB33FFFFF
Preformatted text
portMUX_TYPE m_valMux;
std::string NimBLECharacteristic::getValue(time_t *timestamp) {
portENTER_CRITICAL(&m_valMux);
std::string retVal = m_value;
if(timestamp != nullptr) {
*timestamp = m_timestamp;
}
portEXIT_CRITICAL(&m_valMux);
return retVal;
} // getValue
/**
* @brief A template to convert the characteristic data to <type\>.
* @tparam T The type to convert the data to.
* @param [in] timestamp A pointer to a time_t struct to store the time the value was read.
* @param [in] skipSizeCheck If true it will skip checking if the data size is less than <tt>sizeof(<type\>)</tt>.
* @return The data converted to <type\> or NULL if skipSizeCheck is false and the data is
* less than <tt>sizeof(<type\>)</tt>.
* @details <b>Use:</b> <tt>getValue<type>(×tamp, skipSizeCheck);</tt>
*/
template<typename T>
T getValue(time_t *timestamp = nullptr, bool skipSizeCheck = false) {
std::string value = getValue();
if(!skipSizeCheck && value.size() < sizeof(T)) return T();
const char *pData = value.data();
return *((T *)pData);
}
I believe it may not be encoded in utf-8 or 16, I had some problems with that before as a string.
These characters are beyond what I can support.
I leave them to you.
That I will do, but how do I send two bytes as one?
I tried to put it in a multiedemensional array but it's not that.
This is serial communication, right?
- send the first byte
- send the second byte
By the way, have you looked at the Web component's Encode and Decode blocks?
They provide a way to encode and decode characters that aren't allowed to appear in URLs.
They might be useful in reducing the space of allowable symbols.
Ok men... Think I got it! I will remember this. Take care.
Thank You ABG so much for idea of putting all characters in one field for solving ASCII issue. Brilliant!