-
Notifications
You must be signed in to change notification settings - Fork 1
/
BLE-HJ-580XP_jul07a.ino
98 lines (74 loc) · 1.46 KB
/
BLE-HJ-580XP_jul07a.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <SoftwareSerial.h>
#define CONFIG 7
#define RX 11
#define TX 10
SoftwareSerial ble(TX, RX);
void setConfigMode(bool mode) {
digitalWrite(CONFIG, mode ? LOW : HIGH);
delay(100);
}
void setup() {
Serial.begin(19200);
ble .begin(19200);
while (!Serial);
while ( !ble ) ;
pinMode(CONFIG, OUTPUT);
Serial.println();
setConfigMode(1); // - [AT Config.]
SEND_COMMANDS( ); // - [AT Commands.]
setConfigMode(0); // - [UART Config.]
//ble.setConfigMode(1);
delay(2000);
}
String tmp;
void loop() {
manageBLE_SerialData();
//hmm.. #0
while (Serial.available() > 0) {
tmp += char(Serial.read());
delay(2);
}
if(tmp.length() > 0) {
Serial.print((String) "SENT: " + tmp + "\n");
ble.print(tmp);
tmp = "";
}
}
const String ATcommands[] = {
"NAMEIG: @giorgos.xou",
"MNAME","SVER",
"HVER","AGAP",
"MINCGAP",
"CTIMEOUT",
"STATE",
"ROLETYPE",
"RESET"
};
void SEND_COMMANDS(){
for(int i; i<10; i++){
ble.print((String)"<" + ATcommands[i] + ">");
delay(777);
manageBLE_SerialData();
}
}
void manageBLE_SerialData()
{
while (ble.available() > 0) {
tmp += char(ble.read());
delay(2);
}
if(tmp.length() > 0) {
Serial.print("RECEIVED: ");
Serial.println(tmp);
tmp = "";
}
}
/* #0
if (Serial.available()) {
tmp = Serial.readString();
Serial.print((String) "SENT: " + tmp + "\n");
ble.print(tmp);
tmp = "";
}
* /
*/