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
05d00b43
Commit
05d00b43
authored
2 years ago
by
Moritz Perschke
Browse files
Options
Downloads
Patches
Plain Diff
added functionality to change mac address in flash
parent
38205401
No related branches found
Branches containing commit
No related tags found
Tags containing commit
4 merge requests
!39
Merge Develop into Main
,
!19
development into master
,
!17
Inital Host, initial Client
,
!6
Espnow
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/client/lib/espnow/src/ESPNow.cpp
+30
-4
30 additions, 4 deletions
client/client/lib/espnow/src/ESPNow.cpp
client/client/src/main.cpp
+5
-14
5 additions, 14 deletions
client/client/src/main.cpp
with
35 additions
and
18 deletions
client/client/lib/espnow/src/ESPNow.cpp
+
30
−
4
View file @
05d00b43
...
...
@@ -28,15 +28,29 @@ void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status)
// go to sleep
}
bool
are_mac_addresses_equal
(
uint8_t
first_mac
[],
uint8_t
second_mac
[]){
bool
result
=
true
;
for
(
int
i
=
0
;
i
<
6
;
i
++
){
result
&&
(
first_mac
[
i
]
==
second_mac
[
i
]);
}
return
result
;
}
void
on_data_recv
(
const
uint8_t
*
mac
,
const
uint8_t
*
incomingData
,
int
len
)
{
ESP_LOGI
(
TAG
,
"Message recieved"
);
ESP_LOGE
(
TAG
,
"Message recieved"
);
preferences
.
begin
(
"config"
,
false
);
config
new_config
;
memcpy
(
&
new_config
,
incomingData
,
sizeof
(
new_config
));
// TODO: check for valid mac
// all the esp32 macs so far use the same first 3(?) bytes so maybe use that
uint8_t
stored
[
6
];
preferences
.
getBytes
(
"host"
,
stored
,
sizeof
(
uint8_t
)
*
6
);
// put the host address in flash mem
preferences
.
begin
(
"config"
,
false
);
if
(
!
preferences
.
isKey
(
"host"
))
{
// this does not work as long as we don't know whether a message was received
// save received host address if there is none saved or received one is different than before
if
(
!
preferences
.
isKey
(
"host"
)
||
!
are_mac_addresses_equal
(
stored
,
new_config
.
host
))
{
preferences
.
putBytes
(
"host"
,
new_config
.
host
,
sizeof
(
new_config
.
host
));
ESP_LOGI
(
TAG
,
"host MAC address saved to flash"
);
...
...
@@ -50,7 +64,18 @@ void on_data_recv(const uint8_t *mac, const uint8_t *incomingData, int len)
ESP_LOGE
(
TAG
,
"Adding host to peers failed"
);
}
}
// host change shouldn't be an issue
if
(
!
are_mac_addresses_equal
(
stored
,
new_config
.
host
)){
esp_now_del_peer
(
stored
);
}
}
// changed Oct. 24th: now has the capability to change the mac in flash
else
{
uint8_t
stored
[
6
];
preferences
.
getBytes
(
"host"
,
stored
,
sizeof
(
uint8_t
)
*
6
);
if
(
!
are_mac_addresses_equal
(
stored
,
new_config
.
host
)){
}
}
preferences
.
end
();
// sync time
Time
::
getInstance
().
setTime
(
...
...
@@ -77,6 +102,7 @@ esp_err_t espnow_setup()
hostInfo
.
encrypt
=
false
;
esp_now_add_peer
(
&
hostInfo
);
preferences
.
clear
();
esp_now_register_recv_cb
(
on_data_recv
);
esp_now_register_send_cb
(
on_data_sent
);
...
...
This diff is collapsed.
Click to expand it.
client/client/src/main.cpp
+
5
−
14
View file @
05d00b43
...
...
@@ -32,21 +32,12 @@ void loop()
auto
messages
=
drs26
.
buildMessages
();
for
(
const
Message
&
message
:
messages
)
{
//
if(message.send() != ESP_OK){
//
RtcMemory::store(message.getMessageAsMinifiedJsonString());
//
}
if
(
message
.
send
()
!=
ESP_OK
){
RtcMemory
::
store
(
message
.
getMessageAsMinifiedJsonString
());
}
// some sort of if(message received) is needed as well
RtcMemory
::
store
(
message
.
getMessageAsMinifiedJsonString
());
// Serial.println("original string:");
// Serial.println(message.getMessageAsMinifiedJsonString().c_str());
// Serial.println("length: " + (String) sizeof(message.getMessageAsMinifiedJsonString().c_str()));
// Serial.println("\n after retrieval:");
String
test
=
RtcMemory
::
get_from_storage
();
// Serial.println(test);
// Serial.println("length: " + (String) sizeof(test));
Serial
.
println
(
"------------------------"
);
// String test = RtcMemory::get_from_storage();
}
Serial
.
println
(
"================================"
);
}
catch
(
const
NoDataAvailableException
&
e
)
{
std
::
cerr
<<
e
.
what
()
<<
'\n'
;
...
...
@@ -60,5 +51,5 @@ void loop()
Serial
.
println
(
WiFi
.
macAddress
());
Serial
.
println
(
"
\n
"
);
delay
(
10000
);
//
DeepSleep::deep_sleep(5);
DeepSleep
::
deep_sleep
(
5
);
}
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