Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
L
lora-temperature-sensor
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
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
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
Jonas Leder
lora-temperature-sensor
Commits
d7358bb8
Verified
Commit
d7358bb8
authored
2 years ago
by
Jonas Leder
Browse files
Options
Downloads
Patches
Plain Diff
move bat voltage check to startup
parent
a3bc1675
No related branches found
No related tags found
No related merge requests found
Pipeline
#9916
passed
2 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.cpp
+21
-16
21 additions, 16 deletions
src/main.cpp
with
21 additions
and
16 deletions
src/main.cpp
+
21
−
16
View file @
d7358bb8
...
@@ -15,10 +15,22 @@ esp_adc_cal_characteristics_t *adc_chars;
...
@@ -15,10 +15,22 @@ esp_adc_cal_characteristics_t *adc_chars;
char
DEVEUI
[
16
];
char
DEVEUI
[
16
];
float
getBatVoltage
();
float
getBatVoltage
();
void
sleep
();
float
batVoltage
;
void
setup
()
void
setup
()
{
{
(
String
(
ESP
.
getEfuseMac
(),
HEX
)
+
"0000"
).
toCharArray
(
DEVEUI
,
17
);
(
String
(
ESP
.
getEfuseMac
(),
HEX
)
+
"0000"
).
toCharArray
(
DEVEUI
,
17
);
batVoltage
=
getBatVoltage
();
if
(
BAT_MIN_VOLTAGE
>
batVoltage
)
{
#ifdef SERIAL_OUTPUT
Serial
.
println
(
"Battery voltage too low, going to sleep again"
);
Serial
.
flush
();
#endif
sleep
();
}
pinMode
(
Vext
,
OUTPUT
);
pinMode
(
Vext
,
OUTPUT
);
digitalWrite
(
Vext
,
LOW
);
// enable power to DS18B20
digitalWrite
(
Vext
,
LOW
);
// enable power to DS18B20
...
@@ -43,7 +55,7 @@ void setup()
...
@@ -43,7 +55,7 @@ void setup()
uint8_t
txBuffer
[
14
];
uint8_t
txBuffer
[
14
];
txBuffer
[
0
]
=
(
rawTemp
>>
8
)
&
0xFF
;
txBuffer
[
0
]
=
(
rawTemp
>>
8
)
&
0xFF
;
txBuffer
[
1
]
=
rawTemp
&
0xFF
;
txBuffer
[
1
]
=
rawTemp
&
0xFF
;
txBuffer
[
2
]
=
(
getB
atVoltage
()
*
100
)
-
200
;
txBuffer
[
2
]
=
(
b
atVoltage
*
100
)
-
200
;
#ifdef SERIAL_OUTPUT
#ifdef SERIAL_OUTPUT
Serial
.
print
(
"Raw Temperature: "
);
Serial
.
print
(
"Raw Temperature: "
);
...
@@ -56,25 +68,12 @@ void setup()
...
@@ -56,25 +68,12 @@ void setup()
#ifdef SERIAL_OUTPUT
#ifdef SERIAL_OUTPUT
Serial
.
print
(
"Battery voltage: "
);
Serial
.
print
(
"Battery voltage: "
);
Serial
.
println
(
getB
atVoltage
()
);
Serial
.
println
(
b
atVoltage
);
Serial
.
println
(
"Going to sleep"
);
Serial
.
println
(
"Going to sleep"
);
Serial
.
flush
();
Serial
.
flush
();
#endif
#endif
sleep
();
if
(
BAT_MIN_VOLTAGE
<
getBatVoltage
())
{
uint64_t
sleepTime
=
SLEEP_TIME
*
uS_TO_S_FACTOR
;
esp_sleep_enable_timer_wakeup
(
sleepTime
);
}
#ifdef SERIAL_OUTPUT
else
{
Serial
.
println
(
"Battery voltage too low, going to permanent deep sleep"
);
}
#endif
esp_deep_sleep_start
();
}
}
float
getBatVoltage
()
{
float
getBatVoltage
()
{
...
@@ -86,6 +85,12 @@ float getBatVoltage() {
...
@@ -86,6 +85,12 @@ float getBatVoltage() {
return
adcVal
/
4095.0
*
BAT_FACTOR
;
return
adcVal
/
4095.0
*
BAT_FACTOR
;
}
}
void
sleep
()
{
uint64_t
sleepTime
=
SLEEP_TIME
*
uS_TO_S_FACTOR
;
esp_sleep_enable_timer_wakeup
(
sleepTime
);
esp_deep_sleep_start
();
}
void
loop
()
void
loop
()
{
{
}
}
\ 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