Skip to content

Commit

Permalink
Merge branch 'wifi_disable'
Browse files Browse the repository at this point in the history
  • Loading branch information
dewenni committed Jan 1, 2025
2 parents 5822d71 + f8655fc commit 65d3369
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 67 deletions.
50 changes: 36 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,20 +317,6 @@ If everything done correct, all shutters should work like before. If not, some s

# MQTT

## additional information's (read only)

status information about WiFi:

```text
Topic: ESP32-Jarolift-Controller/wifi = {
"status":"online",
"rssi":"-50",
"signal":"90",
"ip":"192.168.1.1",
"date-time":"01.01.2022 - 10:20:30"
}
```

## Commands

### Shutter
Expand Down Expand Up @@ -420,10 +406,46 @@ payload: {0b0000000000010101, 0x15, 21}
```

## Status

The controller will also send a status **based on the commands**.

> [!IMPORTANT]
> But it is important to know, that this status is only a "copy of the received command".
> It does not correspond to the real status of the roller shutter, because unfortunately the roller shutter itself does not have a status that could be analyzed. So if the roller shutter is operated via the original remote control, for example, or via local operation, or is stopped during movement, then this status is no longer correct!
```text
Status: Shutter OPEN
topic: ../status/shutter/1 ... status/shutter/16
payload: {0}
Status: Shutter CLOSED
topic: ../status/shutter/1 ... status/shutter/16
payload: {100}
Status: Shutter SHADE
topic: ../status/shutter/1 ... status/shutter/16
payload: {90}
```

> [!NOTE]
> < ../ > is the placeholder for the MQTT topic which is specified in the settings.
## additional information's (read only)

status information about WiFi:

```text
Topic: ESP32-Jarolift-Controller/wifi = {
"status":"online",
"rssi":"-50",
"signal":"90",
"ip":"192.168.1.1",
"date-time":"01.01.2022 - 10:20:30"
}
```

## Home Assistant

MQTT discovery for Home Assistant makes it easy to get all values in Home Assistant.
Expand Down
50 changes: 36 additions & 14 deletions README_DE.md
Original file line number Diff line number Diff line change
Expand Up @@ -316,20 +316,6 @@ Wenn alles richtig gemacht wurde, sollten alle Rollläden wie vorher funktionier

# MQTT

### zusätzliche Informationen (nur lesen)

Statusinformationen über WiFi:

```text
Topic: ESP32-Jarolift-Controller/wifi = {
"status":"online",
"rssi":"-50",
"signal":"90",
"ip":"192.168.1.1",
"date-time":"01.01.2022 - 10:20:30"
}
```

## Kommandos

### Rolläden
Expand Down Expand Up @@ -419,9 +405,45 @@ payload: {0b0000000000010101, 0x15, 21}
```

## Status

Der Controller sendet auch einen Status, **basierend auf den empfangenen Kommandos.**

> [!IMPORTANT]
> Aber es ist wichtig zu beachten, dass dieser Status nicht dem tatsächlichen Zustand des Rollladens entspricht, denn leider sendet der Rolladen selbst keinen Status den man dazu auswerten könnte. Wenn also der Rolladen z.B. über die originale Fernbedienung bedient wird oder über eine vor Ort Bedienung, oder während der Bewegung gestoppt wird, dann stimmt dieser Status hier nicht mehr!
```text
Status: Rolladen OFFEN
topic: ../status/shutter/1 ... status/shutter/16
payload: {0}
Status: Rolladen GESCHLOSSEN
topic: ../status/shutter/1 ... status/shutter/16
payload: {100}
Status: Rolladen SCHATTEN
topic: ../status/shutter/1 ... status/shutter/16
payload: {90}
```

> [!NOTE]
> < ../ > ist der Platzhalter für das MQTT-Topic, das in den Einstellungen angegeben ist.
## zusätzliche Informationen (nur lesen)

Statusinformationen über WiFi:

```text
Topic: ESP32-Jarolift-Controller/wifi = {
"status":"online",
"rssi":"-50",
"signal":"90",
"ip":"192.168.1.1",
"date-time":"01.01.2022 - 10:20:30"
}
```

## Home Assistant

MQTT Discovery für Home Assistant macht es einfach, alle Werte in Home Assistant zu erhalten.
Expand Down
1 change: 1 addition & 0 deletions include/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct s_cfg_jaro {
};

struct s_cfg_wifi {
bool enable = false;
char ssid[128];
char password[128];
char hostname[128];
Expand Down
22 changes: 6 additions & 16 deletions src/basics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,32 +113,23 @@ void setupWiFi() {

if (setupMode) {
// start Accesspoint for initial setup
IPAddress ip(192, 168, 4, 1);
IPAddress gateway(192, 168, 4, 1);
IPAddress subnet(255, 255, 255, 0);
WiFi.softAPConfig(ip, gateway, subnet);
WiFi.softAPConfig(IPAddress(192, 168, 4, 1), IPAddress(192, 168, 4, 1), IPAddress(255, 255, 255, 0));
WiFi.softAP("ESP32-Jarolift");
MY_LOGI(TAG, "\n! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !\n");
MY_LOGI(TAG, "> WiFi Mode: AccessPoint <");
MY_LOGI(TAG, "1. connect your device to SSID: ESP32-Jarolift");
MY_LOGI(TAG, "2. open Browser and go to Address: http://192.168.4.1");
MY_LOGI(TAG, "\n! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !\n");
} else {

} else if (config.wifi.enable) {

// setup callback function
WiFi.onEvent(onWiFiStationConnected, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_CONNECTED);
WiFi.onEvent(onWiFiGotIP, WiFiEvent_t::ARDUINO_EVENT_WIFI_STA_GOT_IP);

// manual IP-Settings
if (config.wifi.static_ip) {
// manual IP-Settings
IPAddress manIp;
manIp.fromString(config.wifi.ipaddress);
IPAddress manSubnet;
manSubnet.fromString(config.wifi.subnet);
IPAddress manGateway;
manGateway.fromString(config.wifi.gateway);
IPAddress manDns;
manDns.fromString(config.wifi.dns);
WiFi.config(manIp, manGateway, manSubnet, manDns);
WiFi.config(IPAddress(config.wifi.ipaddress), IPAddress(config.wifi.gateway), IPAddress(config.wifi.subnet), IPAddress(config.wifi.dns));
}

// connect to configured wifi AP
Expand Down Expand Up @@ -228,7 +219,6 @@ void basicSetup() {

// NTP
ntpSetup();

}

/**
Expand Down
27 changes: 22 additions & 5 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ static const char *TAG = "CFG"; // LOG TAG
void configGPIO();
void configInitValue();
void checkGPIO();
void configFinalCheck();

/**
* *******************************************************************
Expand All @@ -39,6 +40,8 @@ void configSetup() {
checkGPIO();
// gpio settings
configGPIO();
// check final settings
configFinalCheck();
}

/**
Expand Down Expand Up @@ -229,6 +232,7 @@ void configInitValue() {
config.log.level = 4;

// WiFi
config.wifi.enable = true;
snprintf(config.wifi.hostname, sizeof(config.wifi.hostname), "ESP32-Jarolift");

// MQTT
Expand Down Expand Up @@ -267,6 +271,7 @@ void configSaveToFile() {

doc["lang"] = (config.lang);

doc["wifi"]["enable"] = config.wifi.enable;
doc["wifi"]["ssid"] = config.wifi.ssid;
doc["wifi"]["password"] = config.wifi.password;
doc["wifi"]["hostname"] = config.wifi.hostname;
Expand Down Expand Up @@ -398,7 +403,7 @@ void configLoadFromFile() {
} else {

config.lang = doc["lang"];

config.wifi.enable = doc["wifi"]["enable"];
EspStrUtil::readJSONstring(config.wifi.ssid, sizeof(config.wifi.ssid), doc["wifi"]["ssid"]);
EspStrUtil::readJSONstring(config.wifi.password, sizeof(config.wifi.password), doc["wifi"]["password"]);
EspStrUtil::readJSONstring(config.wifi.hostname, sizeof(config.wifi.hostname), doc["wifi"]["hostname"]);
Expand Down Expand Up @@ -480,18 +485,30 @@ void configLoadFromFile() {
}
}


file.close(); // Close the file (Curiously, File's destructor doesn't close the file)
configHashInit(); // init hash value

}

void configFinalCheck(){

// check network settings
if (strlen(config.wifi.ssid) == 0) {
// no valid wifi setting => start AP-Mode
MY_LOGW(TAG, "no valid wifi SSID set => enter SetupMode and start AP-Mode");
setupMode = true;
} else if (config.wifi.enable == false && config.eth.enable == false) {
// no network enabled => start AP-Mode
MY_LOGW(TAG, "WiFi and ETH disabled => enter SetupMode and start AP-Mode");
setupMode = true;
}

file.close(); // Close the file (Curiously, File's destructor doesn't close the file)
configHashInit(); // init hash value

// check log level
if (config.jaro.learn_mode == 0) {
config.jaro.learn_mode = 4; // ESP_LOG_DEBUG
}
setLogLevel(config.log.level);
}


}
7 changes: 6 additions & 1 deletion src/message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,13 @@ void messageCyclic() {

// send cyclic infos
if (mainTimer.cycleTrigger(10000) && !setupMode && mqttIsConnected()) {
sendWiFiInfo();

sendSysInfo();

if (config.wifi.enable) {
sendWiFiInfo();
}

if (config.eth.enable) {
sendETHInfo();
}
Expand Down
3 changes: 3 additions & 0 deletions src/webUIcallback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ void webCallback(const char *elementId, const char *value) {
// ------------------------------------------------------------------

// WiFi
if (strcmp(elementId, "cfg_wifi_enable") == 0) {
config.wifi.enable = EspStrUtil::stringToBool(value);
}
if (strcmp(elementId, "cfg_wifi_hostname") == 0) {
snprintf(config.wifi.hostname, sizeof(config.wifi.hostname), value);
}
Expand Down
43 changes: 26 additions & 17 deletions src/webUIupdates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,28 +96,37 @@ void updateSystemInfoElements() {

initJsonBuffer(jsonDoc);

// Network information
addJson(jsonDoc, "p09_wifi_ip", wifi.ipAddress);
snprintf(tmpMessage, sizeof(tmpMessage), "%i %%", wifi.signal);
addJson(jsonDoc, "p09_wifi_signal", tmpMessage);
snprintf(tmpMessage, sizeof(tmpMessage), "%ld dbm", wifi.rssi);
addJson(jsonDoc, "p09_wifi_rssi", tmpMessage);

if (!WiFi.isConnected()) {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_nok");
} else if (wifi.rssi < -80) {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_1");
} else if (wifi.rssi < -70) {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_2");
} else if (wifi.rssi < -60) {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_3");
// WiFi information
if (config.eth.enable) {
addJson(jsonDoc, "p09_wifi_ip", wifi.ipAddress);
snprintf(tmpMessage, sizeof(tmpMessage), "%i %%", wifi.signal);
addJson(jsonDoc, "p09_wifi_signal", tmpMessage);
snprintf(tmpMessage, sizeof(tmpMessage), "%ld dbm", wifi.rssi);
addJson(jsonDoc, "p09_wifi_rssi", tmpMessage);

if (!WiFi.isConnected()) {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_nok");
} else if (wifi.rssi < -80) {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_1");
} else if (wifi.rssi < -70) {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_2");
} else if (wifi.rssi < -60) {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_3");
} else {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_4");
}

} else {
addJson(jsonDoc, "p00_wifi_icon", "i_wifi_4");
addJson(jsonDoc, "p00_wifi_icon", "");
addJson(jsonDoc, "p09_wifi_ip", "-.-.-.-");
addJson(jsonDoc, "p09_wifi_signal", "0");
addJson(jsonDoc, "p09_wifi_rssi", "0 dbm");
}

addJson(jsonDoc, "p09_eth_ip", strlen(eth.ipAddress) ? eth.ipAddress : "-.-.-.-");
addJson(jsonDoc, "p09_eth_status", eth.connected ? WEB_TXT::CONNECTED[config.lang] : WEB_TXT::NOT_CONNECTED[config.lang]);

// ETH information
if (config.eth.enable) {
if (eth.connected) {
addJson(jsonDoc, "p00_eth_icon", "i_eth_ok");
Expand Down Expand Up @@ -378,7 +387,7 @@ void webUIupdates() {
processGitHubVersion();
// perform GitHub update
processGitHubUpdate();

// update webUI Logger
if (webLogRefreshActive()) {
webReadLogBufferCyclic();
Expand Down
11 changes: 11 additions & 0 deletions web/html/12_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@
<!-- WLAN -->
<details>
<summary data-i18n="wifi"></summary>
<div class="section-header">
<label for="wifi_enable" data-i18n="activate"></label>
<div class="switch-container">
<input
name="wifi_enable"
type="checkbox"
role="switch"
id="cfg_wifi_enable" />
</div>
</div>
<br />
<label for="wifi_hostname" data-i18n="hostname"></label>
<input type="text" id="cfg_wifi_hostname" name="wifi_hostname" />
<label for="wifi_ssid" data-i18n="ssid"></label>
Expand Down

0 comments on commit 65d3369

Please sign in to comment.