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
c8e6c63f
Commit
c8e6c63f
authored
2 years ago
by
Moritz Perschke
Browse files
Options
Downloads
Patches
Plain Diff
created message class, started implementing configuration
parent
3032f591
No related branches found
No related tags found
5 merge requests
!39
Merge Develop into Main
,
!19
development into master
,
!17
Inital Host, initial Client
,
!3
Merge Branch `develop` into `sensor_readout`
,
!1
Espnow
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
client/client/lib/espnow/src/espnow.cpp
+51
-12
51 additions, 12 deletions
client/client/lib/espnow/src/espnow.cpp
client/client/lib/espnow/src/espnow.hpp
+27
-7
27 additions, 7 deletions
client/client/lib/espnow/src/espnow.hpp
with
78 additions
and
19 deletions
client/client/lib/espnow/src/espnow.cpp
+
51
−
12
View file @
c8e6c63f
#include
<esp_now.h>
#include
<esp_now.h>
#include
<Preferences.h>
#include
"WiFi.h"
#include
"WiFi.h"
#include
"espnow.hpp"
#include
"espnow.hpp"
uint8_t
BROADCAST_MAC
[]
=
{
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
};
//probably shouldn't be defined here, works for now
uint8_t
BROADCAST_MAC
[]
=
{
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0xFF
};
// leaving this in as possible backup
uint8_t
host_mac
[
6
];
esp_now_peer_info_t
hostInfo
;
esp_now_peer_info_t
hostInfo
;
Preferences
preferences
;
void
on_data_sent
(
const
uint8_t
*
mac_addr
,
esp_now_send_status_t
status
){
void
on_data_sent
(
const
uint8_t
*
mac_addr
,
esp_now_send_status_t
status
){
// go to sleep
// go to sleep
...
@@ -11,31 +14,67 @@ void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status){
...
@@ -11,31 +14,67 @@ void on_data_sent(const uint8_t *mac_addr, esp_now_send_status_t status){
void
on_data_recv
(
const
uint8_t
*
mac
,
const
uint8_t
*
incomingData
,
int
len
){
void
on_data_recv
(
const
uint8_t
*
mac
,
const
uint8_t
*
incomingData
,
int
len
){
// sync time
// sync time
}
config
new_config
;
memcpy
(
&
new_config
,
incomingData
,
sizeof
(
new_config
));
// TODO: check for valid mac
int
send_data
(
dataMessage
data
){
preferences
.
begin
(
"config"
,
false
);
esp_err_t
result
=
esp_now_send
(
BROADCAST_MAC
,
(
uint8_t
*
)
&
data
,
sizeof
(
data
));
if
(
!
preferences
.
isKey
(
"host"
)){
return
result
;
preferences
.
putBytes
(
"host"
,
new_config
.
host
,
sizeof
(
uint8_t
)
*
6
);
}
}
}
int
espnow_setup
(){
esp_err_t
espnow_setup
(){
esp_err_t
result
;
WiFi
.
mode
(
WIFI_STA
);
WiFi
.
mode
(
WIFI_STA
);
if
(
esp_now_init
()
!=
ESP_OK
){
result
=
esp_now_init
();
if
(
result
!=
ESP_OK
){
//initialization failed
//initialization failed
return
1
;
return
result
;
}
}
memcpy
(
hostInfo
.
peer_addr
,
BROADCAST_MAC
,
sizeof
(
BROADCAST_MAC
));
memcpy
(
hostInfo
.
peer_addr
,
BROADCAST_MAC
,
sizeof
(
BROADCAST_MAC
));
hostInfo
.
channel
=
0
;
hostInfo
.
channel
=
0
;
hostInfo
.
encrypt
=
true
;
//if we encrypt espnow we can have no more than 10 clients per host
hostInfo
.
encrypt
=
true
;
//if we encrypt espnow we can have no more than 10 clients per host
es
p_err_t
peerAddStatus
=
esp_now_add_peer
(
&
hostInfo
);
//there are a couple errors that can happen here
r
es
ult
=
esp_now_add_peer
(
&
hostInfo
);
//there are a couple errors that can happen here
if
(
peerAddStatus
!=
ESP_OK
){
if
(
result
!=
ESP_OK
){
//peer couldn't be added
//peer couldn't be added
return
2
;
return
result
;
}
}
esp_now_register_recv_cb
(
on_data_recv
);
esp_now_register_recv_cb
(
on_data_recv
);
esp_now_register_send_cb
(
on_data_sent
);
esp_now_register_send_cb
(
on_data_sent
);
return
0
;
return
ESP_OK
;
}
}
void
Message
::
add_data
(
float
value
,
int
identifier
){
data
.
values
[
amountData
]
=
value
;
data
.
identifiers
[
amountData
]
=
identifier
;
amountData
++
;
if
(
data
.
timestamp
==
NULL
){
//add timestamp
}
}
// BROADCAST_MAC is to be changed
esp_err_t
Message
::
send
(){
esp_err_t
success
;
if
(
host_mac
==
NULL
){
success
=
esp_now_send
(
BROADCAST_MAC
,
(
uint8_t
*
)
&
data
,
sizeof
(
data
));
}
// if no host defined broadcast message
success
=
esp_now_send
(
host_mac
,
(
uint8_t
*
)
&
data
,
sizeof
(
data
));
// TODO: cache data before resetting
data_struct
empty_data
;
data
=
empty_data
;
amountData
=
0
;
return
success
;
}
void
Message
::
set_timestamp
(
long
millis
){
data
.
timestamp
=
millis
;
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
client/client/lib/espnow/src/espnow.hpp
+
27
−
7
View file @
c8e6c63f
#ifndef _ESPNOW
#define _ESPNOW
#include
<string>
#define NUM_SENSORS 10
#define NUM_SENSORS 10
// I originally wanted to define the mac addresses here, but i got a "multiple definition" error?
// having the data be a struct of basic types makes sending easier,
typedef
struct
dataMessage
{
// otherwise we would have to serialize the data before sending
std
::
string
identifiers
[
NUM_SENSORS
];
typedef
struct
data_struct
{
int
identifiers
[
NUM_SENSORS
];
float
values
[
NUM_SENSORS
];
float
values
[
NUM_SENSORS
];
}
dataMessage
;
long
timestamp
;
//maybe make this array
}
data
;
int
send_data
(
dataMessage
data
);
// if more things are sent from the host the name might not be accurate anymore
typedef
struct
config
{
uint8_t
host
[
6
];
long
time_millis
;
}
config
;
int
espnow_setup
();
class
Message
{
\ No newline at end of file
public:
void
add_data
(
float
value
,
int
identifier
);
void
set_timestamp
(
long
millis
);
esp_err_t
send
();
private:
data_struct
data
;
int
amountData
=
0
;
};
esp_err_t
espnow_setup
();
#endif
\ No newline at end of file
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