Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
8372df49
Commit
8372df49
authored
4 years ago
by
Eric Duminil
Browse files
Options
Download
Email Patches
Plain Diff
NTP time : Slowly replacing Strings by C strings
parent
6ae78c3c
master
develop
experimental/example_for_iotwebconf
senseair_s8
v0.3.0
v0.2.3
v0.2.2
v0.2.1
v0.2.0
v0.1.0
archive/refactor/src_structure
archive/experimental/wifimanager
archive/experimental/simple
archive/experimental/save_lora_session
archive/experimental/save_config
archive/experimental/ota
archive/experimental/binary_clock
archive/experimental/autoconnect
archive/dev/debugcalib
No related merge requests found
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
ampel-firmware/csv_writer.cpp
+3
-3
ampel-firmware/csv_writer.cpp
ampel-firmware/csv_writer.h
+1
-1
ampel-firmware/csv_writer.h
ampel-firmware/mqtt.cpp
+4
-4
ampel-firmware/mqtt.cpp
ampel-firmware/mqtt.h
+1
-1
ampel-firmware/mqtt.h
ampel-firmware/src/lib/NTPClient-master/NTPClient.cpp
+6
-7
ampel-firmware/src/lib/NTPClient-master/NTPClient.cpp
ampel-firmware/src/lib/NTPClient-master/NTPClient.h
+1
-1
ampel-firmware/src/lib/NTPClient-master/NTPClient.h
with
16 additions
and
17 deletions
+16
-17
ampel-firmware/csv_writer.cpp
+
3
-
3
View file @
8372df49
...
@@ -132,11 +132,11 @@ namespace csv_writer {
...
@@ -132,11 +132,11 @@ namespace csv_writer {
return
csv_file
;
return
csv_file
;
}
}
void
log
(
const
String
&
time
S
tamp
,
const
int16_t
&
co2
,
const
float
&
temperature
,
const
float
&
humidity
)
{
void
log
(
const
char
*
time
s
tamp
,
const
int16_t
&
co2
,
const
float
&
temperature
,
const
float
&
humidity
)
{
led_effects
::
onBoardLEDOn
();
led_effects
::
onBoardLEDOn
();
File
csv_file
=
openOrCreate
();
File
csv_file
=
openOrCreate
();
char
csv_line
[
42
];
char
csv_line
[
42
];
snprintf
(
csv_line
,
sizeof
(
csv_line
),
"%s;%d;%.1f;%.1f
\r\n
"
,
time
S
tamp
.
c_str
()
,
co2
,
temperature
,
humidity
);
snprintf
(
csv_line
,
sizeof
(
csv_line
),
"%s;%d;%.1f;%.1f
\r\n
"
,
time
s
tamp
,
co2
,
temperature
,
humidity
);
if
(
csv_file
)
{
if
(
csv_file
)
{
size_t
written_bytes
=
csv_file
.
print
(
csv_line
);
size_t
written_bytes
=
csv_file
.
print
(
csv_line
);
csv_file
.
close
();
csv_file
.
close
();
...
@@ -156,7 +156,7 @@ namespace csv_writer {
...
@@ -156,7 +156,7 @@ namespace csv_writer {
led_effects
::
onBoardLEDOff
();
led_effects
::
onBoardLEDOff
();
}
}
void
logIfTimeHasCome
(
const
String
&
timeStamp
,
const
int16_t
&
co2
,
const
float
&
temperature
,
const
float
&
humidity
)
{
void
logIfTimeHasCome
(
const
char
*
timeStamp
,
const
int16_t
&
co2
,
const
float
&
temperature
,
const
float
&
humidity
)
{
unsigned
long
now
=
seconds
();
unsigned
long
now
=
seconds
();
if
(
now
-
last_written_at
>
config
::
csv_interval
)
{
if
(
now
-
last_written_at
>
config
::
csv_interval
)
{
last_written_at
=
now
;
last_written_at
=
now
;
...
...
This diff is collapsed.
Click to expand it.
ampel-firmware/csv_writer.h
+
1
-
1
View file @
8372df49
...
@@ -22,7 +22,7 @@ namespace config {
...
@@ -22,7 +22,7 @@ namespace config {
namespace
csv_writer
{
namespace
csv_writer
{
extern
char
last_successful_write
[
23
];
extern
char
last_successful_write
[
23
];
void
initialize
();
void
initialize
();
void
logIfTimeHasCome
(
const
String
&
time
S
tamp
,
const
int16_t
&
co2
,
const
float
&
temperature
,
const
float
&
humidity
);
void
logIfTimeHasCome
(
const
char
*
time
s
tamp
,
const
int16_t
&
co2
,
const
float
&
temperature
,
const
float
&
humidity
);
int
getAvailableSpace
();
int
getAvailableSpace
();
extern
const
String
filename
;
extern
const
String
filename
;
...
...
This diff is collapsed.
Click to expand it.
ampel-firmware/mqtt.cpp
+
4
-
4
View file @
8372df49
...
@@ -41,13 +41,13 @@ namespace mqtt {
...
@@ -41,13 +41,13 @@ namespace mqtt {
" (Sends local IP and SSID via MQTT. Can be useful to find sensor)"
);
" (Sends local IP and SSID via MQTT. Can be useful to find sensor)"
);
}
}
void
publish
(
const
String
&
timestamp
,
int16_t
co2
,
float
temperature
,
float
humidity
)
{
void
publish
(
const
char
*
timestamp
,
int16_t
co2
,
float
temperature
,
float
humidity
)
{
if
(
WiFi
.
status
()
==
WL_CONNECTED
&&
mqttClient
.
connected
())
{
if
(
WiFi
.
status
()
==
WL_CONNECTED
&&
mqttClient
.
connected
())
{
led_effects
::
onBoardLEDOn
();
led_effects
::
onBoardLEDOn
();
Serial
.
print
(
F
(
"MQTT - Publishing message ... "
));
Serial
.
print
(
F
(
"MQTT - Publishing message ... "
));
char
payload
[
75
];
// Should be enough for json...
char
payload
[
75
];
// Should be enough for json...
snprintf
(
payload
,
sizeof
(
payload
),
json_sensor_format
,
timestamp
.
c_str
()
,
co2
,
temperature
,
humidity
);
snprintf
(
payload
,
sizeof
(
payload
),
json_sensor_format
,
timestamp
,
co2
,
temperature
,
humidity
);
// Topic is the same as clientID. e.g. 'CO2sensors/ESP3d03da'
// Topic is the same as clientID. e.g. 'CO2sensors/ESP3d03da'
if
(
mqttClient
.
publish
(
publish_topic
.
c_str
(),
payload
))
{
if
(
mqttClient
.
publish
(
publish_topic
.
c_str
(),
payload
))
{
Serial
.
println
(
F
(
"OK"
));
Serial
.
println
(
F
(
"OK"
));
...
@@ -120,12 +120,12 @@ namespace mqtt {
...
@@ -120,12 +120,12 @@ namespace mqtt {
}
}
}
}
void
publishIfTimeHasCome
(
const
String
&
time
S
tamp
,
const
int16_t
&
co2
,
const
float
&
temp
,
const
float
&
hum
)
{
void
publishIfTimeHasCome
(
const
char
*
time
s
tamp
,
const
int16_t
&
co2
,
const
float
&
temp
,
const
float
&
hum
)
{
// Send message via MQTT according to sending interval
// Send message via MQTT according to sending interval
unsigned
long
now
=
seconds
();
unsigned
long
now
=
seconds
();
if
(
now
-
last_sent_at
>
config
::
mqtt_sending_interval
)
{
if
(
now
-
last_sent_at
>
config
::
mqtt_sending_interval
)
{
last_sent_at
=
now
;
last_sent_at
=
now
;
publish
(
time
S
tamp
,
co2
,
temp
,
hum
);
publish
(
time
s
tamp
,
co2
,
temp
,
hum
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
ampel-firmware/mqtt.h
+
1
-
1
View file @
8372df49
...
@@ -15,7 +15,7 @@ namespace mqtt {
...
@@ -15,7 +15,7 @@ namespace mqtt {
extern
bool
connected
;
extern
bool
connected
;
void
initialize
(
String
&
topic
);
void
initialize
(
String
&
topic
);
void
keepConnection
();
void
keepConnection
();
void
publishIfTimeHasCome
(
const
String
&
time
S
tamp
,
const
int16_t
&
co2
,
const
float
&
temp
,
const
float
&
hum
);
void
publishIfTimeHasCome
(
const
char
*
time
s
tamp
,
const
int16_t
&
co2
,
const
float
&
temp
,
const
float
&
hum
);
void
setMQTTinterval
(
int32_t
sending_interval
);
void
setMQTTinterval
(
int32_t
sending_interval
);
void
sendInfoAboutLocalNetwork
();
void
sendInfoAboutLocalNetwork
();
...
...
This diff is collapsed.
Click to expand it.
ampel-firmware/src/lib/NTPClient-master/NTPClient.cpp
+
6
-
7
View file @
8372df49
...
@@ -152,19 +152,17 @@ int NTPClient::getSeconds() {
...
@@ -152,19 +152,17 @@ int NTPClient::getSeconds() {
return
(
this
->
getEpochTime
()
%
60
);
return
(
this
->
getEpochTime
()
%
60
);
}
}
String
NTPClient
::
getFormattedTime
(
unsigned
long
secs
)
{
void
NTPClient
::
getFormattedTime
(
char
*
formatted_time
,
unsigned
long
secs
)
{
unsigned
long
rawTime
=
secs
?
secs
:
this
->
getEpochTime
();
unsigned
long
rawTime
=
secs
?
secs
:
this
->
getEpochTime
();
unsigned
int
hours
=
(
rawTime
%
86400L
)
/
3600
;
unsigned
int
hours
=
(
rawTime
%
86400L
)
/
3600
;
unsigned
int
minutes
=
(
rawTime
%
3600
)
/
60
;
unsigned
int
minutes
=
(
rawTime
%
3600
)
/
60
;
unsigned
int
seconds
=
rawTime
%
60
;
unsigned
int
seconds
=
rawTime
%
60
;
char
formatted_time
[
9
];
snprintf
(
formatted_time
,
9
,
"%02d:%02d:%02d"
,
hours
,
minutes
,
seconds
);
snprintf
(
formatted_time
,
sizeof
(
formatted_time
),
"%02d:%02d:%02d"
,
hours
,
minutes
,
seconds
);
return
String
(
formatted_time
);
}
}
// Based on https://github.com/PaulStoffregen/Time/blob/master/Time.cpp
// Based on https://github.com/PaulStoffregen/Time/blob/master/Time.cpp
void
NTPClient
::
getFormattedDate
(
char
*
formatted_date
,
unsigned
long
secs
)
{
void
NTPClient
::
getFormattedDate
(
char
*
formatted_date
,
unsigned
long
secs
)
{
unsigned
long
rawTime
=
(
secs
?
secs
:
this
->
getEpochTime
())
/
86400L
;
// in days
unsigned
long
rawTime
=
(
secs
?
secs
:
this
->
getEpochTime
())
/
86400L
;
// in days
unsigned
long
days
=
0
,
year
=
1970
;
unsigned
long
days
=
0
,
year
=
1970
;
uint8_t
month
;
uint8_t
month
;
...
@@ -187,8 +185,9 @@ void NTPClient::getFormattedDate(char * formatted_date, unsigned long secs) {
...
@@ -187,8 +185,9 @@ void NTPClient::getFormattedDate(char * formatted_date, unsigned long secs) {
month
++
;
// jan is month 1
month
++
;
// jan is month 1
rawTime
++
;
// first day is day 1
rawTime
++
;
// first day is day 1
snprintf
(
formatted_date
,
23
,
"%4lu-%02d-%02lu %s%+03d"
,
char
formatted_time
[
9
];
year
,
month
,
rawTime
,
this
->
getFormattedTime
(
secs
).
c_str
(),
this
->
_timeOffset
/
3600
);
this
->
getFormattedTime
(
formatted_time
,
secs
);
snprintf
(
formatted_date
,
23
,
"%4lu-%02d-%02lu %s%+03d"
,
year
,
month
,
rawTime
,
formatted_time
,
this
->
_timeOffset
/
3600
);
}
}
void
NTPClient
::
end
()
{
void
NTPClient
::
end
()
{
...
...
This diff is collapsed.
Click to expand it.
ampel-firmware/src/lib/NTPClient-master/NTPClient.h
+
1
-
1
View file @
8372df49
...
@@ -80,7 +80,7 @@ class NTPClient {
...
@@ -80,7 +80,7 @@ class NTPClient {
/**
/**
* @return secs argument (or 0 for current time) formatted like `hh:mm:ss`
* @return secs argument (or 0 for current time) formatted like `hh:mm:ss`
*/
*/
String
getFormattedTime
(
unsigned
long
secs
=
0
);
void
getFormattedTime
(
char
*
formatted_time
,
unsigned
long
secs
=
0
);
/**
/**
* @return time in seconds since Jan. 1, 1970
* @return time in seconds since Jan. 1, 1970
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets