Created
November 19, 2015 17:11
-
-
Save ZiTAL/3c634d01fe75bc028f44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
#include <Regexp.h> | |
SoftwareSerial BT(7, 8); | |
void setup() | |
{ | |
BT.begin(9600); | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
String s; | |
String b; | |
BT.print("AT"); | |
delay(50); | |
s = SResponse(); | |
b = BTResponse(); | |
/* | |
if(s!="") | |
BT.print(s); | |
if(b!="") | |
Serial.println(b); | |
*/ | |
Serial.println("Command: AT"); | |
if(b==String("OK")) | |
{ | |
BT.print("AT+DISI?"); | |
Serial.println("Command: AT+DISI?"); | |
b = BTResponse(); | |
if(b==String("OK+DISIS")) | |
{ | |
b = BTResponse(); | |
Serial.println(b); | |
} | |
} | |
else | |
{ | |
Serial.println(b); | |
} | |
delay(1000); | |
} | |
String BTResponse() | |
{ | |
String result; | |
if (BT.available()) | |
{ | |
while(BT.available()) | |
{ | |
result += char(BT.read()); | |
} | |
return result; | |
} | |
return ""; | |
} | |
String SResponse() | |
{ | |
String result; | |
if (Serial.available()) | |
{ | |
while(Serial.available()) | |
{ | |
result += char(Serial.read()); | |
} | |
return result; | |
} | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment