int i = 0;
String Val = "";
while (txt.substring(i,i+4) != NULL)
{
Val = txt.substring(i, i+4);
int test = Val.toInt();
Serial.println(char(test));
i = i + 4;
}
But the problem is, i can get 0050 to 0x0050 and get it to string, but i dont know how to get 010D to this form ... My goal is get String txt to char. Can you help me ?
Don't use the String class (with a capital S). stick to c-strings and the functions from stdlib.h and string.h
how do you get the initial data in your string is the real question and why do you store it this way? ASCII is likely coded on 2 chars like 0xYY where YY is the ASCII Hex representation of the char, not 3 or 4 or whatever - how come do you have 00 in front of some codes? or what is it exactly you have in your String?
Try to avoid the String class and use C strings instead, as suggested earlier. This might help as a starting point:
#define SUBSTRINGSPLIT 4 // Number of chars in a substring
void setup() {
char input[] = "005000720065010D006F00200074006F0020006E0065006601480075006A006701610069006A0065";
char output[sizeof(input) / SUBSTRINGSPLIT + 1]; // Don't forget NULL at end of string
char temp[5];
int length;
int index = 0;
int i;
Serial.begin(9600);
length = strlen(input);
for (i = 0; i < length; i += SUBSTRINGSPLIT, index++) {
strncpy(temp, &input[i], SUBSTRINGSPLIT);
Serial.print(temp);
output[index] = atoi(temp);
Serial.print(" ");
Serial.println((char) output[index]);
}
}
void loop() {
}
come on... that's your representation of the output of your SIM800. The SIM 800 sends you ASCII char, so just bytes. The way you store that is clearly the problem...
show the code you use to read from the SIM800... I suppose you read the data in an int or long and that's what you store in your string in a weird format?
Its normaly SIM.readString();
Im not home, but what i sended here, that’s UCS2 format from parsed readstring ... srsly ... i can give printscreen in 5hrs
I don't need an image/printscreen. We work from code here - that's what your Arduino runs..
Your SIM800 is connected to a serial port, just listen to the serial port to see what's coming
check Serial Input Basics to see how to handle the Serial line correctly
Ok man, so ...
I have configured SIM with AT+CSCS=“UCS2”, because i had to send char like š,č,ž,...
I receive readsting(); in hex like 0050072 - that’s first 2letters from message
lukeesvk:
Ok man, so ...
I have configured SIM with AT+CSCS=“UCS2”, because i had to send char like š,č,ž,...
Ok man
So missed an important info - you don’t have an ASCII communication at all... you changed the char set to UCS2.. so you need a table decoding UCS2 to ascii (UTF-8 might be easier, never tried UCS2)
lukeesvk:
but i cant set communication in UTF-8... there is only available: HEX,BIN,UCS2,GSM,8859-1, but letters which i need support only 8859-1 and UCS2
Thing is, your goal is impossible because a char can't contain a UCS2 because it's 2 bytes long. A char is one byte long. All you can do is convert the hex ASCII to a UCS2 string and store it. That is just a step by step conversion operation.
Of course there is no function. There isn't a standard 8 bit character set that will represent those characters. There could be in theory, but since none exists you would have to implement it yourself.
Yea man ... i don't know that there is no fuction for this ... that's the reason why i'm here ... use logic bro.
Look ... when you don't want help, just don't write, if you want, give me some idea how to make it. Thanks
lukeesvk:
And i want to get from 00500072... normal characters.
Look up the ASCII table. Those are the only characters you can map to. There are 8 bit sets that include 128 extra characters but I doubt that any of them would happen to include all the special ones you are using.
lukeesvk:
Yea man ... i don't know that there is no fuction for this ... that's the reason why i'm here ... use logic bro.
Look ... when you don't want help, just don't write, if you want, give me some idea how to make it. Thanks
I am presenting logic. The only way to do what you ask, is to create a custom 8 bit character set that includes all the characters you want to represent. But now, I have to ask, how would you display them? What do you intend to do with the 8 bit string once you have assembled it? Does it have to be human readable at any future point?
I just want make a normal sentence from that ... I need to get it in normal ascii form and upload it to database.
Ok i'm going to make my own character set
lukeesvk:
I just want make a normal sentence from that ... I need to get it in normal ascii form and upload it to database.
Ok i'm going to make my own character set
What is the point? Why not just store the UCS2 string, as it is standardized and presumably printable by existing systems?
Because its main company ... i need received sms in classic text for employee.
Maybe, its possible to do this transform in C# ? cause im doint this througt webservice.