how do I get a string from the com port and check it ?
#include <MD5.h> // connect the library
int val =12345; // the variable is equal to five characters 12345
String stringOne, stringTwo; // declaration of 2 lines, to address in any part of the code???
void setup(){
Serial.begin(9600); // enable port monitor, set speed
}
void loop() {
char buff[5]; // char = int val
itoa(val, buff, DEC); // char = int val
unsigned char* hash=MD5::make_hash(buff); // hashing 12345
char *md5str = MD5::make_digest(hash, 16); // hashing 12345
free(hash); // hashing 12345
Serial.println(md5str); // we print the hash 12345 it is equal to = 827ccb0eea8a706c4c34a16891f84e7b
stringTwo = Serial.readString(); // stringTwo must be equal to "827ccb0eea8a706c4c34a16891f84e7b"
Serial.println(stringTwo); // for tracking, you can specify stringTwo = "827ccb0eea8a706c4c34a16891f84e7b"; that's how it works, but you need to read from the port
stringOne = "827ccb0eea8a706c4c34a16891f84e7b"; // line 1 == hash that is needed
if (stringOne == stringTwo) { // compare hashes 1 and 2, and if there are matches // ANALOG if (stringOne.equals(stringTwo)) {
Serial.println(stringOne + " == " + stringTwo); } // print there is a match
}
I do not see an answer there, I tried to rewrite this code many times as indicated in the lessons, but there is no result, this part of the code does not work, stringtwo = Serial.ReadString();
it works stringTwo = "827ccb0eea8a706c4c34a16891f84e7b"; but you need not specify, but read from the com port
first of all post your latest complete sketch. The complete sketch. It doesn't matter if the sketch is 2000 lines long. You can add some hints where you assume where the problem might be.
You can post code by using this method that adds the code-tags
just three steps
press Ctrl-T for autoformatting your code
do a rightclick with the mouse and choose "copy for forum"
paste clipboard into write-window of a posting
If your code does not work there are two ways to analyse the problem:
adding a second serial interface and listening to serial-debug-output with an USB-to-TTL-adapter.
If you just send you could use the standard serial monitor to send and receive the serial debug-output
going up from a small testprogram that simply sends a few characters and print the received characters to the serial-monitor and working up to the complete complexity from there
thank you, you should probably give up string comparison or compare every character, which is inconvenient... and the speed will decrease .. but there is probably no other way
probably the best option of all that I have tried, but unfortunately it prints the hash twice, if you have other options, please show the code, prove the code
I highly recommend as the first step to use a very simple test-code that does just test if serial receiving works at all. No hash-calculation no use of Serial.find().
The reference explains about find() Serial.find() reads data from the serial buffer until the target is found. The function returns true if target is found, false if it times out.
it is very likely that there is happening a timeout everytime.
You should really do a primary test with simply receiving whatever character come in and print the received characters 1:1 to the serial monitor
My five cents:
When you get a string from UART - it will potentially have the NEWLINE (NL) or CARRIAGE RETURN (CR) (when you hit enter to finish the input for the line).
If you compare now two strings - they never match (one has a CR or NL as input string) - the other not. I might never match, except: you limit the number of characters to compare or you remove any unwanted characters you get from UART (such as NL and/or CR).