Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1.12.0 #834

Merged
merged 3 commits into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@
.vscode/launch.json
/test/remote/settings.json
/test/remote/espmh.env
lib/Environment/wifi_credentials.h
lib/Environment/wifi_credentials.h
.idea
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ Both modules are SPI devices and should be connected to the standard SPI pins on
<img src="https://user-images.githubusercontent.com/40266/47967518-67556f00-e05e-11e8-857d-1173a9da955c.png" align="left" width="32%" />
<img src="https://user-images.githubusercontent.com/40266/47967520-691f3280-e05e-11e8-838a-83706df2edb0.png" align="left" width="22%" />

NodeMCU | Radio | Color
-- | -- | --
GND | GND | Black
3V3 | VCC | Red
D2 (GPIO4) | CE | Orange
D8 (GPIO15) | CSN/CS | Yellow
D5 (GPIO14) | SCK | Green
D7 (GPIO13) | MOSI | Blue
D6 (GPIO12) | MISO | Violet
NodeMCU (Esp8266) | Esp32 | Radio | Color
--------- |--------------|----| --
GND | GND | GND | Black
3V3 | 3V3 | VCC | Red
D2 (GPIO4) | D4 (GPIO4) | CE | Orange
D8 (GPIO15) | D5 (GPIO5) | CSN/CS | Yellow
D5 (GPIO14) | D18 (GPIO18) | SCK | Green
D7 (GPIO13) | D23 (GPIO23) | MOSI | Blue
D6 (GPIO12) | D19 (GPIO19) | MISO | Violet

_Image source: [MySensors.org](https://mysensors.org)_

Expand Down
17 changes: 17 additions & 0 deletions lib/ESP/ESPId.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <ESPId.h>

#ifdef ESP8266
uint32_t getESPId()
{
return ESP.getChipId();
}
#elif ESP32
uint32_t getESPId()
{
uint32_t id = 0;
for(int i=0; i<17; i=i+8) {
id |= ((ESP.getEfuseMac() >> (40 - i)) & 0xff) << i;
}
return id;
}
#endif
8 changes: 8 additions & 0 deletions lib/ESP/ESPId.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef _ESPID_H
#define _ESPID_H

#include <Esp.h>

uint32_t getESPId();

#endif
29 changes: 20 additions & 9 deletions lib/MQTT/HomeAssistantDiscoveryClient.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#include <HomeAssistantDiscoveryClient.h>
#include <MiLightCommands.h>
#include <Units.h>
#include <ESP8266WiFi.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#elif ESP32
#include <WiFi.h>
#endif

HomeAssistantDiscoveryClient::HomeAssistantDiscoveryClient(Settings& settings, MqttClient* mqttClient)
: settings(settings)
Expand Down Expand Up @@ -40,7 +44,7 @@ void HomeAssistantDiscoveryClient::addConfig(const char* alias, const BulbId& bu

// Unique ID for this device + alias combo
char uniqueIdBuffer[30];
snprintf_P(uniqueIdBuffer, sizeof(uniqueIdBuffer), PSTR("%X-%s"), ESP.getChipId(), alias);
snprintf_P(uniqueIdBuffer, sizeof(uniqueIdBuffer), PSTR("%X-%s"), getESPId(), alias);

// String to ID the firmware version
char fwVersion[100];
Expand All @@ -64,7 +68,7 @@ void HomeAssistantDiscoveryClient::addConfig(const char* alias, const BulbId& bu
deviceMetadata[F("sw")] = fwVersion;
deviceMetadata[F("mf")] = F("espressif");
deviceMetadata[F("mdl")] = QUOTE(FIRMWARE_VARIANT);
deviceMetadata[F("identifiers")] = String(ESP.getChipId());
deviceMetadata[F("identifiers")] = String(getESPId());
deviceMetadata[F("cu")] = deviceUrl;

// HomeAssistant only supports simple client availability
Expand All @@ -78,9 +82,6 @@ void HomeAssistantDiscoveryClient::addConfig(const char* alias, const BulbId& bu
}

// Configure supported commands based on the bulb type

// All supported bulbs support brightness and night mode
config[GroupStateFieldNames::BRIGHTNESS] = true;
config[GroupStateFieldNames::EFFECT] = true;

// effect_list
Expand Down Expand Up @@ -110,18 +111,28 @@ void HomeAssistantDiscoveryClient::addConfig(const char* alias, const BulbId& bu
break;
}

// supported_color_modes
JsonArray colorModes = config.createNestedArray(F("sup_clrm"));

// Flag RGB support
if (MiLightRemoteTypeHelpers::supportsRgb(bulbId.deviceType)) {
config[F("rgb")] = true;
colorModes.add(F("rgb"));
}

// Flag adjustable color temp support
if (MiLightRemoteTypeHelpers::supportsColorTemp(bulbId.deviceType)) {
config[GroupStateFieldNames::COLOR_TEMP] = true;
colorModes.add(GroupStateFieldNames::COLOR_TEMP);

config[F("max_mirs")] = COLOR_TEMP_MAX_MIREDS;
config[F("min_mirs")] = COLOR_TEMP_MIN_MIREDS;
}

// should only have brightness in this list if there are no other color modes
// https://www.home-assistant.io/integrations/light.mqtt/#supported_color_modes
if (colorModes.size() == 0) {
colorModes.add(F("brightness"));
}

String message;
serializeJson(config, message);

Expand All @@ -148,7 +159,7 @@ String HomeAssistantDiscoveryClient::buildTopic(const BulbId& bulbId) {

topic += "light/";
// Use a static ID that doesn't depend on configuration.
topic += "milight_hub_" + String(ESP.getChipId());
topic += "milight_hub_" + String(getESPId());

// make the object ID based on the actual parameters rather than the alias.
topic += "/";
Expand Down
1 change: 1 addition & 0 deletions lib/MQTT/HomeAssistantDiscoveryClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <BulbId.h>
#include <MqttClient.h>
#include <ESPId.h>
#include <map>

class HomeAssistantDiscoveryClient {
Expand Down
3 changes: 2 additions & 1 deletion lib/MQTT/MqttClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <MiLightRadioConfig.h>
#include <AboutHelper.h>


static const char* STATUS_CONNECTED = "connected";
static const char* STATUS_DISCONNECTED = "disconnected_clean";
static const char* STATUS_LWT_DISCONNECTED = "disconnected_unclean";
Expand Down Expand Up @@ -56,7 +57,7 @@ void MqttClient::begin() {

bool MqttClient::connect() {
char nameBuffer[30];
sprintf_P(nameBuffer, PSTR("milight-hub-%u"), ESP.getChipId());
sprintf_P(nameBuffer, PSTR("milight-hub-%u"), getESPId());

#ifdef MQTT_DEBUG
Serial.println(F("MqttClient - connecting using name"));
Expand Down
1 change: 1 addition & 0 deletions lib/MQTT/MqttClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <PubSubClient.h>
#include <WiFiClient.h>
#include <MiLightRadioConfig.h>
#include <ESPId.h>

#ifndef MQTT_CONNECTION_ATTEMPT_FREQUENCY
#define MQTT_CONNECTION_ATTEMPT_FREQUENCY 5000
Expand Down
1 change: 1 addition & 0 deletions lib/MiLight/MiLightClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <MiLightCommands.h>
#include <functional>


using namespace std::placeholders;

static const uint8_t STATUS_UNDEFINED = 255;
Expand Down
1 change: 1 addition & 0 deletions lib/MiLight/V2PacketFormatter.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <V2PacketFormatter.h>
#include <V2RFEncoding.h>


#define GROUP_COMMAND_ARG(status, groupId, numGroups) ( groupId + (status == OFF ? (numGroups + 1) : 0) )

V2PacketFormatter::V2PacketFormatter(const MiLightRemoteType deviceType, uint8_t protocolId, uint8_t numGroups)
Expand Down
1 change: 1 addition & 0 deletions lib/MiLightState/GroupState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <BulbId.h>
#include <MiLightCommands.h>


static const char* BULB_MODE_NAMES[] = {
"white",
"color",
Expand Down
1 change: 1 addition & 0 deletions lib/MiLightState/GroupState.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <ArduinoJson.h>
#include <BulbId.h>
#include <ParsedColor.h>
#include <vector>

#ifndef _GROUP_STATE_H
#define _GROUP_STATE_H
Expand Down
9 changes: 8 additions & 1 deletion lib/MiLightState/GroupStatePersistence.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
#include <GroupStatePersistence.h>
#include <FS.h>
#ifdef ESP32
#include <SPIFFS.h>
#endif
#include "ProjectFS.h"

static const char FILE_PREFIX[] = "group_states/";
#ifdef ESP8266
static const char FILE_PREFIX[] = "group_states/";
#elif ESP32
static const char FILE_PREFIX[] = "/group_states/";
#endif

void GroupStatePersistence::get(const BulbId &id, GroupState& state) {
char path[30];
Expand Down
6 changes: 5 additions & 1 deletion lib/SSDP/New_ESP8266SSDP.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@ License (MIT license):
#define ESP8266SSDP_H

#include <Arduino.h>
#include <ESP8266WiFi.h>
#ifdef ESP8266
#include <ESP8266WiFi.h>
#elif ESP32
#include <WiFi.h>
#endif
#include <WiFiUdp.h>

class UdpContext;
Expand Down
49 changes: 40 additions & 9 deletions lib/Settings/AboutHelper.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
#include <AboutHelper.h>
#include <ArduinoJson.h>
#include <Settings.h>

#ifdef ESP8266
#include <ESP8266WiFi.h>
#include <cont.h>
#elif ESP32

#include <WiFi.h>
#include <SPIFFS.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>

#endif

#include <ProjectFS.h>

#ifdef ESP8266
extern "C" {
#include <cont.h>
extern cont_t* g_pcont;
};
extern cont_t* g_pcont;
}
#endif

String AboutHelper::generateAboutString(bool abbreviated) {
DynamicJsonDocument buffer(1024);
Expand All @@ -20,22 +33,40 @@ String AboutHelper::generateAboutString(bool abbreviated) {
return body;
}

void AboutHelper::generateAboutObject(JsonDocument& obj, bool abbreviated) {
void AboutHelper::generateAboutObject(JsonDocument &obj, bool abbreviated) {
obj[FPSTR("firmware")] = QUOTE(FIRMWARE_NAME);
obj[FPSTR("version")] = QUOTE(MILIGHT_HUB_VERSION);
obj[FPSTR("ip_address")] = WiFi.localIP().toString();
#ifdef ESP8266
obj[FPSTR("reset_reason")] = ESP.getResetReason();
#elif ESP32
obj[FPSTR("reset_reason")] = String(esp_reset_reason());
#endif

if (! abbreviated) {
if (!abbreviated) {
obj[FPSTR("variant")] = QUOTE(FIRMWARE_VARIANT);
obj[FPSTR("free_heap")] = ESP.getFreeHeap();
#ifdef ESP8266
obj[FPSTR("arduino_version")] = ESP.getCoreVersion();
obj[FPSTR("free_stack")] = cont_get_free_stack(g_pcont);
#elif ESP32
obj[FPSTR("arduino_version")] = ESP.getSdkVersion();
obj[FPSTR("free_stack")] = uxTaskGetStackHighWaterMark(nullptr);
#endif

#ifdef ESP8266
FSInfo fsInfo;
ProjectFS.info(fsInfo);
obj[FPSTR("flash_used")] = fsInfo.usedBytes;
obj[FPSTR("flash_total")] = fsInfo.totalBytes;
obj[FPSTR("flash_pct_free")] = fsInfo.totalBytes == 0 ? 0 : (fsInfo.totalBytes - fsInfo.usedBytes) * 100 / fsInfo.totalBytes;
ProjectFS.info(fsInfo);
obj[FPSTR("flash_used")] = fsInfo.usedBytes;
obj[FPSTR("flash_total")] = fsInfo.totalBytes;
obj[FPSTR("flash_pct_free")] = fsInfo.totalBytes == 0 ? 0 : (fsInfo.totalBytes - fsInfo.usedBytes) * 100 / fsInfo.totalBytes;
#elif ESP32

obj[FPSTR("flash_used")] = ProjectFS.usedBytes();
obj[FPSTR("flash_total")] = ProjectFS.totalBytes();
obj[FPSTR("flash_pct_free")] =
ProjectFS.totalBytes() == 0 ? 0 : (ProjectFS.totalBytes() - ProjectFS.usedBytes()) * 100 /
ProjectFS.totalBytes();
#endif
}
}
4 changes: 4 additions & 0 deletions lib/Settings/BackupManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
//

#include <BackupManager.h>
#ifdef ESP32
#include <SPIFFS.h>
#endif
#include <ProjectFS.h>
#include <StreamUtils.h>


const uint8_t BackupManager::SETTINGS_BACKUP_VERSION = 1;
const uint32_t BackupManager::SETTINGS_MAGIC_HEADER = 0x92A7C300 | SETTINGS_BACKUP_VERSION;

Expand Down
4 changes: 4 additions & 0 deletions lib/Settings/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
#include <ProjectFS.h>
#include <StreamUtils.h>

#ifdef ESP32
#include <SPIFFS.h>
#endif

#define PORT_POSITION(s) ( s.indexOf(':') )

GatewayConfig::GatewayConfig(uint16_t deviceId, uint16_t port, uint8_t protocolVersion)
Expand Down
Loading
Loading