Skip to content

Commit

Permalink
Merge branch 'develop' into statusled
Browse files Browse the repository at this point in the history
  • Loading branch information
markirb authored Jan 10, 2025
2 parents 007648b + c126c4e commit daa70a2
Show file tree
Hide file tree
Showing 11 changed files with 151 additions and 45 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ jobs:
- ShellyColorBulb
- ShellyDuo
- ShellyI3
- ShellyMini1Gen3
- ShellyMini1PMGen3
- ShellyPlug
- ShellyPlugS
- ShellyPlus1
- ShellyPlus1Mini
- ShellyPlus1PM
- ShellyPlus1PMMini
- ShellyPlus2PM
- ShellyPlusI4
- ShellyPlusPlugS
- ShellyPlusRGBWPM
- ShellyPlus1Mini
- ShellyPlus1PMMini
- ShellyMini1Gen3
- ShellyMini1PMGen3
- ShellyPlusUni
- ShellyRGBW2
- ShellyUNI
- ShellyVintage
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MAKEFLAGS += --warn-undefined-variables --no-builtin-rules

.PHONY: build check-format format release upload \
Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlusPlugS ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI ShellyPlus1Mini ShellyPlusRGBWPM ShellyMini1Gen3 ShellyMini1PMGen3
Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlusPlugS ShellyPlus1 ShellyPlus1PM ShellyPlus2PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI ShellyPlus1Mini ShellyPlusRGBWPM ShellyMini1Gen3 ShellyMini1PMGen3 ShellyPlusUni
.SUFFIXES:

MOS ?= mos
Expand Down Expand Up @@ -110,6 +110,10 @@ ShellyRGBW2: build-ShellyRGBW2
ShellyUNI: build-ShellyUNI
@true

ShellyPlusUni: PLATFORM=esp32
ShellyPlusUni: build-ShellyPlusUni
@true

ShellyVintage: build-ShellyVintage
@true

Expand Down
12 changes: 10 additions & 2 deletions libreset/src/shelly_reset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ extern "C" uint32_t rtc_get_reset_reason(void);
// so we can repurpose this location for failsafe flag.
#define RTC_SCRATCH_ADDR 0x600011fc
#elif CS_PLATFORM == CS_P_ESP32
#include "esp32/rom/rtc.h"

#include "sdkconfig.h"
#define RTC_SCRATCH_ADDR 0x50001ffc

#ifdef CONFIG_IDF_TARGET_ESP32
#include "esp32/rom/rtc.h"
#elif CONFIG_IDF_TARGET_ESP32C3
#include "esp32c3/rom/rtc.h"
#endif

#endif

#define FF_MODE_MAGIC 0x18365472
Expand Down Expand Up @@ -168,7 +176,7 @@ bool IsSoftReboot() {
return (ri->reason == REASON_SOFT_RESTART);
#elif CS_PLATFORM == CS_P_ESP32
RESET_REASON rr = rtc_get_reset_reason(0 /* core */);
return (rr == SW_RESET || rr == SW_CPU_RESET);
return (rr == (int) RESET_REASON_CORE_SW || rr == (int) RESET_REASON_CPU0_SW);
#else
return false;
#endif
Expand Down
79 changes: 78 additions & 1 deletion mos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1183,16 +1183,25 @@ conds:
- when: build_vars.MODEL == "ShellyUNI"
apply:
name: uni
sources:
- src/DS18XXX
- src/DHT
libs:
- location: https://github.com/mongoose-os-libs/onewire
- location: https://github.com/mongoose-os-libs/dht
- location: https://github.com/mongoose-os-libs/mongoose
variant: esp8266-nossl
- location: https://github.com/mongoose-os-libs/ade7953
build_vars:
FLASH_SIZE: 2097152
FS_SIZE: 262144
BOOT_CONFIG_ADDR: 0x1000
MGOS_ROOT_FS_TYPE: SPIFFS
cdefs:
RELAY1_GPIO: 15
RELAY2_GPIO: 4
SWITCH1_GPIO: 12
SWITCH2_GPIO: 13
SENSOR_GPIO: 5
LED_GPIO: 0
LED_ON: 0
BTN_GPIO: 2
Expand All @@ -1217,6 +1226,74 @@ conds:
- ["gdo1", "gdo", {title: "GDO1 settings"}]
- ["gdo1.name", "Garage Door"]

- ["ts1", "ts", {title: "TS1 settings"}]
- ["ts1.name", "Shelly TS1"]
- ["ts2", "ts", {title: "TS2 settings"}]
- ["ts2.name", "Shelly TS2"]
- ["ts3", "ts", {title: "TS3 settings"}]
- ["ts3.name", "Shelly TS3"]

- when: build_vars.MODEL == "ShellyPlusUni"
apply:
name: PlusUni
sources:
- src/DS18XXX
- src/DHT
- src/ShellyUNI
libs:
- location: https://github.com/mongoose-os-libs/onewire
- location: https://github.com/mongoose-os-libs/dht
- location: https://github.com/mongoose-os-libs/mongoose
build_vars:
ESP_IDF_EXTRA_PARTITION: "aux,0x55,0x00,0x3f0000,48K"
ESP_IDF_EXTRA_PARTITION_2: "shelly,data,0x88,0x3fc000,16K,encrypted"
ESP_IDF_SDKCONFIG_OPTS: >
${build_vars.ESP_IDF_SDKCONFIG_OPTS}
CONFIG_FREERTOS_UNICORE=y
CONFIG_ESPTOOLPY_FLASHMODE_DIO=y
cdefs:
LED_GPIO: 18
LED_ON: 0
BTN_GPIO: -1
BTN_DOWN: 0
RELAY1_GPIO: 21
RELAY2_GPIO: 19
SWITCH1_GPIO: 37
SWITCH2_GPIO: 38
SENSOR_GPIO: 13
PRODUCT_HW_REV: "0.1.4"
STOCK_FW_MODEL: PlusUni
MAX_NUM_HAP_SESSIONS: 16
config_schema:
- ["device.id", "ShellyPlusUni-????????????"]
- ["shelly.name", "ShellyPlusUni--????????????"]
- ["wifi.ap.ssid", "ShellyPlusUni--????????????"]

- ["sw1", "sw", {title: "SW1 settings"}]
- ["sw1.name", "Shelly SW1"]
- ["in1", "in", {title: "Input 1 settings"}]
- ["in1.ssw.name", "Shelly SSW1"]
- ["in1.sensor.name", "Shelly S1"]
- ["sw2", "sw", {title: "SW2 settings"}]
- ["sw2.name", "Shelly SW2"]
- ["in2", "in", {title: "Input 2 settings"}]
- ["in2.ssw.name", "Shelly SSW2"]
- ["in2.sensor.name", "Shelly S2"]
- ["gdo1", "gdo", {title: "GDO1 settings"}]
- ["gdo1.name", "Garage Door"]

- ["ts1", "ts", {title: "TS1 settings"}]
- ["ts1.name", "Shelly TS1"]
- ["ts2", "ts", {title: "TS2 settings"}]
- ["ts2.name", "Shelly TS2"]
- ["ts3", "ts", {title: "TS3 settings"}]
- ["ts3.name", "Shelly TS3"]
- ["ts4", "ts", {title: "TS4 settings"}]
- ["ts4.name", "Shelly TS4"]
- ["ts5", "ts", {title: "TS5 settings"}]
- ["ts5.name", "Shelly TS5"]


- when: build_vars.MODEL == "ShellyVintage"
apply:
name: bulb6w # To allow OTA from stock fw.
Expand Down
3 changes: 2 additions & 1 deletion src/BL0937/shelly_pm_bl0937.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ void BL0937PowerMeter::MeasureTimerCB() {
(int) cf_count, cfps, (int) cf1_count, cf1ps, apa_, aea_));
// Start new measurement cycle.
mgos_ints_disable();
cf_count_ = cf1_count_ = 0;
cf_count_ = 0;
cf1_count_ = 0;
meas_start_ = mgos_uptime_micros();
mgos_ints_enable();
}
Expand Down
2 changes: 1 addition & 1 deletion src/DS18XXX/shelly_temp_sensor_ow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ std::vector<std::unique_ptr<TempSensor>> Onewire::DiscoverAll() {
std::vector<std::unique_ptr<TempSensor>> sensors;
mgos_onewire_search_clean(ow_);
std::unique_ptr<TempSensor> sensor;
while (sensor = NextAvailableSensor(0)) {
while ((sensor = NextAvailableSensor(0))) {
sensors.push_back(std::move(sensor));
}
LOG(LL_INFO, ("Found %i sensors", sensors.size()));
Expand Down
2 changes: 1 addition & 1 deletion src/ShellyMini1PMGen3/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,

void PrintCalibrationData() {
mgos_config_factory *c = &(mgos_sys_config.factory);
LOG(LL_INFO, ("calibration.done %Q", c->calib.done));
LOG(LL_INFO, ("calibration.done %b", c->calib.done));
mgos_config_scales *s = &c->calib.scales0;
LOG(LL_INFO, ("gains vs: %f cs: %f ps: %f es: %f", s->voltage_scale,
s->current_scale, s->apower_scale, s->aenergy_scale));
Expand Down
12 changes: 9 additions & 3 deletions src/ShellyPlus2PM/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,15 @@ static Status PowerMeterInit(std::vector<std::unique_ptr<PowerMeter>> *pms) {
.current_pga_gain_1 = 0, // MGOS_ADE7953_PGA_GAIN_8,
};

bool new_rev = false;
mgos_config_factory *c = &(mgos_sys_config.factory);
if (c->model != NULL && strcmp(c->model, "SNSW-102P16EU") == 0) {
new_rev = true;
}

int reset_pin = -1;
bool conf_changed = false;
if (c->model != NULL && strcmp(c->model, "SNSW-102P16EU") == 0) {
if (new_rev) {
if (mgos_sys_config_get_i2c_sda_gpio() != 26) {
mgos_sys_config_set_i2c_sda_gpio(26);
conf_changed = true;
Expand Down Expand Up @@ -120,9 +124,11 @@ static Status PowerMeterInit(std::vector<std::unique_ptr<PowerMeter>> *pms) {
}

Status st;
std::unique_ptr<PowerMeter> pm1(new ADE7953PowerMeter(1, s_ade7953, 0));
std::unique_ptr<PowerMeter> pm1(
new ADE7953PowerMeter(1, s_ade7953, (new_rev ? 0 : 1)));
if (!(st = pm1->Init()).ok()) return st;
std::unique_ptr<PowerMeter> pm2(new ADE7953PowerMeter(2, s_ade7953, 1));
std::unique_ptr<PowerMeter> pm2(
new ADE7953PowerMeter(2, s_ade7953, (new_rev ? 1 : 0)));
if (!(st = pm2->Init()).ok()) return st;

pms->emplace_back(std::move(pm1));
Expand Down
55 changes: 32 additions & 23 deletions src/ShellyUNI/shelly_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,55 +17,64 @@

#include <algorithm>

#include "shelly_dht_sensor.hpp"
#include "shelly_hap_garage_door_opener.hpp"
#include "shelly_hap_input.hpp"
#include "shelly_hap_window_covering.hpp"
#include "shelly_main.hpp"
#include "shelly_noisy_input_pin.hpp"
#include "shelly_sys_led_btn.hpp"
#include "shelly_temp_sensor_ow.hpp"

namespace shelly {

static std::unique_ptr<Onewire> s_onewire;
static std::vector<std::unique_ptr<TempSensor>> sensors;

void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
std::vector<std::unique_ptr<Output>> *outputs,
std::vector<std::unique_ptr<PowerMeter>> *pms,
std::unique_ptr<TempSensor> *sys_temp) {
outputs->emplace_back(new OutputPin(1, 15, 1));
outputs->emplace_back(new OutputPin(2, 4, 1));
auto *in1 = new NoisyInputPin(1, 12, 1, MGOS_GPIO_PULL_NONE, true);
in1->AddHandler(std::bind(&HandleInputResetSequence, in1, 4, _1, _2));
outputs->emplace_back(new OutputPin(1, RELAY1_GPIO, 1));
outputs->emplace_back(new OutputPin(2, RELAY2_GPIO, 1));
auto *in1 = new NoisyInputPin(1, SWITCH1_GPIO, 1, MGOS_GPIO_PULL_NONE, true);
in1->AddHandler(std::bind(&HandleInputResetSequence, in1, LED_GPIO, _1, _2));
in1->Init();
inputs->emplace_back(in1);
auto *in2 = new NoisyInputPin(2, 13, 1, MGOS_GPIO_PULL_NONE, false);
auto *in2 = new NoisyInputPin(2, SWITCH2_GPIO, 1, MGOS_GPIO_PULL_NONE, false);
in2->Init();
inputs->emplace_back(in2);

s_onewire.reset(new Onewire(SENSOR_GPIO, SENSOR_GPIO));
sensors = s_onewire->DiscoverAll();
if (sensors.empty()) {
s_onewire.reset();
sensors = DiscoverDHTSensors(SENSOR_GPIO, SENSOR_GPIO);
}

InitSysLED(LED_GPIO, LED_ON);
InitSysBtn(BTN_GPIO, BTN_DOWN);
}

void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
std::vector<std::unique_ptr<mgos::hap::Accessory>> *accs,
HAPAccessoryServerRef *svr) {
// Garage door opener mode.
if (mgos_sys_config_get_shelly_mode() == 2) {
auto *gdo_cfg = (struct mgos_config_gdo *) mgos_sys_config_get_gdo1();
std::unique_ptr<hap::GarageDoorOpener> gdo(new hap::GarageDoorOpener(
1, FindInput(1), FindInput(2), FindOutput(1), FindOutput(2), gdo_cfg));
if (gdo == nullptr || !gdo->Init().ok()) {
return;
}
gdo->set_primary(true);
mgos::hap::Accessory *pri_acc = (*accs)[0].get();
pri_acc->SetCategory(kHAPAccessoryCategory_GarageDoorOpeners);
pri_acc->AddService(gdo.get());
comps->emplace_back(std::move(gdo));
return;
bool gdo_mode = mgos_sys_config_get_shelly_mode() == (int) Mode::kGarageDoor;

if (gdo_mode) {
hap::CreateHAPGDO(1, FindInput(1), FindInput(2), FindOutput(1),
FindOutput(2), mgos_sys_config_get_gdo1(), comps, accs,
svr, true);
} else {
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(),
comps, accs, svr, false /* to_pri_acc */);
CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_in2(),
comps, accs, svr, false /* to_pri_acc */);
}

CreateHAPSwitch(1, mgos_sys_config_get_sw1(), mgos_sys_config_get_in1(),
comps, accs, svr, false /* to_pri_acc */);
CreateHAPSwitch(2, mgos_sys_config_get_sw2(), mgos_sys_config_get_in2(),
comps, accs, svr, false /* to_pri_acc */);
if (!sensors.empty()) {
CreateHAPSensors(&sensors, comps, accs, svr);
}
}

} // namespace shelly
2 changes: 1 addition & 1 deletion src/noisy_input_pin/shelly_noisy_input_pin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ static IRAM void GPIOHWTimerCB(void *arg) {
for (i = 0; i < NUM_SAMPLES; i++) {
if (s_gpio_vals[i] != gpio_vals) return;
}
s_meas_cnt++;
s_meas_cnt = s_meas_cnt + 1;
// Has anything changed?
if (s_gpio_last == gpio_vals) return;
s_gpio_last = gpio_vals;
Expand Down
14 changes: 7 additions & 7 deletions src/shelly_rpc_service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,13 @@ static void AppendWifiInfoExt(std::string *res) {
uint32_t digest[8];
mbedtls_sha256_context ctx;
mbedtls_sha256_init(&ctx);
mbedtls_sha256_starts_ret(&ctx, 0 /* is224 */);
mbedtls_sha256_update_ret(&ctx, (uint8_t *) device_id, strlen(device_id));
mbedtls_sha256_update_ret(&ctx, (uint8_t *) wc.sta.ssid.data(),
wc.sta.ssid.length());
mbedtls_sha256_update_ret(&ctx, (uint8_t *) wc.sta.pass.data(),
wc.sta.pass.length());
mbedtls_sha256_finish_ret(&ctx, (uint8_t *) digest);
mbedtls_sha256_starts(&ctx, 0 /* is224 */);
mbedtls_sha256_update(&ctx, (uint8_t *) device_id, strlen(device_id));
mbedtls_sha256_update(&ctx, (uint8_t *) wc.sta.ssid.data(),
wc.sta.ssid.length());
mbedtls_sha256_update(&ctx, (uint8_t *) wc.sta.pass.data(),
wc.sta.pass.length());
mbedtls_sha256_finish(&ctx, (uint8_t *) digest);
mbedtls_sha256_free(&ctx);
std::string wifi_pass = ScreenPassword(wc.sta.pass);
std::string wifi1_pass = ScreenPassword(wc.sta1.pass);
Expand Down

0 comments on commit daa70a2

Please sign in to comment.