Communication entre Android et Arduino
Bonjour tout le monde,
Je suis en train d'essayer une application à base de l'échantillon Bluetoothchat du SDK, et qui fait échanger des chaines de caractères entres un téléphone android et une arduino.
Ma question est comment s'assurer que la chaine est bien reçue de l'autre coté?
J'ai fait envoyer "OK" par Arduino après la réception d'une chaine:
Code:
1 2 3 4 5 6
| void loop() {
if (bluetooth.available() > 0) {
chaine_recue=bluetooth.read();
bluetooth.print("OK");
}
} |
Et coté android j'ai fait un test si "OK" est envoyé par arduino:
Code:
1 2 3 4
| String ack = ""; //global var
bt.send("test string"); //envoyer vers arduino
SystemClock.sleep(100); //wait
if(ack.equals("OK")) txtvw.setText("bien reçu!!); |
et qqs part dans un handler:
Code:
1 2 3 4
| if(msg.what == Bluetooth.MESSAGE_READ){
String receivedstring = new String((byte[]) msg.obj, 0, msg.arg1);
ack= receivedstring;
} |
Mais hélas, ça marche PAS !!
Je vous remercie d'avance pour votre aide.