Konverzia String-char

Sekcia určená pre Arduino nadšencov

Moderátor: Moderátori

boro
Stály člen
Stály člen
Príspevky: 118
Dátum registrácie: 10 Nov 2010, 00:00
Vek: 80

Konverzia String-char

Príspevok od používateľa boro » 27 Nov 2020, 17:06

Dobrý deň,na internete som našiel program ktorý spĺňa po úprave moje potreby.Odskúšal som ho,všetko fungovalo.Keď som ho upravil,tak som narazil pri inštrukcii:
int a=strcpm("A",answer); na to,že kompilátor vypisuje:
cannot convert 'String' to 'const char*' for argument '2' to 'int strcpm(const char*,const char*)'
Prosím o pomoc akú konverziu urobiť,aby strcpm fungovalo.Podotýkam,že keď tam dám napr.:"A","A" ,tak je to o.k.
Kód Client:
void loop () {
digitalWrite(14,LOW);
client.connect(server, 80); // Connection to the server
digitalWrite(ledPin, LOW); // to show the communication only (inverted logic)
Serial.println(".");
client.println("Hello server! Are you sleeping?\r"); // sends the message to the server
String answer = client.readStringUntil('\r'); // receives the answer from the sever
Serial.println("from server: " + answer);
int a=strcmp ("A", answer );
if (a==0){
digitalWrite(14,HIGH);
delay(1000);
digitalWrite(14,LOW);
}
client.flush();
digitalWrite(ledPin, HIGH);
delay(2000); // client will trigger the communication after two seconds
}
Kód Server:
//SERVER
void loop () {
WiFiClient client = server.available();
if (client) {
if (client.connected()) {
digitalWrite(ledPin, LOW); // to show the communication only (inverted logic)
Serial.println(".");
String request = client.readStringUntil('\r'); // receives the message from the client
Serial.print("From client: "); Serial.println(request);
client.flush();
// client.println("Hi client! No, I am listening.\r"); // sends the answer to the client
client.println( "A\r");
digitalWrite(ledPin, HIGH);
}
client.stop(); // tarminates the connection with the client
}
}
inšrukcia:client.println("Hi client......je pôvodná a ja som ju nahradil s:
client.println("A\r");

Ďakujem za pomoc
boro
Prílohy
Client.txt
(703 Bajtov) 61 stiahnutí
0

Používateľov profilový obrázok
budvar10
Pokročilý člen
Pokročilý člen
Príspevky: 983
Dátum registrácie: 15 Dec 2014, 10:55
Bydlisko: Košice

Re: Konverzia String-char

Príspevok od používateľa budvar10 » 27 Nov 2020, 19:38

Kód: Vybrať všetko

int a=strcmp ("A", answer.c_str() );
0

boro
Stály člen
Stály člen
Príspevky: 118
Dátum registrácie: 10 Nov 2010, 00:00
Vek: 80

Re: Konverzia String-char

Príspevok od používateľa boro » 27 Nov 2020, 21:00

Ďakujem pekne za odpoveď.Už som to aj vyskúšal,heureka ,funguje to.
Ešte raz ďakujem.
boro
0

Napísať odpoveď