Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
co2ampel
ampel-firmware
Commits
318eb864
Commit
318eb864
authored
Apr 20, 2021
by
Eric Duminil
Browse files
Local ip as char[]
parent
d86de0ab
Changes
5
Hide whitespace changes
Inline
Side-by-side
ampel-firmware/ampel-firmware.ino
View file @
318eb864
...
...
@@ -92,7 +92,7 @@ void setup() {
#endif
#ifdef AMPEL_WIFI
WiFiC
onnect
(
ampel
.
sensorId
);
wifi
::
c
onnect
(
ampel
.
sensorId
);
Serial
.
print
(
F
(
"WiFi - Status: "
));
Serial
.
println
(
WiFi
.
status
());
...
...
ampel-firmware/mqtt.cpp
View file @
318eb864
...
...
@@ -157,7 +157,7 @@ namespace mqtt {
char
payload
[
75
];
// Should be enough for info json...
const
char
*
json_info_format
=
PSTR
(
"{
\"
local_ip
\"
:
\"
%s
\"
,
\"
ssid
\"
:
\"
%s
\"
}"
);
snprintf
(
payload
,
sizeof
(
payload
),
json_info_format
,
WiFi
.
localIP
().
toString
().
c_str
(),
WiFi
.
SSID
().
c_str
()
);
snprintf
(
payload
,
sizeof
(
payload
),
json_info_format
,
wifi
::
local_ip
,
WIFI_SSID
);
mqttClient
.
publish
(
info_topic
,
payload
);
}
...
...
ampel-firmware/web_server.cpp
View file @
318eb864
...
...
@@ -212,7 +212,7 @@ namespace web_server {
char
content
[
2000
];
// Update if needed
// INFO - Header size : 1767 - Body size : 1812 - Script size : 1909
snprintf_P
(
content
,
sizeof
(
content
),
header_template
,
sensor
::
co2
,
ampel
.
sensorId
,
WiFi
.
localIP
().
toString
().
c_str
()
snprintf_P
(
content
,
sizeof
(
content
),
header_template
,
sensor
::
co2
,
ampel
.
sensorId
,
wifi
::
local_ip
#ifdef AMPEL_CSV
,
csv_writer
::
filename
#endif
...
...
@@ -237,8 +237,7 @@ namespace web_server {
config
::
lorawan_sending_interval
,
#endif
config
::
temperature_offset
,
config
::
auto_calibrate_sensor
?
"Yes"
:
"No"
,
ampel
.
sensorId
,
ampel
.
sensorId
,
WiFi
.
localIP
().
toString
().
c_str
(),
WiFi
.
localIP
().
toString
().
c_str
(),
get_free_heap_size
(),
ampel
.
max_loop_duration
,
ampel
.
board
,
dd
,
hh
,
mm
,
ss
);
wifi
::
local_ip
,
wifi
::
local_ip
,
get_free_heap_size
(),
ampel
.
max_loop_duration
,
ampel
.
board
,
dd
,
hh
,
mm
,
ss
);
Serial
.
print
(
F
(
" - Body size : "
));
http
.
sendContent
(
content
);
...
...
ampel-firmware/wifi_util.cpp
View file @
318eb864
...
...
@@ -12,34 +12,39 @@ namespace config {
#endif
}
// Initialize Wi-Fi
void
WiFiConnect
(
const
char
*
hostname
)
{
//NOTE: WiFi Multi could allow multiple SSID and passwords.
WiFi
.
persistent
(
false
);
// Don't write user & password to Flash.
WiFi
.
mode
(
WIFI_STA
);
// Set ESP to be a WiFi-client only
namespace
wifi
{
char
local_ip
[
16
];
// "255.255.255.255\0"
// Initialize Wi-Fi
void
connect
(
const
char
*
hostname
)
{
//NOTE: WiFi Multi could allow multiple SSID and passwords.
WiFi
.
persistent
(
false
);
// Don't write user & password to Flash.
WiFi
.
mode
(
WIFI_STA
);
// Set ESP to be a WiFi-client only
#if defined(ESP8266)
WiFi
.
hostname
(
hostname
);
#elif defined(ESP32)
WiFi
.
setHostname
(
hostname
);
WiFi
.
setHostname
(
hostname
);
#endif
Serial
.
print
(
F
(
"WiFi - Connecting to "
));
Serial
.
println
(
config
::
wifi_ssid
);
WiFi
.
begin
(
config
::
wifi_ssid
,
config
::
wifi_password
);
Serial
.
print
(
F
(
"WiFi - Connecting to "
));
Serial
.
println
(
config
::
wifi_ssid
);
WiFi
.
begin
(
config
::
wifi_ssid
,
config
::
wifi_password
);
// Wait for connection, at most wifi_timeout seconds
for
(
int
i
=
0
;
i
<=
config
::
wifi_timeout
&&
(
WiFi
.
status
()
!=
WL_CONNECTED
);
i
++
)
{
led_effects
::
showRainbowWheel
();
Serial
.
print
(
"."
);
}
if
(
WiFi
.
status
()
==
WL_CONNECTED
)
{
led_effects
::
showKITTWheel
(
color
::
green
);
Serial
.
println
();
Serial
.
print
(
F
(
"WiFi - Connected! IP address: "
));
Serial
.
println
(
WiFi
.
localIP
());
}
else
{
//TODO: Allow sensor to work as an Access Point, in order to define SSID & password?
led_effects
::
showKITTWheel
(
color
::
red
);
Serial
.
println
(
F
(
"Connection to WiFi failed"
));
// Wait for connection, at most wifi_timeout seconds
for
(
int
i
=
0
;
i
<=
config
::
wifi_timeout
&&
(
WiFi
.
status
()
!=
WL_CONNECTED
);
i
++
)
{
led_effects
::
showRainbowWheel
();
Serial
.
print
(
"."
);
}
if
(
WiFi
.
status
()
==
WL_CONNECTED
)
{
led_effects
::
showKITTWheel
(
color
::
green
);
Serial
.
println
();
Serial
.
print
(
F
(
"WiFi - Connected! IP address: "
));
IPAddress
address
=
WiFi
.
localIP
();
snprintf
(
local_ip
,
sizeof
(
local_ip
),
"%d.%d.%d.%d"
,
address
[
0
],
address
[
1
],
address
[
2
],
address
[
3
]);
Serial
.
println
(
local_ip
);
}
else
{
//TODO: Allow sensor to work as an Access Point, in order to define SSID & password?
led_effects
::
showKITTWheel
(
color
::
red
);
Serial
.
println
(
F
(
"Connection to WiFi failed"
));
}
}
}
ampel-firmware/wifi_util.h
View file @
318eb864
...
...
@@ -5,6 +5,9 @@
#include
"util.h"
#include
"led_effects.h"
void
WiFiConnect
(
const
char
*
hostname
);
namespace
wifi
{
extern
char
local_ip
[];
void
connect
(
const
char
*
hostname
);
}
#endif
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