Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Open-Cube FW
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Open Cube
Open-Cube FW
Commits
b3cbc47c
Commit
b3cbc47c
authored
1 year ago
by
Václav Jelínek
Browse files
Options
Downloads
Patches
Plain Diff
Improve ESP command responsivness and add working turnable WiFi AP server
parent
0b4fbbe2
No related branches found
Branches containing commit
No related tags found
1 merge request
!7
Merge old hardware code with new hardware code
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
ESP/uart/uart.ino
+44
-26
44 additions, 26 deletions
ESP/uart/uart.ino
lib/cube/esp_config.py
+7
-6
7 additions, 6 deletions
lib/cube/esp_config.py
main/main.py
+2
-2
2 additions, 2 deletions
main/main.py
with
53 additions
and
34 deletions
ESP/uart/uart.ino
+
44
−
26
View file @
b3cbc47c
...
...
@@ -44,9 +44,11 @@ WiFiServer server(80);
WiFiClient
client
;
char
default_name
[]
=
"OPEN-CUBE"
;
char
default_pass
[]
=
"12345678"
;
uint8_t
message_rx
[
MAX_PAYLOAD
+
3
];
uint8_t
message_tx
[
MAX_PAYLOAD
+
3
];
char
esp_name
[
MAX_PAYLOAD
];
char
esp_pass
[
MAX_PAYLOAD
];
int
message_idx
=
0
;
uint8_t
ch
;
int
cmd_pin
=
0
;
...
...
@@ -181,16 +183,22 @@ void html () {
client
.
println
(
"</body>"
);
client
.
println
(
"</html>"
);
}
void
esp_cmd_change
()
{
cmd_pin
=
digitalRead
(
CMD_PIN
);
digitalWrite
(
LED_PIN
,
cmd_pin
);
}
void
setup
()
{
Serial
.
begin
(
115200
);
pinMode
(
CMD_PIN
,
INPUT
);
pinMode
(
LED_PIN
,
OUTPUT
);
cmd_pin
=
digitalRead
(
CMD_PIN
);
cmd_pin_prev
=
cmd_pin
;
//SerialBT.setPin(pin);
memset
(
esp_name
,
'\0'
,
sizeof
(
esp_name
));
memcpy
(
esp_name
,
&
default_name
,
9
);
memset
(
esp_pass
,
'\0'
,
sizeof
(
esp_pass
));
memcpy
(
esp_pass
,
&
default_pass
,
8
);
SerialBT
.
enableSSP
();
SerialBT
.
onConfirmRequest
(
BTConfirmRequestCallback
);
SerialBT
.
onAuthComplete
(
BTAuthCompleteCallback
);
...
...
@@ -199,11 +207,12 @@ void setup() {
dir
=
STOP
;
counter
=
0
;
attachInterrupt
(
digitalPinToInterrupt
(
CMD_PIN
),
esp_cmd_change
,
CHANGE
);
}
void
loop
()
{
cmd_pin
=
digitalRead
(
CMD_PIN
);
digitalWrite
(
LED_PIN
,
cmd_pin
);
//
cmd_pin = digitalRead(CMD_PIN);
//
digitalWrite(LED_PIN, cmd_pin);
if
(
cmd_pin
&&
cmd_pin_prev
==
0
)
{
send_short_cmd
(
COM_ACK
);
message_idx
=
0
;
...
...
@@ -235,23 +244,29 @@ void loop() {
memset
(
esp_name
,
'\0'
,
sizeof
(
esp_name
));
memcpy
(
esp_name
,
&
message_rx
[
2
],
message_rx
[
1
]);
if
(
bt_on
)
{
SerialBT
.
end
();
SerialBT
.
begin
(
esp_name
);
//Bluetooth device name
}
else
{
server
.
end
();
WiFi
.
softAP
(
esp_name
,
"12345678"
);
server
.
begin
();
WiFi
.
softAP
(
esp_name
,
esp_pass
);
}
break
;
case
COM_PASSWORD
:
send_short_cmd
(
COM_ACK
);
memset
(
esp_pass
,
'\0'
,
sizeof
(
esp_pass
));
memcpy
(
esp_pass
,
&
message_rx
[
2
],
message_rx
[
1
]);
if
(
!
bt_on
)
{
WiFi
.
softAP
(
esp_name
,
esp_pass
);
}
break
;
case
COM_RESET
:
send_short_cmd
(
COM_ACK
);
bt_on
=
true
;
server
.
end
();
SerialBT
.
end
();
if
(
bt_on
)
{
//SerialBT.end();
}
else
{
server
.
end
();
WiFi
.
softAPdisconnect
(
true
);
bt_on
=
true
;
}
SerialBT
.
begin
(
esp_name
);
//Bluetooth device name
break
;
case
COM_ACK
:
...
...
@@ -267,14 +282,14 @@ void loop() {
break
;
case
COM_BT_PAIR
:
if
(
confirmRequestPending
)
{
SerialBT
.
confirmReply
(
true
);
send_short_cmd
(
COM_ACK
);
SerialBT
.
confirmReply
(
true
);
}
break
;
case
COM_BT_CANCEL
:
if
(
confirmRequestPending
)
{
SerialBT
.
confirmReply
(
false
);
send_short_cmd
(
COM_ACK
);
SerialBT
.
confirmReply
(
false
);
}
break
;
case
COM_BT_SUCCESS
:
...
...
@@ -285,21 +300,23 @@ void loop() {
}
break
;
case
COM_WIFI
:
bt_on
=
false
;
SerialBT
.
end
();
WiFi
.
softAP
(
esp_name
,
"12345678"
);
WiFi
.
softAPConfig
(
local_ip
,
gateway
,
subnet
);
IPAddress
myIP
=
WiFi
.
softAPIP
();
server
.
begin
();
if
(
bt_on
)
{
send_short_cmd
(
COM_ACK
);
bt_on
=
false
;
SerialBT
.
end
();
WiFi
.
softAP
(
esp_name
,
esp_pass
);
WiFi
.
softAPConfig
(
local_ip
,
gateway
,
subnet
);
IPAddress
myIP
=
WiFi
.
softAPIP
();
server
.
begin
();
}
else
{
send_short_cmd
(
COM_NACK
);
}
break
;
}
//SerialBT.write(10);
}
else
{
//SerialBT.write(110);
send_short_cmd
(
COM_NACK
);
}
}
else
{
//SerialBT.write(ch);
}
else
{
//payload
message_idx
++
;
}
}
...
...
@@ -317,12 +334,12 @@ void loop() {
}
}
else
{
client
=
server
.
available
();
if
(
!
client
)
if
(
client
)
{
return
;
}
while
(
client
.
connected
())
while
(
client
.
connected
()
&&
!
cmd_pin
)
{
if
(
client
.
available
())
...
...
@@ -361,6 +378,7 @@ void loop() {
request
=
""
;
client
.
stop
();
}
}
}
...
...
This diff is collapsed.
Click to expand it.
lib/cube/esp_config.py
+
7
−
6
View file @
b3cbc47c
...
...
@@ -94,7 +94,7 @@ class Esp:
time
=
utime
.
ticks_ms
()
while
utime
.
ticks_diff
(
utime
.
ticks_ms
(),
time
)
<
timeout
:
self
.
send_reset
()
utime
.
sleep_ms
(
5
0
)
utime
.
sleep_ms
(
5
)
if
self
.
ack_received
()
==
Esp
.
ACK
:
self
.
esp_running
=
True
return
True
...
...
@@ -146,15 +146,16 @@ class Esp:
self
.
send_message
(
self
.
i2b
(
command
)
+
self
.
i2b
(
0
))
receive
=
self
.
wait_for_ack
(
timeout
)
if
receive
!=
Esp
.
TIMEOUT
:
re
turn
receive
return
Esp
.
TIMEOUT
b
re
ak
return
receive
def
repeat_str
(
self
,
command
:
int
,
str
:
str
,
timeout
=
50
):
for
i
in
range
(
Esp
.
NACK_ATTEMPTS
):
self
.
send_str
(
command
,
str
)
if
self
.
wait_for_ack
(
timeout
)
==
Esp
.
ACK
:
return
True
return
False
receive
=
self
.
wait_for_ack
(
timeout
)
if
receive
!=
Esp
.
TIMEOUT
:
break
return
receive
def
send_str
(
self
,
command
:
int
,
str
:
str
):
str_len
=
len
(
str
)
...
...
This diff is collapsed.
Click to expand it.
main/main.py
+
2
−
2
View file @
b3cbc47c
...
...
@@ -141,11 +141,11 @@ def main():
esp_command
(
robot
)
reset
=
robot
.
esp
.
reset
(
100
)
print
(
"
Reset:
"
,
reset
)
robot
.
esp
.
flush
()
robot
.
buttons
.
set_pin
(
14
,
True
)
if
reset
:
print
(
"
Name:
"
,
robot
.
esp
.
set_name
(
"
Open-Cube5
"
,
300
)
)
utime
.
sleep
(
0.5
)
robot
.
esp
.
flush
()
print
(
"
Name:
"
,
robot
.
esp
.
set_name
(
"
Open-Cube5
"
,
300
))
robot
.
buttons
.
set_pin
(
8
,
True
)
bat_voltage
=
robot
.
battery
.
voltage
()
# Get current battery voltage
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment