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
Merge requests
!21
Develop central mast client
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Develop central mast client
develop-central-mast-client
into
develop
Overview
0
Commits
7
Pipelines
0
Changes
9
Merged
User expired
requested to merge
develop-central-mast-client
into
develop
2 years ago
Overview
0
Commits
7
Pipelines
0
Changes
9
Expand
Mostly central mast client stuff. Small changes in host and satellite client
Edited
2 years ago
by
User expired
0
0
Merge request reports
Compare
develop
develop (base)
and
latest version
latest version
ae91d741
7 commits,
2 years ago
9 files
+
1172
−
522
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
9
Search (e.g. *.vue) (Ctrl+P)
client/client_central_mast/src/main.cpp
+
63
−
22
Options
#include
"Arduino.h"
#include
"ESPNow.hpp"
#include
"rs485.hpp"
#include
"NoDataAvailableException.hpp"
#include
"rs485.hpp"
#define uS_TO_S_FACTOR 1000000
/* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 60
/* Time ESP32 will go to sleep (in seconds) */
static
const
char
*
TAG
=
"MAIN"
;
#define uS_TO_S_FACTOR 1000000
/* Conversion factor for micro seconds to seconds */
#define TIME_TO_SLEEP 5 * 60
/* Time ESP32 will go to sleep (in seconds) */
Forte_RS485
rs485
;
void
setup
()
float
getBatteryVoltage
()
{
rs485
.
setup
();
espnow_setup
();
//************ Measuring Battery Voltage ***********
// reference voltage of microcontroller 3.3v for esp32
const
float
reference_vcc
=
3.3
;
// value of R2 resistor [kOhm]
const
float
bat_res_gnd
=
20
;
// value of R1 resistor [kOhm]
const
float
bat_res_vcc
=
68
;
// max ADC value
const
int
adc
=
4095
;
float
sample
=
0
;
// Get 100 analog read to prevent unusefully read
for
(
int
i
=
0
;
i
<
100
;
i
++
)
{
sample
=
sample
+
analogRead
(
35
);
// read the voltage from the divider circuit
delay
(
2
);
}
sample
=
sample
/
100
;
float
battery_voltage
=
(
sample
/
4095
*
reference_vcc
*
(
bat_res_vcc
+
bat_res_gnd
)
/
bat_res_gnd
);
ESP_LOGI
(
TAG
,
"Battery Voltage: %4.2f V"
,
battery_voltage
);
ESP_LOGD
(
TAG
,
"ADC mean Value: %4.2f"
,
sample
);
return
battery_voltage
;
}
void
loop
()
{
try
{
// FIXME: put this in ESPNow.hpp and let stupid Markus Rampp know how you did it. After years of Python he moved past
// the idea of types and declarations
void
send_msgs
(
const
std
::
__cxx11
::
list
<
Message
>
msgs
)
{
for
(
const
Message
&
msg
:
msgs
)
{
auto
messages
=
rs485
.
buildMessages
();
for
(
const
Message
&
message
:
messages
)
{
if
(
message
.
send
()
!=
ESP_OK
){
RtcMemory
::
store
(
message
.
getMessageAsMinifiedJsonString
());
}
delay
(
5000
);
if
(
!
was_msg_received
()){
RtcMemory
::
store
(
message
.
getMessageAsMinifiedJsonString
());
if
(
msg
.
send
()
!=
ESP_OK
)
{
RtcMemory
::
store
(
msg
.
getMessageAsMinifiedJsonString
());
}
unsigned
long
ts
=
millis
();
// it takes ~110ms for receiving an acknowledgement by the host in perfect conditions
uint16_t
message_timeout
=
2000
;
while
(
!
was_msg_received
())
{
if
((
millis
()
-
ts
)
>
message_timeout
)
{
RtcMemory
::
store
(
msg
.
getMessageAsMinifiedJsonString
());
ESP_LOGE
(
TAG
,
"Timeout: Host not available
\n
"
);
break
;
}
}
ESP_LOGD
(
TAG
,
"Time until acknowledgement: %ld"
,
millis
()
-
ts
);
}
}
void
setup
()
{
// whole loop should be around ~3000 ms
Serial
.
begin
(
115200
);
rs485
.
setup
();
getBatteryVoltage
();
// ~2100ms
try
{
auto
messages
=
rs485
.
buildMessages
();
espnow_setup
();
send_msgs
(
messages
);
}
catch
(
const
NoDataAvailableException
&
e
)
{
std
::
cerr
<<
e
.
what
()
<<
'\n'
;
}
Serial
.
print
(
"Going to sleep for secounds:"
);
Serial
.
println
(
TIME_TO_SLEEP
);
esp_sleep_enable_timer_wakeup
(
TIME_TO_SLEEP
*
uS_TO_S_FACTOR
);
esp_deep_sleep_start
();
ESP_LOGD
(
TAG
,
"Going to sleep for %d seconds"
,
TIME_TO_SLEEP
);
esp_sleep_enable_timer_wakeup
(
TIME_TO_SLEEP
*
uS_TO_S_FACTOR
);
esp_deep_sleep_start
();
}
void
loop
()
{}
Loading