Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sensor System
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Institut für Informatik
QE Research Group
FORTE
Sensor System
Commits
4f655c60
Commit
4f655c60
authored
2 years ago
by
Moritz Perschke
Browse files
Options
Downloads
Patches
Plain Diff
host change should now be handled properly
parent
051d7b75
No related branches found
No related tags found
3 merge requests
!39
Merge Develop into Main
,
!19
development into master
,
!17
Inital Host, initial Client
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
Tests/Mieming/host_esp32Wroom/client/lib/espnow/src/ESPNow.cpp
+18
-11
18 additions, 11 deletions
.../Mieming/host_esp32Wroom/client/lib/espnow/src/ESPNow.cpp
host/esp-t-sim7000g/src/main.cpp
+3
-3
3 additions, 3 deletions
host/esp-t-sim7000g/src/main.cpp
with
21 additions
and
14 deletions
Tests/Mieming/host_esp32Wroom/client/lib/espnow/src/ESPNow.cpp
+
18
−
11
View file @
4f655c60
...
@@ -22,7 +22,7 @@ void get_host_mac(uint8_t *destination)
...
@@ -22,7 +22,7 @@ void get_host_mac(uint8_t *destination)
preferences
.
getBytes
(
"host"
,
destination
,
sizeof
(
uint8_t
)
*
6
);
preferences
.
getBytes
(
"host"
,
destination
,
sizeof
(
uint8_t
)
*
6
);
}
else
{
}
else
{
memcpy
(
destination
,
BROADCAST_MAC
,
sizeof
(
BROADCAST_MAC
));
memcpy
(
destination
,
BROADCAST_MAC
,
sizeof
(
BROADCAST_MAC
));
ESP_LOG
E
(
TAG
,
"Backup MAC address used"
);
ESP_LOG
I
(
TAG
,
"Backup MAC address used"
);
}
}
preferences
.
end
();
preferences
.
end
();
}
}
...
@@ -53,47 +53,54 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
...
@@ -53,47 +53,54 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
// assume host change not happening, rare event
// assume host change not happening, rare event
// => on host change, broadcast
// => on host change, broadcast
ESP_LOGE
(
TAG
,
"Message recieved"
);
ESP_LOGE
(
TAG
,
"Message recieved"
);
preferences
.
begin
(
"config"
,
false
);
config
received_msg
;
config
received_msg
;
memcpy
(
&
received_msg
,
incomingData
,
sizeof
(
received_msg
));
// TODO: check for valid mac
memcpy
(
&
received_msg
,
incomingData
,
sizeof
(
received_msg
));
// TODO: check for valid mac
// all the esp32 macs so far use the same first 3(?) bytes so maybe use that
// all the esp32 macs so far use the same first 3(?) bytes so maybe use that
switch
(
received_msg
.
type
){
switch
(
received_msg
.
type
){
case
dataAck
:{
case
dataAck
:{
ESP_LOGI
(
TAG
,
"dataAck received."
);
msg_recv
=
true
;
msg_recv
=
true
;
Time
::
getInstance
().
setTime
(
Time
::
getInstance
().
setTime
(
received_msg
.
epoch_seconds
);
// see https://www.esp32.com/viewtopic.php?t=9965, maybe this needs an offset
received_msg
.
epoch_seconds
);
// see https://www.esp32.com/viewtopic.php?t=9965, maybe this needs an offset
Serial
.
println
(
Time
::
getInstance
().
getEpochSeconds
());
Serial
.
println
(
Time
::
getInstance
().
getEpochSeconds
());
preferences
.
begin
(
"config"
,
false
);
if
(
!
preferences
.
isKey
(
"host"
))
{
if
(
!
preferences
.
isKey
(
"host"
))
{
preferences
.
putBytes
(
"host"
,
received_msg
.
host
,
sizeof
(
received_msg
.
host
));
if
(
preferences
.
putBytes
(
"host"
,
received_msg
.
host
,
sizeof
(
received_msg
.
host
))
>
0
){
;
ESP_LOGI
(
TAG
,
"host MAC address saved to flash"
);
ESP_LOGI
(
TAG
,
"host MAC address saved to flash"
);
}
// add host to peers
// add host to peers
add_host_to_peers
(
received_msg
);
add_host_to_peers
(
received_msg
);
}
}
preferences
.
end
();
}
}
case
hostChange
:{
case
hostChange
:{
ESP_LOGI
(
TAG
,
"hostChange received"
);
Time
::
getInstance
().
setTime
(
received_msg
.
epoch_seconds
);
Time
::
getInstance
().
setTime
(
received_msg
.
epoch_seconds
);
// delete old host
// delete old host
preferences
.
begin
(
"config"
,
false
);
if
(
preferences
.
isKey
(
"host"
)){
if
(
preferences
.
isKey
(
"host"
)){
ESP_LOGI
(
TAG
,
"removing old host"
);
uint8_t
old
[
6
];
uint8_t
old
[
6
];
get_host_mac
(
old
);
preferences
.
end
();
get_host_mac
(
old
);
// maybe problem here, re-opening preferences
esp_now_del_peer
(
old
);
esp_now_del_peer
(
old
);
}
}
// add new host
// add new host
preferences
.
putBytes
(
"host"
,
received_msg
.
host
,
sizeof
(
received_msg
.
host
));
preferences
.
begin
(
"config"
,
false
);
ESP_LOGI
(
TAG
,
"Host Mac address saved to flash:"
);
if
(
preferences
.
putBytes
(
"host"
,
received_msg
.
host
,
sizeof
(
received_msg
.
host
))
>
0
){
for
(
int
i
=
0
;
i
<
6
;
i
++
){
ESP_LOGI
(
TAG
,
"Host Mac address saved to flash:"
);
Serial
.
print
(
received_msg
.
host
[
i
],
HEX
);
Serial
.
print
(
":"
);
}
}
Serial
.
println
();
else
{
ESP_LOGI
(
TAG
,
"Couldn't save Host Mac to flash"
);
}
preferences
.
end
();
add_host_to_peers
(
received_msg
);
add_host_to_peers
(
received_msg
);
}
}
default
:
{
default
:
{
break
;
break
;
}
}
}
}
preferences
.
end
();
}
}
...
...
This diff is collapsed.
Click to expand it.
host/esp-t-sim7000g/src/main.cpp
+
3
−
3
View file @
4f655c60
...
@@ -139,7 +139,7 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
...
@@ -139,7 +139,7 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
if
(
!
esp_now_is_peer_exist
(
mac
)){
if
(
!
esp_now_is_peer_exist
(
mac
)){
esp_now_peer_info_t
client
=
{};
esp_now_peer_info_t
client
=
{};
memcpy
(
client
.
peer_addr
,
mac
,
6
);
memcpy
(
client
.
peer_addr
,
mac
,
sizeof
(
uint8_t
)
*
6
);
client
.
encrypt
=
false
;
client
.
encrypt
=
false
;
client
.
channel
=
0
;
client
.
channel
=
0
;
...
@@ -171,13 +171,13 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
...
@@ -171,13 +171,13 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
queue
.
push
(
lineData
);
queue
.
push
(
lineData
);
xSemaphoreGive
(
xMutex
);
xSemaphoreGive
(
xMutex
);
response
response
;
response
response
=
{}
;
response
.
type
=
dataAck
;
response
.
type
=
dataAck
;
esp_read_mac
(
response
.
mac
,
ESP_MAC_WIFI_STA
);
esp_read_mac
(
response
.
mac
,
ESP_MAC_WIFI_STA
);
response
.
time
=
rtc
.
getEpoch
();
response
.
time
=
rtc
.
getEpoch
();
esp_err_t
success
=
esp_now_send
(
mac
,
(
uint8_t
*
)
&
response
,
sizeof
(
response
));
esp_err_t
success
=
esp_now_send
(
mac
,
(
uint8_t
*
)
&
response
,
sizeof
(
response
));
esp_log_write
(
ESP_LOG_DEBUG
,
TAG_ESPNOW
.
c_str
(),
esp_log_write
(
ESP_LOG_DEBUG
,
TAG_ESPNOW
.
c_str
(),
(
success
==
ESP_OK
)
?
"Response sent
.
"
:
"Failed to respond"
);
(
success
==
ESP_OK
)
?
"Response sent
\n
"
:
"Failed to respond
\n
"
);
}
}
String
documentToLineProtocolString
(
const
DynamicJsonDocument
&
doc
)
String
documentToLineProtocolString
(
const
DynamicJsonDocument
&
doc
)
...
...
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