Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Matrix of Life
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Jan Grewe
Matrix of Life
Commits
ee7ff3a3
Commit
ee7ff3a3
authored
2 years ago
by
Jan Grewe
Browse files
Options
Downloads
Patches
Plain Diff
speed OTA up by only updating display on percent change
add more Telnet commands use nested JSON for config
parent
636ed214
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/gameoflife.cpp
+1
-0
1 addition, 0 deletions
src/gameoflife.cpp
src/network.cpp
+49
-27
49 additions, 27 deletions
src/network.cpp
src/network.h
+2
-1
2 additions, 1 deletion
src/network.h
with
52 additions
and
28 deletions
src/gameoflife.cpp
+
1
−
0
View file @
ee7ff3a3
...
...
@@ -36,6 +36,7 @@ void setupGameOfLife()
{
addGlider
(
random
(
SCREEN_HEIGHT
),
random
(
SCREEN_WIDTH
),
g
);
}
logLine
(
"Starting Game "
+
String
(
gameEra
));
}
void
createRandomMatrix
(
int
(
&
a
)[
SCREEN_HEIGHT
][
SCREEN_WIDTH
])
...
...
This diff is collapsed.
Click to expand it.
src/network.cpp
+
49
−
27
View file @
ee7ff3a3
...
...
@@ -11,6 +11,8 @@ AsyncWebSocket ws("/ws");
ESPTelnet
telnet
;
IPAddress
ip
;
int
otaProgress
=
0
;
void
setupNetwork
()
{
setupWifi
();
...
...
@@ -53,9 +55,6 @@ void setupOTA()
ArduinoOTA
.
onStart
([]()
{
runGame
=
false
;
if
(
ArduinoOTA
.
getCommand
()
!=
U_FLASH
)
{
LittleFS
.
end
();
}
ws
.
enable
(
false
);
ws
.
textAll
(
"OTA Update Started"
);
ws
.
closeAll
();
...
...
@@ -68,12 +67,16 @@ void setupOTA()
clearDisplay
();
});
ArduinoOTA
.
onProgress
([](
unsigned
int
progress
,
unsigned
int
total
)
{
int
percent
=
ceil
(
progress
/
(
total
/
100
));
if
(
percent
>
otaProgress
)
{
char
msg
[
10
];
sprintf
(
msg
,
"OTA:%3d%%"
,
(
progress
/
(
total
/
100
))
);
sprintf
(
msg
,
"OTA:%3d%%"
,
percent
);
showMessage
(
msg
);
logLine
(
"OTA: "
,
false
);
logLine
((
String
)(
progress
/
(
total
/
100
)),
false
);
logLine
(
"%"
);
});
logLine
((
String
)
percent
,
false
);
logLine
(
"%"
);
otaProgress
=
percent
;
}
});
ArduinoOTA
.
onError
([](
ota_error_t
error
)
{
if
(
error
==
OTA_AUTH_ERROR
)
logLine
(
"OTA Auth Failed"
);
...
...
@@ -122,7 +125,6 @@ void setupWebserver()
void
networkLoop
()
{
ArduinoOTA
.
handle
();
if
(
runGame
)
telnet
.
loop
();
}
...
...
@@ -133,7 +135,7 @@ void onTelnetConnect(String ip)
Serial
.
println
(
" connected"
);
telnet
.
println
(
"
\n
Welcome "
+
telnet
.
getIP
());
telnet
.
println
(
"Use CTRL+
q
to disconnect.
\n
"
);
telnet
.
println
(
"Use
'
CTRL+
Q, ENTER'
to disconnect.
\n
"
);
}
void
onTelnetDisconnect
(
String
ip
)
...
...
@@ -159,25 +161,29 @@ void onTelnetConnectionAttempt(String ip)
void
onTelnetInput
(
String
str
)
{
// checks for a certain command
if
(
str
==
"ping"
)
{
telnet
.
println
(
"> pong"
);
Serial
.
println
(
"- Telnet: pong"
);
// disconnect the client
}
else
if
(
str
==
"quit"
)
else
if
(
str
==
"quit"
||
str
==
"exit"
)
{
telnet
.
println
(
"> disconnecting
you
..."
);
telnet
.
println
(
"> disconnecting..."
);
telnet
.
disconnectClient
();
}
else
if
(
str
==
"reboot"
||
str
==
"reset"
)
{
telnet
.
println
(
"> rebooting..."
);
ESP
.
restart
();
}
}
DynamicJsonDocument
getConfigJson
()
{
DynamicJsonDocument
doc
(
1024
);
doc
[
"brightness"
]
=
defaultBrightness
;
doc
[
"interval"
]
=
gameInterval
;
DynamicJsonDocument
doc
(
200
);
JsonObject
config
=
doc
.
createNestedObject
(
"config"
);
config
[
"brightness"
]
=
defaultBrightness
;
config
[
"interval"
]
=
gameInterval
;
return
doc
;
}
...
...
@@ -186,7 +192,8 @@ void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType
if
(
type
==
WS_EVT_CONNECT
)
{
// client connected
logLine
(
"WS: connect"
);
logLine
(
"WS<< connect"
);
logLine
(
"WS>> ping"
);
client
->
ping
();
DynamicJsonDocument
doc
=
getConfigJson
();
size_t
strsize
=
measureJson
(
doc
)
+
1
;
...
...
@@ -198,7 +205,7 @@ void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType
}
else
if
(
type
==
WS_EVT_DISCONNECT
)
{
logLine
(
"WS
:
disconnect"
);
logLine
(
"WS
<<
disconnect"
);
}
else
if
(
type
==
WS_EVT_ERROR
)
{
...
...
@@ -210,7 +217,7 @@ void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType
else
if
(
type
==
WS_EVT_PONG
)
{
// pong message was received (in response to a ping request maybe)
logLine
(
"WS
:
pong"
);
logLine
(
"WS
<<
pong"
);
}
else
if
(
type
==
WS_EVT_DATA
)
{
...
...
@@ -218,15 +225,30 @@ void onEvent(AsyncWebSocket *server, AsyncWebSocketClient *client, AwsEventType
data
[
len
]
=
0
;
logLine
(
"WS<< "
,
false
);
logLine
((
char
*
)
data
);
updateConfig
(
data
);
handleJson
(
data
);
}
}
void
updateConfig
(
uint8_t
*
data
)
void
handleJson
(
uint8_t
*
data
)
{
StaticJsonDocument
<
200
>
doc
;
deserializeJson
(
doc
,
(
char
*
)
data
);
defaultBrightness
=
(
int
)
doc
[
"brightness"
];
DeserializationError
error
=
deserializeJson
(
doc
,
(
char
*
)
data
);
if
(
error
)
{
logLine
(
"deserializeJson() failed: "
,
false
);
logLine
(
error
.
c_str
());
return
;
}
if
(
doc
.
containsKey
(
"config"
))
{
updateConfig
(
doc
);
}
}
void
updateConfig
(
StaticJsonDocument
<
200U
>
doc
)
{
gameInterval
=
doc
[
"config"
][
"interval"
];
defaultBrightness
=
doc
[
"config"
][
"brightness"
];
displayBrightness
(
defaultBrightness
);
gameInterval
=
(
int
)
doc
[
"interval"
];
}
This diff is collapsed.
Click to expand it.
src/network.h
+
2
−
1
View file @
ee7ff3a3
...
...
@@ -29,6 +29,7 @@ void onTelnetReconnect(String ip);
void
onTelnetConnectionAttempt
(
String
ip
);
void
onTelnetInput
(
String
str
);
void
onEvent
(
AsyncWebSocket
*
server
,
AsyncWebSocketClient
*
client
,
AwsEventType
type
,
void
*
arg
,
uint8_t
*
data
,
size_t
len
);
void
updateConfig
(
uint8_t
*
data
);
void
handleJson
(
uint8_t
*
data
);
void
updateConfig
(
StaticJsonDocument
<
200U
>
doc
);
#endif
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