Hi everyone !
I fixed it (with the huge help of a coworker) !
By analising the string received from my browser, I found that, at the end, there were no '\0' but a '\r\n' instead. (I didn't tested on the UNO Wifi but I guess the function BridgeClient::readString() of Arduino Yun is different from the one for UnoWifi.
| 0 | | | 1 | | | 2 | | | 3 | | | 4 | | | 5 | | | 6 | | | 7 | | | 8 | | | 9 | | | 10 | | | 11 | | | 12 |
| - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - | - |
| 0x63 | | | 0x6F | | | 0x6D | | | 0x6D | | | 0x75 | | | 0x74 | | | 0x61 | | | 0x74 | | | 0x69 | | | 0x6F | | | 0x6E | | | 0x0D | | | 0x0A |
| 'c' | | | 'o' | | | 'm' | | | 'm' | | | 'u' | | | 't' | | | 'a' | | | 't' | | | 'i' | | | 'o' | | | 'n' | | | '\r' | | | '\n' |
So here is my new code for Yùn:
void wf_getd(){
String d = Client.readStringUntil('\r');
/*Serial.println(d); //DEBUG
Serial.println(d.length());
char temp[16];
d.getBytes(temp,sizeof(temp));
int lop;
for(lop=0;lop<16;lop++){
Serial.print(lop);
Serial.print(" ");
Serial.println(temp[lop],HEX);
}*/
if(d == "state"){
wf_state();
}
else if(d == "current"){
wf_current();
}
else{
//Serial.println(F("error wf_getd"));
wf_error();
}
}
void wf_process(){
Client = Wifi.accept();
while(Client.available()){
if (Client.readStringUntil('/') == "mode")
wf_switch();
else
Serial.println(F("command not found (process)"));//wf_error();
}
Client.stop();
}
void wf_switch(){
String command = Client.readStringUntil('/');
char temp[16];
command.getBytes(temp,sizeof(temp));
int lop;
for(lop=0;lop<16;lop++){
Serial.print(lop);
Serial.print(" ");
Serial.println(temp[lop],HEX);
}
Serial.print(F("Commande : "));
//Serial.print(command);
if (command == "commutation\r\n"){
wf_commutation();
}
else if (command == "get"){
wf_getd();
}
else {
wf_error();
Serial.println(F("error wf_switch"));
}
}