Skip to content

Commit

Permalink
Merge pull request #1615 from proddy/dev
Browse files Browse the repository at this point in the history
fix WiFi TxPower, plus a ton of other refactoring
  • Loading branch information
proddy authored Feb 14, 2024
2 parents 57296e5 + 944d86b commit 8ebc552
Show file tree
Hide file tree
Showing 110 changed files with 1,967 additions and 1,947 deletions.
14 changes: 5 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
.vscode/c_cpp_properties.json
.vscode/extensions.json
.vscode/launch.json
# .vscode/settings.json
.vscode/settings.json

# c++ compiling
.clang_complete
Expand All @@ -12,11 +12,11 @@ cppcheck.out.xml
# platformio
.pio
pio_local.ini
*_old

# OS specific
.DS_Store
*Thumbs.db
emsesp

# web specfic
build/
Expand All @@ -43,7 +43,7 @@ interface/analyse.html
test.sh
scripts/run.sh
scripts/__pycache__
/scripts/stackdmp.txt
scripts/stackdmp.txt

# i18n generated files
interface/src/i18n/i18n-react.tsx
Expand All @@ -57,9 +57,5 @@ interface/src/i18n/i18n-util.async.ts
sonar/
bw-output/

# entity dump results
# dump_entities.csv
# dump_entities.xls*

*_old

# testing
emsesp
7 changes: 7 additions & 0 deletions CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

## **IMPORTANT! BREAKING CHANGES**

- The Wifi Tx Power setting in Network Settings will be reset to Auto

## Added

- thermostat boost mode and boost time [#1446](https://github.com/emsesp/EMS-ESP32/issues/1446)
Expand All @@ -28,9 +30,14 @@
- MQTT autodiscovery in Domoticz not working [#1360](https://github.com/emsesp/EMS-ESP32/issues/1528)
- dhw comfort for new ems+, [#1495](https://github.com/emsesp/EMS-ESP32/issues/1495)
- added writeable icon to Web's Custom Entity page for each entity shown in the table
- Wifi Tx Power not adjusted [#1614](https://github.com/emsesp/EMS-ESP32/issues/1614)
- MQTT discovery of custom entity doesn't consider type of data [#1587](https://github.com/emsesp/EMS-ESP32/issues/1587)
- WiFi TxPower wasn't correctly used. Added an 'Auto' setting, which is the default.

## Changed

- HA don't set entity_category to Diagnostic/Configuration for EMS entities [#1459](https://github.com/emsesp/EMS-ESP32/discussions/1459)
- upgraded ArduinoJson to 7.0.0 #1538 and then 7.0.2
- small changes to the API for analog and temperature sensors
- Length of mqtt Broker adress [#1619](https://github.com/emsesp/EMS-ESP32/issues/1619)
- C++ optimizations - see <https://github.com/emsesp/EMS-ESP32/pull/1615>
1 change: 0 additions & 1 deletion factory_settings.ini
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ build_flags =
-D FACTORY_MQTT_PORT=1883
-D FACTORY_MQTT_USERNAME=\"\"
-D FACTORY_MQTT_PASSWORD=\"\"
-D FACTORY_MQTT_CLIENT_ID=\"ems-esp\"
-D FACTORY_MQTT_KEEP_ALIVE=60
-D FACTORY_MQTT_CLEAN_SESSION=false
-D FACTORY_MQTT_MAX_TOPIC_LENGTH=128
Expand Down
4 changes: 2 additions & 2 deletions interface/.eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
},
"extends": [
"eslint:recommended",
"airbnb/hooks",
"airbnb-typescript",
// "airbnb/hooks",
// "airbnb-typescript",
"plugin:react/recommended",
"plugin:react/jsx-runtime",
"plugin:@typescript-eslint/recommended",
Expand Down
10 changes: 4 additions & 6 deletions interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
"@babel/core": "^7.23.9",
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.15.9",
"@mui/material": "^5.15.9",
"@mui/icons-material": "^5.15.10",
"@mui/material": "^5.15.10",
"@table-library/react-table-library": "4.1.7",
"@types/imagemin": "^8.0.5",
"@types/lodash-es": "^4.17.12",
Expand All @@ -54,12 +54,10 @@
"devDependencies": {
"@preact/compat": "^17.1.2",
"@preact/preset-vite": "^2.8.1",
"@typescript-eslint/eslint-plugin": "^6.21.0",
"@typescript-eslint/parser": "^6.21.0",
"@typescript-eslint/eslint-plugin": "^7.0.1",
"@typescript-eslint/parser": "^7.0.1",
"concurrently": "^8.2.2",
"eslint": "^8.56.0",
"eslint-config-airbnb": "^19.0.4",
"eslint-config-airbnb-typescript": "^17.1.0",
"eslint-config-prettier": "^9.1.0",
"eslint-import-resolver-typescript": "^3.6.1",
"eslint-plugin-autofix": "^1.1.0",
Expand Down
20 changes: 17 additions & 3 deletions interface/progmem-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { readdirSync, existsSync, unlinkSync, readFileSync, createWriteStream }
import { resolve, relative, sep } from 'path';
import zlib from 'zlib';
import mime from 'mime-types';
import crypto from 'crypto';

const ARDUINO_INCLUDES = '#include <Arduino.h>\n\n';
const INDENT = ' ';
Expand All @@ -11,14 +12,17 @@ const bytesPerLine = 20;
var totalSize = 0;

const generateWWWClass = () =>
`typedef std::function<void(const String& uri, const String& contentType, const uint8_t * content, size_t len)> RouteRegistrationHandler;
`typedef std::function<void(const String& uri, const String& contentType, const uint8_t * content, size_t len, const String& hash)> RouteRegistrationHandler;
// Total size is ${totalSize} bytes
class WWWData {
${indent}public:
${indent.repeat(2)}static void registerRoutes(RouteRegistrationHandler handler) {
${fileInfo
.map((file) => `${indent.repeat(3)}handler("${file.uri}", "${file.mimeType}", ${file.variable}, ${file.size});`)
.map(
(file) =>
`${indent.repeat(3)}handler("${file.uri}", "${file.mimeType}", ${file.variable}, ${file.size}, "${file.hash}");`
)
.join('\n')}
${indent.repeat(2)}}
};
Expand Down Expand Up @@ -50,6 +54,12 @@ const writeFile = (relativeFilePath, buffer) => {
writeStream.write('const uint8_t ' + variable + '[] = {');
// const zipBuffer = zlib.brotliCompressSync(buffer, { quality: 1 });
const zipBuffer = zlib.gzipSync(buffer, { level: 9 });

// create sha
const hashSum = crypto.createHash('sha256');
hashSum.update(zipBuffer);
const hash = hashSum.digest('hex');

zipBuffer.forEach((b) => {
if (!(size % bytesPerLine)) {
writeStream.write('\n');
Expand All @@ -58,15 +68,19 @@ const writeFile = (relativeFilePath, buffer) => {
writeStream.write('0x' + ('00' + b.toString(16).toUpperCase()).slice(-2) + ',');
size++;
});

if (size % bytesPerLine) {
writeStream.write('\n');
}

writeStream.write('};\n\n');

fileInfo.push({
uri: '/' + relativeFilePath.replace(sep, '/'),
mimeType,
variable,
size
size,
hash
});

// console.log(relativeFilePath + ' (size ' + size + ' bytes)');
Expand Down
1 change: 1 addition & 0 deletions interface/src/framework/mqtt/MqttSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ const MqttSettingsForm: FC = () => {
name="host"
label={LL.ADDRESS_OF(LL.BROKER())}
fullWidth
multiline
variant="outlined"
value={data.host}
onChange={updateFormValue}
Expand Down
31 changes: 19 additions & 12 deletions interface/src/framework/network/NetworkSettingsForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import {
ListItemSecondaryAction,
ListItemText,
Typography,
InputAdornment,
TextField
TextField,
MenuItem
} from '@mui/material';
// eslint-disable-next-line import/named
import { updateState, useRequest } from 'alova';
Expand All @@ -43,7 +43,7 @@ import {
} from 'components';
import { useI18nContext } from 'i18n/i18n-react';

import { numberValue, updateValueDirty, useRest } from 'utils';
import { updateValueDirty, useRest } from 'utils';

import { validate } from 'validators';
import { createNetworkSettingsValidator } from 'validators/network';
Expand Down Expand Up @@ -88,7 +88,7 @@ const WiFiSettingsForm: FC = () => {
static_ip_config: false,
enableIPv6: false,
bandwidth20: false,
tx_power: 20,
tx_power: 0,
nosleep: false,
enableMDNS: true,
enableCORS: false,
Expand Down Expand Up @@ -196,20 +196,27 @@ const WiFiSettingsForm: FC = () => {
margin="normal"
/>
)}
<ValidatedTextField
fieldErrors={fieldErrors}
<TextField
name="tx_power"
label={LL.TX_POWER()}
InputProps={{
endAdornment: <InputAdornment position="end">dBm</InputAdornment>
}}
fullWidth
variant="outlined"
value={numberValue(data.tx_power)}
value={data.tx_power}
onChange={updateFormValue}
type="number"
margin="normal"
/>
select
>
<MenuItem value={0}>Auto</MenuItem>
<MenuItem value={78}>19.5 dBm</MenuItem>
<MenuItem value={76}>19 dBm</MenuItem>
<MenuItem value={74}>18.5 dBm</MenuItem>
<MenuItem value={68}>17 dBm</MenuItem>
<MenuItem value={60}>15 dBm</MenuItem>
<MenuItem value={52}>13 dBm</MenuItem>
<MenuItem value={44}>11 dBm</MenuItem>
<MenuItem value={34}>8.5 dBm</MenuItem>
<MenuItem value={28}>7 dBm</MenuItem>
</TextField>
<BlockFormControlLabel
control={<Checkbox name="nosleep" checked={data.nosleep} onChange={updateFormValue} />}
label={LL.NETWORK_DISABLE_SLEEP()}
Expand Down
6 changes: 1 addition & 5 deletions interface/src/validators/network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,5 @@ export const createNetworkSettingsValidator = (networkSettings: NetworkSettings)
subnet_mask: [{ required: true, message: 'Subnet mask is required' }, IP_ADDRESS_VALIDATOR],
dns_ip_1: IP_ADDRESS_VALIDATOR,
dns_ip_2: IP_ADDRESS_VALIDATOR
}),
tx_power: [
{ required: true, message: 'Tx Power is required' },
{ type: 'number', min: 0, max: 20, message: 'Tx Power must be between 0 and 20dBm' }
]
})
});
6 changes: 3 additions & 3 deletions interface/src/validators/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export const IP_ADDRESS_VALIDATOR = {
}
};

const HOSTNAME_LENGTH_REGEXP = /^.{0,63}$/;
const HOSTNAME_LENGTH_REGEXP = /^.{0,200}$/;
const HOSTNAME_PATTERN_REGEXP =
/^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$/;

Expand All @@ -42,7 +42,7 @@ const isValidHostname = (value: string) => HOSTNAME_LENGTH_REGEXP.test(value) &&
export const HOSTNAME_VALIDATOR = {
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
if (value && !isValidHostname(value)) {
callback('Must be a valid hostname of up to 63 characters');
callback('Must be a valid hostname');
} else {
callback();
}
Expand All @@ -52,7 +52,7 @@ export const HOSTNAME_VALIDATOR = {
export const IP_OR_HOSTNAME_VALIDATOR = {
validator(rule: InternalRuleItem, value: string, callback: (error?: string) => void) {
if (value && !(isValidIpAddress(value) || isValidHostname(value))) {
callback('Must be a valid IP address or hostname of up to 63 characters');
callback('Must be a valid IP address or hostname');
} else {
callback();
}
Expand Down
Loading

0 comments on commit 8ebc552

Please sign in to comment.