Browse Source

cfg: move DEVICE and MANUFACTURER to functions

Avoids useless logs like this one:
https://travis-ci.com/github/mcspr/espurna-nightly-builder/jobs/316891026#L449
mcspr-patch-1
Maxim Prokhorov 4 years ago
committed by Max Prokhorov
parent
commit
2dcf1b2bd8
8 changed files with 56 additions and 29 deletions
  1. +2
    -1
      code/espurna/board.h
  2. +19
    -4
      code/espurna/board.ino
  3. +5
    -4
      code/espurna/homeassistant.ino
  4. +4
    -2
      code/espurna/ssdp.ino
  5. +2
    -2
      code/espurna/utils.h
  6. +17
    -7
      code/espurna/utils.ino
  7. +4
    -6
      code/espurna/ws.ino
  8. +3
    -3
      code/platformio.ini

+ 2
- 1
code/espurna/board.h View File

@ -6,7 +6,8 @@ BOARD MODULE
#pragma once
String getIdentifier();
const String& getChipId();
const String& getIdentifier();
String getEspurnaModules();
String getEspurnaOTAModules();


+ 19
- 4
code/espurna/board.ino View File

@ -303,10 +303,25 @@ PROGMEM const char espurna_sensors[] =
//--------------------------------------------------------------------------------
String getIdentifier() {
char buffer[20];
snprintf_P(buffer, sizeof(buffer), PSTR("%s-%06X"), APP_NAME, ESP.getChipId());
return String(buffer);
const String& getChipId() {
static String value;
if (!value.length()) {
char buffer[7];
value.reserve(sizeof(buffer));
snprintf_P(buffer, sizeof(buffer), PSTR("%06X"), ESP.getChipId());
value = buffer;
}
return value;
}
const String& getIdentifier() {
static String value;
if (!value.length()) {
value += APP_NAME;
value += '-';
value += getChipId();
}
return value;
}
String getEspurnaModules() {


+ 5
- 4
code/espurna/homeassistant.ino View File

@ -15,6 +15,7 @@ Copyright (C) 2017-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include "mqtt.h"
#include "relay.h"
#include "rpc.h"
#include "utils.h"
#include "ws.h"
bool _ha_enabled = false;
@ -78,8 +79,8 @@ struct ha_config_t {
deviceConfig.createNestedArray("identifiers").add(identifier.c_str());
deviceConfig["name"] = name.c_str();
deviceConfig["sw_version"] = version.c_str();
deviceConfig["manufacturer"] = MANUFACTURER;
deviceConfig["model"] = DEVICE;
deviceConfig["manufacturer"] = getDevice().c_str();
deviceConfig["model"] = getManufacturer().c_str();
}
ha_config_t() : ha_config_t(DEFAULT_BUFFER_SIZE) {}
@ -394,8 +395,8 @@ void _haSensorYaml(unsigned char index, JsonObject& root) {
void _haGetDeviceConfig(JsonObject& config) {
config.createNestedArray("identifiers").add(getIdentifier());
config["name"] = getSetting("desc", getSetting("hostname"));
config["manufacturer"] = MANUFACTURER;
config["model"] = DEVICE;
config["manufacturer"] = getManufacturer().c_str();
config["model"] = getDevice().c_str();
config["sw_version"] = String(APP_NAME) + " " + APP_VERSION + " (" + getCoreVersion() + ")";
}


+ 4
- 2
code/espurna/ssdp.ino View File

@ -12,6 +12,8 @@ https://github.com/esp8266/Arduino/issues/2283#issuecomment-299635604
#include <ESP8266SSDP.h>
#include "utils.h"
const char _ssdp_template[] PROGMEM =
"<?xml version=\"1.0\"?>"
"<root xmlns=\"urn:schemas-upnp-org:device-1-0\">"
@ -54,7 +56,7 @@ void ssdpSetup() {
APP_NAME, // modelName
APP_VERSION, // modelNumber
APP_WEBSITE, // modelURL
DEVICE_NAME, // manufacturer
getBoardName().c_str(), // manufacturer
"", // manufacturerURL
chipId // UUID
);
@ -71,7 +73,7 @@ void ssdpSetup() {
SSDP.setModelName(APP_NAME);
SSDP.setModelNumber(APP_VERSION);
SSDP.setModelURL(APP_WEBSITE);
SSDP.setManufacturer(DEVICE_NAME);
SSDP.setManufacturer(getBoardName());
SSDP.setManufacturerURL("");
SSDP.setURL("/");
SSDP.begin();


+ 2
- 2
code/espurna/utils.h View File

@ -18,9 +18,9 @@ extern "C" uint32_t _SPIFFS_end;
void setDefaultHostname();
void setBoardName();
String getBoardName();
String getAdminPass();
const String& getDevice();
const String& getManufacturer();
const String& getCoreVersion();
const String& getCoreRevision();


+ 17
- 7
code/espurna/utils.ino View File

@ -40,25 +40,35 @@ PROGMEM const char* const custom_reset_string[] = {
void setDefaultHostname() {
if (strlen(HOSTNAME) > 0) {
setSetting("hostname", HOSTNAME);
setSetting("hostname", F(HOSTNAME));
} else {
setSetting("hostname", getIdentifier());
}
}
void setBoardName() {
if (!isEspurnaCore()) {
setSetting("boardName", DEVICE_NAME);
}
const String& getDevice() {
static const String value(F(DEVICE));
return value;
}
const String& getManufacturer() {
static const String value(F(MANUFACTURER));
return value;
}
String getBoardName() {
static const String defaultValue(DEVICE_NAME);
static const String defaultValue(F(DEVICE_NAME));
return getSetting("boardName", defaultValue);
}
void setBoardName() {
if (!isEspurnaCore()) {
setSetting("boardName", F(DEVICE_NAME));
}
}
String getAdminPass() {
static const String defaultValue(ADMIN_PASS);
static const String defaultValue(F(ADMIN_PASS));
return getSetting("adminPass", defaultValue);
}


+ 4
- 6
code/espurna/ws.ino View File

@ -12,6 +12,7 @@ Copyright (C) 2016-2019 by Xose Pérez <xose dot perez at gmail dot com>
#include "system.h"
#include "web.h"
#include "utils.h"
#include "ws.h"
#include "ws_internal.h"
@ -387,9 +388,6 @@ bool _wsOnKeyCheck(const char * key, JsonVariant& value) {
}
void _wsOnConnected(JsonObject& root) {
char chipid[7];
snprintf_P(chipid, sizeof(chipid), PSTR("%06X"), ESP.getChipId());
root["webMode"] = WEB_MODE_NORMAL;
root["app_name"] = APP_NAME;
@ -398,12 +396,12 @@ void _wsOnConnected(JsonObject& root) {
#if defined(APP_REVISION)
root["app_revision"] = APP_REVISION;
#endif
root["manufacturer"] = MANUFACTURER;
root["chipid"] = String(chipid);
root["device"] = getDevice().c_str();
root["manufacturer"] = getManufacturer().c_str();
root["chipid"] = getChipId().c_str();
root["mac"] = WiFi.macAddress();
root["bssid"] = WiFi.BSSIDstr();
root["channel"] = WiFi.channel();
root["device"] = DEVICE;
root["hostname"] = getSetting("hostname");
root["desc"] = getSetting("desc");
root["network"] = getNetwork();


+ 3
- 3
code/platformio.ini View File

@ -280,15 +280,15 @@ build_flags = ${common.build_flags} -DJUSTWIFI_ENABLE_WPS=1
[env:espurna-core-webui-1MB]
extends = env:esp8266-1m-base
src_build_flags = -DESPURNA_CORE_WEB
src_build_flags = -DESPURNA_CORE_WEBUI
[env:espurna-core-webui-2MB]
extends = env:esp8266-2m-base
src_build_flags = -DESPURNA_CORE_WEB
src_build_flags = -DESPURNA_CORE_WEBUI
[env:espurna-core-webui-4MB]
extends = env:esp8266-4m-base
src_build_flags = -DESPURNA_CORE_WEB
src_build_flags = -DESPURNA_CORE_WEBUI
# ------------------------------------------------------------------------------
# DEVELOPMENT BOARDS


Loading…
Cancel
Save