Fonctionnement en maître/esclave dans des picoréseaux de 7 clients (255 en mode parked) pour un maître (et 10 picoréseaux dans la même zone).
Par défaut, sur un pc (et tél. portable ?), il n'est pas possible de chercher un périphérique maître. Il n'est donc pas possible d'apairer le pc et le module en mode master ? Voir par ex. : http://www.elechouse.com/elechouse/index.php?main_page=product_info&cPath=90_91&products_id=602
\r\n+STWMOD=0\r\n | Set device working mode as client (slave). Save and Rest. |
\r\n+STWMOD=1\r\n | Set device working mode as server (master). Save and Rest. |
Note: \r\n is necessary for operation and the value of are 0x0D 0x0A in Hex. \r and \n represent carriage-return and line-feed (or next line).
\r\n+STBD=115200\r\n | Set baudrate 115200. Save and Rest. |
Supported baudrate: 9600, 19200,38400,57600,115200,230400,460800.
\r\n+STNA=abcdefg\r\n | Set device name as “abcdefg”. Save and Rest. |
\r\n+STAUTO=0\r\n | Auto-connect forbidden. Save and Rest. |
\r\n+STAUTO=1\r\n | Permit Auto-connect. Save and Rest. |
\r\n+STOAUT=0\r\n | Forbidden. Save and Rest. |
\r\n+STOAUT=1\r\n | Permit. Save and Rest. |
\r\n +STPIN=2222\r\n | Set pincode “2222”, Save and Rest. |
\r\n+DLPIN\r\n | Delete pincode. Save and Rest. |
\r\n+RTADDR\r\n | Return address of the device. |
\r\n+LOSSRECONN=0\r\n | Forbid auto-reconnecting. |
\r\n+LOSSRECONN=1\r\n | Permit auto-reconnecting. |
a) Master
\r\n+INQ=0\r\n Stop Inquiring
\r\n+INQ=1\r\n Begin/Restart Inquiring
b) Slave
\r\n+INQ=0\r\n Disable been inquired
\r\n+INQ=1\r\n Enable been inquired
When +INQ=1 command is successful, the red and green LEDS blink alternatively.
\r\n+RTINQ=aa,bb,cc,dd,ee,ff;name\r\n Serial Bluetooth device with the address “aa,bb,cc,dd,ee,ff” and the name “name” is inquired
\r\n+CONN=aa,bb,cc,dd,ee,ff\r\n Connect to a device with address of "aa,bb,cc,dd,ee,ff”
\r\n+INPIN\r\n
\r\n+RTPIN=code\r\n
Example: RTPIN=0000 Input PINCODE which is four zero
xx status:
0 - Initializing
1 - Ready
2 - Inquiring
3 - Connecting
4 - Connected
(Note: This is not a command, but the information returned from the module after every command)
Pour communiquer avec le module bluetooth, la librairie SoftwareSerial permet d'initialiser le module, de définir les pins pour l'émission (Tx) et la réception (Rx) et de lire et écrire des données.
#include <SoftwareSerial.h> #define RxD 2 #define TxD 3 SoftwareSerial blueToothSerial(RxD,TxD); void setup() { pinMode(RxD, INPUT); pinMode(TxD, OUTPUT); Serial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400 blueToothSerial.begin(38400); //Set BluetoothBee BaudRate to default baud rate 38400 delay(1000); sendBlueToothCommand("\r\n+STBD=38400\r\n"); sendBlueToothCommand("\r\n+STWMOD=1\r\n"); sendBlueToothCommand("\r\n+STNA=BaseBT\r\n"); sendBlueToothCommand("\r\n +STPIN=0000\r\n"); delay(2000); // This delay is required. sendBlueToothCommand("\r\n+INQ=1\r\n"); delay(2000); // This delay is required. }
Pour communiquer avec un module bluetooth, il faut transmettre les codes pour du retour à la ligne (carriage-return)
et de nouvelle ligne (line-feed) suivit de la commande. La séquence est terminée en envoyant à nouveau \r\n.
Le module renvoit des informations sur son status ainsi que le texte "OK" une fois la commande acceptée et interprétée. Il est nécessaire (?) d'attendre que
le modem termine de traiter une commande avant de passer à la suivante. Pour cette raison, la solution consiste à
attendre la réception du "OK" après l'envoie d'une nouvelle commande.
Algorithme :
Boucler sans fin
Attendre des données sur le canal bluetooth
Lire le caractère reçu
Si le caractère est égal à la lettre 'O', on valide la première étape du test
Si le caractère est égal à la lettre 'K' ET que la première étape du test est validée, on sort de la boucle sans fin
Si le caractère n'est ni 'O' ni 'K', on réinitialise la variable de test
http://www.commentcamarche.net/contents/bluetooth/bluetooth-fonctionnement.php3