replace Serial.print with logger

This commit is contained in:
cjkas 2026-03-24 20:28:06 +01:00
parent f38dcea1f1
commit a220b9ecc2
13 changed files with 397 additions and 562 deletions

View file

@ -2,6 +2,7 @@
#include <ELECHOUSE_CC1101_SRC_DRV.h>
#include <SPI.h>
#include <esp_task_wdt.h>
#include "esp_log.h"
#include "Utils.h"
#include "ConfigSettings.h"
#include "Somfy.h"
@ -10,6 +11,8 @@
#include "ConfigFile.h"
#include "GitOTA.h"
static const char *TAG = "Somfy";
extern Preferences pref;
extern SomfyShadeController somfy;
extern SocketEmitter sockEmit;
@ -216,37 +219,21 @@ void somfy_frame_t::decodeFrame(byte* frame) {
}
if(this->valid && this->encKey == 0) this->valid = false;
if (!this->valid) {
Serial.print("INVALID FRAME ");
Serial.print("KEY:");
Serial.print(this->encKey);
Serial.print(" ADDR:");
Serial.print(this->remoteAddress);
Serial.print(" CMD:");
Serial.print(translateSomfyCommand(this->cmd));
Serial.print(" RCODE:");
Serial.println(this->rollingCode);
Serial.println(" KEY 1 2 3 4 5 6 ");
Serial.println("--------------------------------");
Serial.print("ENC ");
ESP_LOGW(TAG, "INVALID FRAME KEY:%d ADDR:%d CMD:%s RCODE:%d",
this->encKey, this->remoteAddress,
translateSomfyCommand(this->cmd).c_str(), this->rollingCode);
ESP_LOGD(TAG, " KEY 1 2 3 4 5 6 ");
ESP_LOGD(TAG, "--------------------------------");
char enc_buf[64], dec_buf[64];
int enc_pos = 0, dec_pos = 0;
enc_pos += snprintf(enc_buf + enc_pos, sizeof(enc_buf) - enc_pos, "ENC ");
dec_pos += snprintf(dec_buf + dec_pos, sizeof(dec_buf) - dec_pos, "DEC ");
for (byte i = 0; i < 10; i++) {
if (frame[i] < 10)
Serial.print(" ");
else if (frame[i] < 100)
Serial.print(" ");
Serial.print(frame[i]);
Serial.print(" ");
enc_pos += snprintf(enc_buf + enc_pos, sizeof(enc_buf) - enc_pos, "%3d ", frame[i]);
dec_pos += snprintf(dec_buf + dec_pos, sizeof(dec_buf) - dec_pos, "%3d ", decoded[i]);
}
Serial.println();
Serial.print("DEC ");
for (byte i = 0; i < 10; i++) {
if (decoded[i] < 10)
Serial.print(" ");
else if (decoded[i] < 100)
Serial.print(" ");
Serial.print(decoded[i]);
Serial.print(" ");
}
Serial.println();
ESP_LOGD(TAG, "%s", enc_buf);
ESP_LOGD(TAG, "%s", dec_buf);
}
}
void somfy_frame_t::decodeFrame(somfy_rx_t *rx) {
@ -435,21 +422,11 @@ void somfy_frame_t::encodeFrame(byte *frame) {
}
}
void somfy_frame_t::print() {
Serial.println("----------- Receiving -------------");
Serial.print("RSSI:");
Serial.print(this->rssi);
Serial.print(" LQI:");
Serial.println(this->lqi);
Serial.print("CMD:");
Serial.print(translateSomfyCommand(this->cmd));
Serial.print(" ADDR:");
Serial.print(this->remoteAddress);
Serial.print(" RCODE:");
Serial.println(this->rollingCode);
Serial.print("KEY:");
Serial.print(this->encKey, HEX);
Serial.print(" CS:");
Serial.println(this->checksum);
ESP_LOGD(TAG, "----------- Receiving -------------");
ESP_LOGD(TAG, "RSSI:%d LQI:%d", this->rssi, this->lqi);
ESP_LOGD(TAG, "CMD:%s ADDR:%d RCODE:%d",
translateSomfyCommand(this->cmd).c_str(), this->remoteAddress, this->rollingCode);
ESP_LOGD(TAG, "KEY:%02X CS:%d", this->encKey, this->checksum);
}
bool somfy_frame_t::isSynonym(somfy_frame_t &frame) { return this->remoteAddress == frame.remoteAddress && this->cmd != frame.cmd && this->rollingCode == frame.rollingCode; }
bool somfy_frame_t::isRepeat(somfy_frame_t &frame) { return this->remoteAddress == frame.remoteAddress && this->cmd == frame.cmd && this->rollingCode == frame.rollingCode; }
@ -513,7 +490,7 @@ void SomfyShadeController::updateGroupFlags() {
}
#ifdef USE_NVS
bool SomfyShadeController::loadLegacy() {
Serial.println("Loading Legacy shades using NVS");
ESP_LOGI(TAG, "Loading Legacy shades using NVS");
pref.begin("Shades", true);
pref.getBytes("shadeIds", this->m_shadeIds, sizeof(this->m_shadeIds));
pref.end();
@ -549,7 +526,6 @@ bool SomfyShadeController::loadLegacy() {
DEBUG_SOMFY.print(this->m_shadeIds[i]);
if(i < SOMFY_MAX_SHADES - 1) DEBUG_SOMFY.print(",");
}
Serial.println();
#endif
#ifdef USE_NVS
if(!this->useNVS()) {
@ -565,12 +541,12 @@ bool SomfyShadeController::loadLegacy() {
bool SomfyShadeController::begin() {
// Load up all the configuration data.
//ShadeConfigFile::getAppVersion(this->appVersion);
Serial.printf("App Version:%u.%u.%u\n", settings.appVersion.major, settings.appVersion.minor, settings.appVersion.build);
ESP_LOGI(TAG, "App Version:%u.%u.%u", settings.appVersion.major, settings.appVersion.minor, settings.appVersion.build);
#ifdef USE_NVS
if(!this->useNVS()) { // At 1.4 we started using the configuration file. If the file doesn't exist then booh.
// We need to remove all the extraeneous data from NVS for the shades. From here on out we
// will rely on the shade configuration.
Serial.println("No longer using NVS");
ESP_LOGI(TAG, "No longer using NVS");
if(ShadeConfigFile::exists()) {
ShadeConfigFile::load(this);
}
@ -595,11 +571,11 @@ bool SomfyShadeController::begin() {
}
#endif
if(ShadeConfigFile::exists()) {
Serial.println("shades.cfg exists so we are using that");
ESP_LOGI(TAG, "shades.cfg exists so we are using that");
ShadeConfigFile::load(this);
}
else {
Serial.println("Starting clean");
ESP_LOGI(TAG, "Starting clean");
#ifdef USE_NVS
this->loadLegacy();
#endif
@ -774,8 +750,7 @@ void SomfyShade::commitShadePosition() {
char shadeKey[15];
if(somfy.useNVS()) {
snprintf(shadeKey, sizeof(shadeKey), "SomfyShade%u", this->shadeId);
Serial.print("Writing current shade position: ");
Serial.println(this->currentPos, 4);
ESP_LOGD(TAG, "Writing current shade position: %.4f", this->currentPos);
pref.begin(shadeKey);
pref.putFloat("currentPos", this->currentPos);
pref.end();
@ -788,9 +763,7 @@ void SomfyShade::commitMyPosition() {
if(somfy.useNVS()) {
char shadeKey[15];
snprintf(shadeKey, sizeof(shadeKey), "SomfyShade%u", this->shadeId);
Serial.print("Writing my shade position:");
Serial.print(this->myPos);
Serial.println("%");
ESP_LOGD(TAG, "Writing my shade position:%.2f%%", this->myPos);
pref.begin(shadeKey);
pref.putUShort("myPos", this->myPos);
pref.end();
@ -803,8 +776,7 @@ void SomfyShade::commitTiltPosition() {
if(somfy.useNVS()) {
char shadeKey[15];
snprintf(shadeKey, sizeof(shadeKey), "SomfyShade%u", this->shadeId);
Serial.print("Writing current shade tilt position: ");
Serial.println(this->currentTiltPos, 4);
ESP_LOGD(TAG, "Writing current shade tilt position: %.4f", this->currentTiltPos);
pref.begin(shadeKey);
pref.putFloat("currentTiltPos", this->currentTiltPos);
pref.end();
@ -956,19 +928,19 @@ void SomfyShade::setGPIOs() {
case -1:
digitalWrite(this->gpioDown, p_off);
digitalWrite(this->gpioUp, p_on);
if(dir != this->gpioDir) Serial.printf("UP: true, DOWN: false\n");
if(dir != this->gpioDir) ESP_LOGD(TAG, "UP: true, DOWN: false");
this->gpioDir = dir;
break;
case 1:
digitalWrite(this->gpioUp, p_off);
digitalWrite(this->gpioDown, p_on);
if(dir != this->gpioDir) Serial.printf("UP: false, DOWN: true\n");
if(dir != this->gpioDir) ESP_LOGD(TAG, "UP: false, DOWN: true");
this->gpioDir = dir;
break;
default:
digitalWrite(this->gpioUp, p_off);
digitalWrite(this->gpioDown, p_off);
if(dir != this->gpioDir) Serial.printf("UP: false, DOWN: false\n");
if(dir != this->gpioDir) ESP_LOGD(TAG, "UP: false, DOWN: false");
this->gpioDir = dir;
break;
}
@ -998,7 +970,7 @@ void SomfyShade::triggerGPIOs(somfy_frame_t &frame) {
digitalWrite(this->gpioDown, p_off);
digitalWrite(this->gpioMy, p_on);
dir = 0;
if(dir != this->gpioDir) Serial.printf("UP: false, DOWN: false, MY: true\n");
if(dir != this->gpioDir) ESP_LOGD(TAG, "UP: false, DOWN: false, MY: true");
}
break;
case somfy_commands::Up:
@ -1007,7 +979,7 @@ void SomfyShade::triggerGPIOs(somfy_frame_t &frame) {
digitalWrite(this->gpioDown, p_off);
digitalWrite(this->gpioUp, p_on);
dir = -1;
Serial.printf("UP: true, DOWN: false, MY: false\n");
ESP_LOGD(TAG, "UP: true, DOWN: false, MY: false");
}
break;
case somfy_commands::Toggle:
@ -1018,14 +990,14 @@ void SomfyShade::triggerGPIOs(somfy_frame_t &frame) {
}
digitalWrite(this->gpioDown, p_on);
dir = 1;
Serial.printf("UP: false, DOWN: true, MY: false\n");
ESP_LOGD(TAG, "UP: false, DOWN: true, MY: false");
break;
case somfy_commands::MyUp:
if(this->shadeType != shade_types::drycontact && !this->isToggle() && this->shadeType != shade_types::drycontact2) {
digitalWrite(this->gpioDown, p_off);
digitalWrite(this->gpioMy, p_on);
digitalWrite(this->gpioUp, p_on);
Serial.printf("UP: true, DOWN: false, MY: true\n");
ESP_LOGD(TAG, "UP: true, DOWN: false, MY: true");
}
break;
case somfy_commands::MyDown:
@ -1033,7 +1005,7 @@ void SomfyShade::triggerGPIOs(somfy_frame_t &frame) {
digitalWrite(this->gpioUp, p_off);
digitalWrite(this->gpioMy, p_on);
digitalWrite(this->gpioDown, p_on);
Serial.printf("UP: false, DOWN: true, MY: true\n");
ESP_LOGD(TAG, "UP: false, DOWN: true, MY: true");
}
break;
case somfy_commands::MyUpDown:
@ -1041,7 +1013,7 @@ void SomfyShade::triggerGPIOs(somfy_frame_t &frame) {
digitalWrite(this->gpioUp, p_on);
digitalWrite(this->gpioMy, p_on);
digitalWrite(this->gpioDown, p_on);
Serial.printf("UP: true, DOWN: true, MY: true\n");
ESP_LOGD(TAG, "UP: true, DOWN: true, MY: true");
}
break;
default:
@ -1089,7 +1061,7 @@ void SomfyShade::checkMovement() {
this->p_target(this->myPos >= 0 ? this->myPos : 100.0f);
//this->target = this->myPos >= 0 ? this->myPos : 100.0f;
this->sunDone = true;
Serial.printf("[%u] Sun -> done\r\n", this->shadeId);
ESP_LOGD(TAG, "[%u] Sun -> done", this->shadeId);
}
if (!this->noWindDone
&& this->noWindStart
@ -1098,7 +1070,7 @@ void SomfyShade::checkMovement() {
this->p_target(this->myPos >= 0 ? this->myPos : 100.0f);
//this->target = this->myPos >= 0 ? this->myPos : 100.0f;
this->noWindDone = true;
Serial.printf("[%u] No Wind -> done\r\n", this->shadeId);
ESP_LOGD(TAG, "[%u] No Wind -> done", this->shadeId);
}
}
if (!isSunny
@ -1109,7 +1081,7 @@ void SomfyShade::checkMovement() {
if(this->tiltType == tilt_types::tiltonly) this->p_tiltTarget(0.0f);
this->p_target(0.0f);
this->noSunDone = true;
Serial.printf("[%u] No Sun -> done\r\n", this->shadeId);
ESP_LOGD(TAG, "[%u] No Sun -> done", this->shadeId);
}
}
@ -1121,7 +1093,7 @@ void SomfyShade::checkMovement() {
if(this->tiltType == tilt_types::tiltonly) this->p_tiltTarget(0.0f);
this->p_target(0.0f);
this->windDone = true;
Serial.printf("[%u] Wind -> done\r\n", this->shadeId);
ESP_LOGD(TAG, "[%u] Wind -> done", this->shadeId);
}
if(!tilt_first && this->direction > 0) {
@ -1167,7 +1139,7 @@ void SomfyShade::checkMovement() {
// not moving otherwise the my function will kick in.
if(this->settingPos) {
if(!isAtTarget()) {
Serial.printf("We are not at our tilt target: %.2f\n", this->tiltTarget);
ESP_LOGD(TAG, "We are not at our tilt target: %.2f", this->tiltTarget);
if(this->target != 100.0) SomfyRemote::sendCommand(somfy_commands::My, this->repeats);
delay(100);
// We now need to move the tilt to the position we requested.
@ -1219,7 +1191,7 @@ void SomfyShade::checkMovement() {
// not moving otherwise the my function will kick in.
if(this->settingPos) {
if(!isAtTarget()) {
Serial.printf("We are not at our tilt target: %.2f\n", this->tiltTarget);
ESP_LOGD(TAG, "We are not at our tilt target: %.2f", this->tiltTarget);
if(this->target != 0.0) SomfyRemote::sendCommand(somfy_commands::My, this->repeats);
delay(100);
// We now need to move the tilt to the position we requested.
@ -1330,7 +1302,7 @@ void SomfyShade::checkMovement() {
}
this->p_tiltDirection(0);
this->settingTiltPos = false;
Serial.println("Stopping at tilt position");
ESP_LOGI(TAG, "Stopping at tilt position");
if(this->isAtTarget()) this->commitShadePosition();
}
}
@ -1402,16 +1374,9 @@ void SomfyShade::load() {
this->tiltTarget = floor(this->currentTiltPos);
pref.getBytes("linkedAddr", linkedAddresses, sizeof(linkedAddresses));
pref.end();
Serial.print("shadeId:");
Serial.print(this->getShadeId());
Serial.print(" name:");
Serial.print(this->name);
Serial.print(" address:");
Serial.print(this->getRemoteAddress());
Serial.print(" position:");
Serial.print(this->currentPos);
Serial.print(" myPos:");
Serial.println(this->myPos);
ESP_LOGI(TAG, "shadeId:%d name:%s address:%d position:%.2f myPos:%.2f",
this->getShadeId(), this->name, this->getRemoteAddress(),
this->currentPos, this->myPos);
pref.begin("ShadeCodes");
this->lastRollingCode = pref.getUShort(this->m_remotePrefId, 0);
for(uint8_t j = 0; j < SOMFY_MAX_LINKED_REMOTES; j++) {
@ -1470,7 +1435,7 @@ void SomfyShade::publishState() {
void SomfyShade::publishDisco() {
if(!mqtt.connected() || !settings.MQTT.pubDisco) return;
char topic[128] = "";
DynamicJsonDocument doc(2048);
JsonDocument doc;
JsonObject obj = doc.to<JsonObject>();
snprintf(topic, sizeof(topic), "%s/shades/%d", settings.MQTT.rootTopic, this->shadeId);
obj["~"] = topic;
@ -2095,12 +2060,8 @@ void SomfyShade::processWaitingFrame() {
this->p_tiltTarget(dir > 0 ? 100.0f : 0.0f);
this->setTiltMovement(dir);
this->lastFrame.processed = true;
Serial.print(this->name);
Serial.print(" Processing tilt ");
Serial.print(translateSomfyCommand(this->lastFrame.cmd));
Serial.print(" after ");
Serial.print(this->lastFrame.repeats);
Serial.println(" repeats");
ESP_LOGD(TAG, "%s Processing tilt %s after %d repeats",
this->name, translateSomfyCommand(this->lastFrame.cmd).c_str(), this->lastFrame.repeats);
this->emitCommand(cmd, "remote", this->lastFrame.remoteAddress);
}
else {
@ -2121,12 +2082,8 @@ void SomfyShade::processWaitingFrame() {
this->p_target(dir > 0 ? 100.0f : 0.0f);
this->setMovement(dir);
this->lastFrame.processed = true;
Serial.print(this->name);
Serial.print(" Processing ");
Serial.print(translateSomfyCommand(this->lastFrame.cmd));
Serial.print(" after ");
Serial.print(this->lastFrame.repeats);
Serial.println(" repeats");
ESP_LOGD(TAG, "%s Processing %s after %d repeats",
this->name, translateSomfyCommand(this->lastFrame.cmd).c_str(), this->lastFrame.repeats);
this->emitCommand(cmd, "remote", this->lastFrame.remoteAddress);
}
else {
@ -2174,10 +2131,7 @@ void SomfyShade::processWaitingFrame() {
}
if(this->lastFrame.repeats > SETMY_REPEATS + 2) this->lastFrame.processed = true;
if(this->lastFrame.processed) {
Serial.print(this->name);
Serial.print(" Processing MY after ");
Serial.print(this->lastFrame.repeats);
Serial.println(" repeats");
ESP_LOGD(TAG, "%s Processing MY after %d repeats", this->name, this->lastFrame.repeats);
}
break;
default:
@ -2264,25 +2218,25 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
{
this->sunStart = curTime;
this->sunDone = false;
Serial.printf("[%u] Sun -> start\r\n", this->shadeId);
ESP_LOGD(TAG, "[%u] Sun -> start", this->shadeId);
}
else if (!isSunny && wasSunny)
{
this->noSunStart = curTime;
this->noSunDone = false;
Serial.printf("[%u] No Sun -> start\r\n", this->shadeId);
ESP_LOGD(TAG, "[%u] No Sun -> start", this->shadeId);
}
if (isWindy && !wasWindy)
{
this->windStart = curTime;
this->windDone = false;
Serial.printf("[%u] Wind -> start\r\n", this->shadeId);
ESP_LOGD(TAG, "[%u] Wind -> start", this->shadeId);
}
else if (!isWindy && wasWindy)
{
this->noWindStart = curTime;
this->noWindDone = false;
Serial.printf("[%u] No Wind -> start\r\n", this->shadeId);
ESP_LOGD(TAG, "[%u] No Wind -> start", this->shadeId);
}
this->emitState();
somfy.updateGroupFlags();
@ -2425,7 +2379,7 @@ void SomfyShade::processFrame(somfy_frame_t &frame, bool internal) {
}
else {
if(this->lastFrame.processed) return;
Serial.println("Moving to My target");
ESP_LOGI(TAG, "Moving to My target");
this->lastFrame.processed = true;
if(this->myTiltPos >= 0.0f && this->myTiltPos <= 100.0f) this->p_tiltTarget(this->myTiltPos);
if(this->myPos >= 0.0f && this->myPos <= 100.0f && this->tiltType != tilt_types::tiltonly) this->p_target(this->myPos);
@ -2610,7 +2564,7 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) {
break;
case somfy_commands::My:
if(this->isIdle()) {
Serial.printf("Shade #%d is idle\n", this->getShadeId());
ESP_LOGD(TAG, "Shade #%d is idle", this->getShadeId());
if(this->simMy()) {
this->moveToMyPosition();
}
@ -2705,7 +2659,7 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) {
this->emitState();
}
else {
Serial.printf("Shade does not have sensor %d\n", this->flags);
ESP_LOGW(TAG, "Shade does not have sensor %d", this->flags);
}
break;
case somfy_commands::SunFlag:
@ -2725,7 +2679,7 @@ void SomfyShade::processInternalCommand(somfy_commands cmd, uint8_t repeat) {
this->emitState();
}
else
Serial.printf("Shade does not have sensor %d\n", this->flags);
ESP_LOGW(TAG, "Shade does not have sensor %d", this->flags);
break;
default:
dir = 0;
@ -2864,7 +2818,7 @@ void SomfyShade::setMyPosition(int8_t pos, int8_t tilt) {
}
void SomfyShade::moveToMyPosition() {
if(!this->isIdle()) return;
Serial.println("Moving to My Position");
ESP_LOGI(TAG, "Moving to My Position");
if(this->tiltType == tilt_types::tiltonly) {
this->p_currentPos(100.0f);
this->p_myPos(-1.0f);
@ -2881,7 +2835,7 @@ void SomfyShade::moveToMyPosition() {
if(this->myTiltPos >= 0.0f && this->myTiltPos <= 100.0f) this->p_tiltTarget(this->myTiltPos);
this->settingPos = false;
if(this->simMy()) {
Serial.print("Moving to simulated favorite\n");
ESP_LOGI(TAG, "Moving to simulated favorite");
this->moveToTarget(this->myPos, this->myTiltPos);
}
else
@ -2889,7 +2843,7 @@ void SomfyShade::moveToMyPosition() {
}
void SomfyShade::sendCommand(somfy_commands cmd) { this->sendCommand(cmd, this->repeats); }
void SomfyShade::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSize) {
Serial.print("Send command start\n");
ESP_LOGD(TAG, "Send command start");
// This sendCommand function will always be called externally. sendCommand at the remote level
// is expected to be called internally when the motor needs commanded.
if(this->bitLength == 0) this->bitLength = somfy.transceiver.config.type;
@ -2897,7 +2851,7 @@ void SomfyShade::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSiz
// The real motor stops on its own when it receives the same direction again.
if((cmd == somfy_commands::Up && this->direction == -1) ||
(cmd == somfy_commands::Down && this->direction == 1)) {
Serial.println("Same command as dir");
ESP_LOGD(TAG, "Same command as dir");
SomfyRemote::sendCommand(cmd, repeat);
this->p_target(this->currentPos);
this->p_tiltTarget(this->currentTiltPos);
@ -2944,12 +2898,12 @@ void SomfyShade::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSiz
if(this->isToggle() || this->shadeType == shade_types::drycontact)
SomfyRemote::sendCommand(cmd, repeat);
else if(this->shadeType == shade_types::drycontact2){
Serial.print("Send command start 1\n");
ESP_LOGD(TAG, "Send command start 1");
return;
}
else if(this->isIdle()) {
this->moveToMyPosition();
Serial.print("Send command end 2\n");
ESP_LOGD(TAG, "Send command end 2");
return;
}
else {
@ -2968,7 +2922,7 @@ void SomfyShade::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSiz
else {
SomfyRemote::sendCommand(cmd, repeat, stepSize);
}
Serial.print("Send command end\n");
ESP_LOGD(TAG, "Send command end");
}
void SomfyGroup::sendCommand(somfy_commands cmd) { this->sendCommand(cmd, this->repeats); }
void SomfyGroup::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSize) {
@ -3028,12 +2982,8 @@ void SomfyShade::moveToTiltTarget(float target) {
// Only send a command if the lift is not moving.
if(this->currentPos == this->target || this->tiltType == tilt_types::tiltmotor) {
if(cmd != somfy_commands::My) {
Serial.print("Moving Tilt to ");
Serial.print(target);
Serial.print("% from ");
Serial.print(this->currentTiltPos);
Serial.print("% using ");
Serial.println(translateSomfyCommand(cmd));
ESP_LOGI(TAG, "Moving Tilt to %.2f%% from %.2f%% using %s",
target, this->currentTiltPos, translateSomfyCommand(cmd).c_str());
SomfyRemote::sendCommand(cmd, this->tiltType == tilt_types::tiltmotor ? TILT_REPEATS : this->repeats);
}
// If the blind is currently moving then the command to stop it
@ -3071,18 +3021,13 @@ void SomfyShade::moveToTarget(float pos, float tilt) {
cmd = somfy_commands::Down;
}
if(cmd != somfy_commands::My) {
Serial.print("Moving to ");
Serial.print(pos);
Serial.print("% from ");
Serial.print(this->currentPos);
if(tilt >= 0) {
Serial.print(" tilt ");
Serial.print(tilt);
Serial.print("% from ");
Serial.print(this->currentTiltPos);
ESP_LOGI(TAG, "Moving to %.2f%% from %.2f%% tilt %.2f%% from %.2f%% using %s",
pos, this->currentPos, tilt, this->currentTiltPos, translateSomfyCommand(cmd).c_str());
} else {
ESP_LOGI(TAG, "Moving to %.2f%% from %.2f%% using %s",
pos, this->currentPos, translateSomfyCommand(cmd).c_str());
}
Serial.print("% using ");
Serial.println(translateSomfyCommand(cmd));
SomfyRemote::sendCommand(cmd, this->tiltType == tilt_types::euromode ? TILT_REPEATS : this->repeats);
this->settingPos = true;
this->p_target(pos);
@ -3521,8 +3466,7 @@ uint8_t SomfyShadeController::getNextShadeId() {
}
}
if(!id_exists) {
Serial.print("Got next Shade Id:");
Serial.print(i);
ESP_LOGD(TAG, "Got next Shade Id:%d", i);
return i;
}
}
@ -3559,8 +3503,7 @@ uint8_t SomfyShadeController::getNextGroupId() {
}
}
if(!id_exists) {
Serial.print("Got next Group Id:");
Serial.print(i);
ESP_LOGD(TAG, "Got next Group Id:%d", i);
return i;
}
}
@ -3579,8 +3522,7 @@ uint8_t SomfyShadeController::getNextRoomId() {
}
}
if(!id_exists) {
Serial.print("Got next room Id:");
Serial.print(i);
ESP_LOGD(TAG, "Got next room Id:%d", i);
return i;
}
}
@ -3659,7 +3601,7 @@ SomfyShade *SomfyShadeController::addShade() {
if(shade) {
shade->setShadeId(shadeId);
shade->sortOrder = this->getMaxShadeOrder() + 1;
Serial.printf("Sort order set to %d\n", shade->sortOrder);
ESP_LOGD(TAG, "Sort order set to %d", shade->sortOrder);
this->isDirty = true;
#ifdef USE_NVS
if(this->useNVS()) {
@ -3688,25 +3630,30 @@ SomfyShade *SomfyShadeController::addShade() {
pref.begin("Shades");
pref.remove("shadeIds");
int x = pref.putBytes("shadeIds", this->m_shadeIds, sizeof(this->m_shadeIds));
Serial.printf("WROTE %d bytes to shadeIds\n", x);
ESP_LOGD(TAG, "WROTE %d bytes to shadeIds", x);
pref.end();
for(uint8_t i = 0; i < sizeof(this->m_shadeIds); i++) {
if(i != 0) Serial.print(",");
else Serial.print("Shade Ids: ");
Serial.print(this->m_shadeIds[i]);
{
char shade_ids_buf[256];
int spos = snprintf(shade_ids_buf, sizeof(shade_ids_buf), "Shade Ids: ");
for(uint8_t i = 0; i < sizeof(this->m_shadeIds); i++) {
if(i != 0) spos += snprintf(shade_ids_buf + spos, sizeof(shade_ids_buf) - spos, ",");
spos += snprintf(shade_ids_buf + spos, sizeof(shade_ids_buf) - spos, "%d", this->m_shadeIds[i]);
}
ESP_LOGD(TAG, "%s", shade_ids_buf);
}
Serial.println();
pref.begin("Shades");
pref.getBytes("shadeIds", this->m_shadeIds, sizeof(this->m_shadeIds));
Serial.print("LENGTH:");
Serial.println(pref.getBytesLength("shadeIds"));
ESP_LOGD(TAG, "LENGTH:%d", pref.getBytesLength("shadeIds"));
pref.end();
for(uint8_t i = 0; i < sizeof(this->m_shadeIds); i++) {
if(i != 0) Serial.print(",");
else Serial.print("Shade Ids: ");
Serial.print(this->m_shadeIds[i]);
{
char shade_ids_buf[256];
int spos = snprintf(shade_ids_buf, sizeof(shade_ids_buf), "Shade Ids: ");
for(uint8_t i = 0; i < sizeof(this->m_shadeIds); i++) {
if(i != 0) spos += snprintf(shade_ids_buf + spos, sizeof(shade_ids_buf) - spos, ",");
spos += snprintf(shade_ids_buf + spos, sizeof(shade_ids_buf) - spos, "%d", this->m_shadeIds[i]);
}
ESP_LOGD(TAG, "%s", shade_ids_buf);
}
Serial.println();
}
#endif
}
@ -3818,14 +3765,9 @@ void SomfyRemote::sendSensorCommand(int8_t isWindy, int8_t isSunny, uint8_t repe
this->lastFrame.encKey = 160; // Sensor commands are always encryption code 160.
this->lastFrame.cmd = somfy_commands::Sensor;
this->lastFrame.processed = false;
Serial.print("CMD:");
Serial.print(translateSomfyCommand(this->lastFrame.cmd));
Serial.print(" ADDR:");
Serial.print(this->lastFrame.remoteAddress);
Serial.print(" RCODE:");
Serial.print(this->lastFrame.rollingCode);
Serial.print(" REPEAT:");
Serial.println(repeat);
ESP_LOGD(TAG, "CMD:%s ADDR:%d RCODE:%d REPEAT:%d",
translateSomfyCommand(this->lastFrame.cmd).c_str(),
this->lastFrame.remoteAddress, this->lastFrame.rollingCode, repeat);
somfy.sendFrame(this->lastFrame, repeat);
somfy.processFrame(this->lastFrame, true);
}
@ -3842,46 +3784,33 @@ void SomfyRemote::sendCommand(somfy_commands cmd, uint8_t repeat, uint8_t stepSi
this->lastFrame.encKey = 0xA0 | static_cast<uint8_t>(this->lastFrame.rollingCode & 0x000F);
this->lastFrame.proto = this->proto;
if(this->lastFrame.bitLength == 0) this->lastFrame.bitLength = bit_length;
if(this->lastFrame.rollingCode == 0) Serial.println("ERROR: Setting rcode to 0");
if(this->lastFrame.rollingCode == 0) ESP_LOGE(TAG, "Setting rcode to 0");
this->p_lastRollingCode(this->lastFrame.rollingCode);
// We have to set the processed to clear this if we are sending
// another command.
this->lastFrame.processed = false;
if(this->proto == radio_proto::GP_Relay) {
Serial.print("CMD:");
Serial.print(translateSomfyCommand(this->lastFrame.cmd));
Serial.print(" ADDR:");
Serial.print(this->lastFrame.remoteAddress);
Serial.print(" RCODE:");
Serial.print(this->lastFrame.rollingCode);
Serial.println(" SETTING GPIO");
ESP_LOGD(TAG, "CMD:%s ADDR:%d RCODE:%d SETTING GPIO",
translateSomfyCommand(this->lastFrame.cmd).c_str(),
this->lastFrame.remoteAddress, this->lastFrame.rollingCode);
}
else if(this->proto == radio_proto::GP_Remote) {
Serial.print("CMD:");
Serial.print(translateSomfyCommand(this->lastFrame.cmd));
Serial.print(" ADDR:");
Serial.print(this->lastFrame.remoteAddress);
Serial.print(" RCODE:");
Serial.print(this->lastFrame.rollingCode);
Serial.println(" TRIGGER GPIO");
ESP_LOGD(TAG, "CMD:%s ADDR:%d RCODE:%d TRIGGER GPIO",
translateSomfyCommand(this->lastFrame.cmd).c_str(),
this->lastFrame.remoteAddress, this->lastFrame.rollingCode);
this->triggerGPIOs(this->lastFrame);
}
else {
Serial.print("CMD:");
Serial.print(translateSomfyCommand(this->lastFrame.cmd));
Serial.print(" ADDR:");
Serial.print(this->lastFrame.remoteAddress);
Serial.print(" RCODE:");
Serial.print(this->lastFrame.rollingCode);
Serial.print(" REPEAT:");
Serial.println(repeat);
ESP_LOGD(TAG, "CMD:%s ADDR:%d RCODE:%d REPEAT:%d",
translateSomfyCommand(this->lastFrame.cmd).c_str(),
this->lastFrame.remoteAddress, this->lastFrame.rollingCode, repeat);
somfy.sendFrame(this->lastFrame, repeat);
}
somfy.processFrame(this->lastFrame, true);
}
bool SomfyRemote::isLastCommand(somfy_commands cmd) {
if(this->lastFrame.cmd != cmd || this->lastFrame.rollingCode != this->lastRollingCode) {
Serial.printf("Not the last command %d: %d - %d\n", static_cast<uint8_t>(this->lastFrame.cmd), this->lastFrame.rollingCode, this->lastRollingCode);
ESP_LOGD(TAG, "Not the last command %d: %d - %d", static_cast<uint8_t>(this->lastFrame.cmd), this->lastFrame.rollingCode, this->lastRollingCode);
return false;
}
return true;
@ -4006,7 +3935,7 @@ uint16_t SomfyRemote::setRollingCode(uint16_t code) {
pref.putUShort(this->m_remotePrefId, code);
pref.end();
this->lastRollingCode = code;
Serial.printf("Setting Last Rolling code %d\n", this->lastRollingCode);
ESP_LOGD(TAG, "Setting Last Rolling code %d", this->lastRollingCode);
}
return code;
}
@ -4151,7 +4080,7 @@ void somfy_tx_queue_t::push(uint8_t hwsync, uint8_t *payload, uint8_t bit_length
this->delay_time = millis() + TX_QUEUE_DELAY; // We do not want to process this frame until a full frame beat has passed.
}
void somfy_rx_queue_t::init() {
Serial.println("Initializing RX Queue");
ESP_LOGD(TAG, "Initializing RX Queue");
for (uint8_t i = 0; i < MAX_RX_BUFFER; i++)
this->items[i].clear();
memset(&this->index[0], 0xFF, MAX_RX_BUFFER);
@ -4395,7 +4324,7 @@ void Transceiver::beginFrequencyScan() {
markFreq = currFreq = 433.0f;
markRSSI = -100;
ELECHOUSE_cc1101.setMHZ(currFreq);
Serial.printf("Begin frequency scan on Pin #%d\n", this->config.RXPin);
ESP_LOGD(TAG, "Begin frequency scan on Pin #%d", this->config.RXPin);
attachInterrupt(interruptPin, handleReceive, CHANGE);
this->emitFrequencyScan();
}
@ -4538,7 +4467,7 @@ void Transceiver::enableReceive(void) {
ELECHOUSE_cc1101.SetRx();
//attachInterrupt(interruptPin, handleReceive, FALLING);
attachInterrupt(interruptPin, handleReceive, CHANGE);
Serial.printf("Enabled receive on Pin #%d Timing: %ld\n", this->config.RXPin, millis() - timing);
ESP_LOGD(TAG, "Enabled receive on Pin #%d Timing: %ld", this->config.RXPin, millis() - timing);
}
}
void Transceiver::disableReceive(void) {
@ -4623,7 +4552,7 @@ void transceiver_config_t::fromJSON(JsonObject& obj) {
if (obj.containsKey("appendStatus")) this->appendStatus = obj["appendStatus"];
if (obj.containsKey("printBuffer")) this->printBuffer = obj["printBuffer"];
*/
Serial.printf("SCK:%u MISO:%u MOSI:%u CSN:%u RX:%u TX:%u\n", this->SCKPin, this->MISOPin, this->MOSIPin, this->CSNPin, this->RXPin, this->TXPin);
ESP_LOGD(TAG, "SCK:%u MISO:%u MOSI:%u CSN:%u RX:%u TX:%u", this->SCKPin, this->MISOPin, this->MOSIPin, this->CSNPin, this->RXPin, this->TXPin);
}
/*
void transceiver_config_t::toJSON(JsonObject& obj) {
@ -4714,12 +4643,11 @@ void transceiver_config_t::save() {
*/
pref.end();
Serial.print("Save Radio Settings ");
Serial.printf("SCK:%u MISO:%u MOSI:%u CSN:%u RX:%u TX:%u\n", this->SCKPin, this->MISOPin, this->MOSIPin, this->CSNPin, this->RXPin, this->TXPin);
ESP_LOGI(TAG, "Save Radio Settings SCK:%u MISO:%u MOSI:%u CSN:%u RX:%u TX:%u", this->SCKPin, this->MISOPin, this->MOSIPin, this->CSNPin, this->RXPin, this->TXPin);
}
void transceiver_config_t::removeNVSKey(const char *key) {
if(pref.isKey(key)) {
Serial.printf("Removing NVS Key: CC1101.%s\n", key);
ESP_LOGD(TAG, "Removing NVS Key: CC1101.%s", key);
pref.remove(key);
}
}
@ -4728,7 +4656,7 @@ void transceiver_config_t::load() {
esp_chip_info(&ci);
switch(ci.model) {
case esp_chip_model_t::CHIP_ESP32S3:
Serial.println("Setting S3 Transceiver Defaults...");
ESP_LOGD(TAG, "Setting S3 Transceiver Defaults...");
this->TXPin = 15;
this->RXPin = 14;
this->MOSIPin = 11;
@ -4812,8 +4740,7 @@ void transceiver_config_t::apply() {
this->radioInit = false;
pref.end();
if(!radioInit) return;
Serial.print("Applying radio settings ");
Serial.printf("Setting Data Pins RX:%u TX:%u\n", this->RXPin, this->TXPin);
ESP_LOGD(TAG, "Applying radio settings - Setting Data Pins RX:%u TX:%u", this->RXPin, this->TXPin);
//if(this->TXPin != this->RXPin)
// pinMode(this->TXPin, OUTPUT);
//pinMode(this->RXPin, INPUT);
@ -4822,9 +4749,9 @@ void transceiver_config_t::apply() {
ELECHOUSE_cc1101.setGDO0(this->TXPin); // This pin may be shared.
else
ELECHOUSE_cc1101.setGDO(this->TXPin, this->RXPin); // GDO0, GDO2
Serial.printf("Setting SPI Pins SCK:%u MISO:%u MOSI:%u CSN:%u\n", this->SCKPin, this->MISOPin, this->MOSIPin, this->CSNPin);
ESP_LOGD(TAG, "Setting SPI Pins SCK:%u MISO:%u MOSI:%u CSN:%u", this->SCKPin, this->MISOPin, this->MOSIPin, this->CSNPin);
ELECHOUSE_cc1101.setSpiPin(this->SCKPin, this->MISOPin, this->MOSIPin, this->CSNPin);
Serial.println("Radio Pins Configured!");
ESP_LOGD(TAG, "Radio Pins Configured!");
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.setCCMode(0); // set config for internal transmission mode.
ELECHOUSE_cc1101.setMHZ(this->frequency); // Here you can set your basic frequency. The lib calculates the frequency automatically (default = 433.92).The cc1101 can: 300-348 MHZ, 387-464MHZ and 779-928MHZ. Read More info from datasheet.
@ -4860,11 +4787,11 @@ void transceiver_config_t::apply() {
if (!ELECHOUSE_cc1101.getCC1101()) {
Serial.println("Error setting up the radio");
ESP_LOGE(TAG, "Error setting up the radio");
this->radioInit = false;
}
else {
Serial.println("Successfully set up the radio");
ESP_LOGI(TAG, "Successfully set up the radio");
somfy.transceiver.enableReceive();
this->radioInit = true;
}
@ -4919,7 +4846,7 @@ void Transceiver::loop() {
for(uint8_t i = 0; i < SOMFY_MAX_REPEATERS; i++) {
if(somfy.repeaters[i] == frame.remoteAddress) {
tx_queue.push(&rx);
Serial.println("Queued repeater frame...");
ESP_LOGD(TAG, "Queued repeater frame...");
break;
}
}
@ -4933,12 +4860,15 @@ void Transceiver::loop() {
somfy_tx_t tx;
tx_queue.pop(&tx);
Serial.printf("Sending frame %d - %d-BIT [", tx.hwsync, tx.bit_length);
for(uint8_t j = 0; j < 10; j++) {
Serial.print(tx.payload[j]);
if(j < 9) Serial.print(", ");
{
char frame_buf[128];
int fpos = snprintf(frame_buf, sizeof(frame_buf), "Sending frame %d - %d-BIT [", tx.hwsync, tx.bit_length);
for(uint8_t j = 0; j < 10; j++) {
fpos += snprintf(frame_buf + fpos, sizeof(frame_buf) - fpos, "%d%s", tx.payload[j], j < 9 ? ", " : "");
}
snprintf(frame_buf + fpos, sizeof(frame_buf) - fpos, "]");
ESP_LOGD(TAG, "%s", frame_buf);
}
Serial.println("]");
this->sendFrame(tx.payload, tx.hwsync, tx.bit_length);
tx_queue.delay_time = millis() + TX_QUEUE_DELAY;