Hi,
I'm wondering, is it possible to convert char to unsigned char?
I get a compiling error with this code:
if ( !strcmp(packetBuffer, "%03d")) {
tableID = packetBuffer;
EEPROM.put(address, tableID);
if (EEPROM.commit()) {
Serial.println("EEPROM successfully committed -- TABLE ID is updated");
Udp.beginPacket(Udp.remoteIP(), destinationPort);
String text = "New table ID is: ";
String toSend = text + tableID;
Udp.print(toSend);
Udp.endPacket();
//resetFunc(); ///RESET CODE(!)
} else {
Serial.println("ERROR! EEPROM commit failed");
}
}
in this case 'tableID' is unsigned char and 'packetBuffer' is char.
I'm trying to capture 3 digits from a UDP packet and put them in tableID.
Since I have a lot of code, I don't want to change the types directly, so is there a way to convert it easy?
'packetBuffer' is char.
I hope packetBuffer is a char*.
Post code.
Post error messages.
TheMemberFormerlyKnownAsAWOL:
I hope packetBuffer is a char*.
Post code.
Post error messages.
char packetBuffer[256]; //buffer to hold incoming packet
unsigned char tableID;
It is quite a project, so please find code attached.
This is the compile error:
invalid conversion from 'char*' to 'unsigned char' [-fpermissive]
Terraslampv10.ino (23.4 KB)
gfvalvo
September 29, 2020, 10:36am
4
Post the COMPLETE error message.
gfvalvo:
Post the COMPLETE error message.
Find attached ( to long to share directly )
errorMsg.txt (73.7 KB)
gfvalvo
September 29, 2020, 10:57am
6
Since 'packetBuffer' is an array of char, it's name is essentially a pointer to a char (aka char *). This:
tableID = (unsigned char)packetBuffer;
is an error since you can't cast a pointer to an (unsigned char).
gfvalvo:
Since 'packetBuffer' is an array of char, it's name is essentially a pointer to a char (aka char *). This:
tableID = (unsigned char)packetBuffer;
is an error since you can't cast a pointer to an (unsigned char).
I've also tried simply tableID = packetBuffer;
like I've shown in my first post, which also did not succeed.
Is there someway possible to assign the incoming packet to 'tableID' ?
gfvalvo
September 29, 2020, 11:21am
8
packetBuffer is an array that can contain as many as 256 characters (255 if it's a null-terminated c-string):
char packetBuffer[256];
tableID is an unsigned char:
unsigned char tableID;
That means it can only hold one byte (eight bits) of data. So, it can't possibly hold the contents of packetBuffer.