Skip to content

Commit dd9215b

Browse files
rojertimoschilling
authored andcommitted
WIP Shelly Plug US support
1 parent 6492dd0 commit dd9215b

File tree

3 files changed

+88
-3
lines changed

3 files changed

+88
-3
lines changed

Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
MAKEFLAGS += --warn-undefined-variables --no-builtin-rules
22

33
.PHONY: build check-format format release upload \
4-
Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlus1 ShellyPlus1PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI
5-
.SUFFIXES:
4+
Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlugUS1 ShellyPlus1 ShellyPlus1PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyUDuo ShellyURGBW2 ShellyUNI
65

76
MOS ?= mos
87
# Build locally by default if Docker is available.
@@ -27,7 +26,7 @@ ifneq "$(VERBOSE)$(V)" "00"
2726
MOS_BUILD_FLAGS_FINAL += --verbose
2827
endif
2928

30-
build: Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlus1 ShellyPlus1PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyURGBW2 ShellyUNI
29+
build: Shelly1 Shelly1L Shelly1PM Shelly25 Shelly2 ShellyColorBulb ShellyDuo ShellyI3 ShellyPlug ShellyPlugS ShellyPlugUS1 ShellyPlus1 ShellyPlus1PM ShellyPlusI4 ShellyRGBW2 ShellyVintage ShellyU ShellyU25 ShellyURGBW2 ShellyUNI
3130

3231
release:
3332
$(MAKE) build CLEAN=1 RELEASE=1
@@ -64,6 +63,9 @@ ShellyPlug: build-ShellyPlug
6463
ShellyPlugS: build-ShellyPlugS
6564
@true
6665

66+
ShellyPlugUS1: build-ShellyPlugUS1
67+
@true
68+
6769
ShellyPlus1: PLATFORM=esp32
6870
ShellyPlus1: build-ShellyPlus1
6971
@true

mos.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,37 @@ conds:
561561
- ["bl0937.power_coeff", "f", 0, {title: "BL0937 counts -> watts conversion coefficient"}]
562562
- ["bl0937.power_coeff", 1.64358469] # (16 + 1010 + 1935) / (9.55 + 617 + 1175)
563563

564+
- when: build_vars.MODEL == "ShellyPlugUS"
565+
apply:
566+
name: shelly-plug-u1
567+
libs:
568+
- location: https://github.com/mongoose-os-libs/mongoose
569+
variant: esp8266-nossl
570+
build_vars:
571+
FLASH_SIZE: 2097152
572+
FS_SIZE: 262144
573+
BOOT_CONFIG_ADDR: 0x7000
574+
MGOS_ROOT_FS_TYPE: SPIFFS
575+
cdefs:
576+
LED_GPIO: 2 # Blue, 0 red.
577+
LED_ON: 0
578+
BTN_GPIO: 13
579+
BTN_DOWN: 0
580+
PRODUCT_HW_REV: '"1.0"'
581+
STOCK_FW_MODEL: '"SHPLG-U1"'
582+
MG_ENABLE_SSL: 0
583+
config_schema:
584+
- ["device.id", "shellyplugu1-??????"]
585+
- ["shelly.name", "shellyplugu1-??????"]
586+
- ["wifi.ap.ssid", "shellyplugu1-??????"]
587+
- ["sw1", "sw", {title: "Plug settings"}]
588+
- ["sw1.name", "Shelly Plug US"]
589+
- ["sw1.in_mode", -1]
590+
- ["sw1.svc_type", 1] # Outlet
591+
- ["sw1.initial_state", 2]
592+
- ["sw1.state_led_en", 1]
593+
- ["bl0937.power_coeff", 1.64358469] # Same as ShellyPlugS
594+
564595
- when: build_vars.MODEL == "ShellyPlus1"
565596
apply:
566597
name: Plus1

src/ShellyPlugUS1/shelly_init.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Shelly-HomeKit Contributors
3+
* All rights reserved
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "shelly_main.hpp"
19+
#include "shelly_output.hpp"
20+
#include "shelly_pm_bl0937.hpp"
21+
#include "shelly_temp_sensor_ntc.hpp"
22+
23+
namespace shelly {
24+
25+
static OutputPin *s_led_out = nullptr;
26+
27+
void CreatePeripherals(std::vector<std::unique_ptr<Input>> *inputs,
28+
std::vector<std::unique_ptr<Output>> *outputs,
29+
std::vector<std::unique_ptr<PowerMeter>> *pms,
30+
std::unique_ptr<TempSensor> *sys_temp) {
31+
outputs->emplace_back(new OutputPin(1, 15, 1));
32+
s_led_out = new OutputPin(99, 0, 0); // Red LED.
33+
std::unique_ptr<PowerMeter> pm(
34+
new BL0937PowerMeter(1, 5 /* CF */, 14 /* CF1 */, 12 /* SEL */, 2));
35+
const Status &st = pm->Init();
36+
if (st.ok()) {
37+
pms->emplace_back(std::move(pm));
38+
} else {
39+
const std::string &s = st.ToString();
40+
LOG(LL_ERROR, ("PM init failed: %s", s.c_str()));
41+
}
42+
sys_temp->reset(new TempSensorSDNT1608X103F3950(0, 3.3f, 33000.0f));
43+
}
44+
45+
void CreateComponents(std::vector<std::unique_ptr<Component>> *comps,
46+
std::vector<std::unique_ptr<mgos::hap::Accessory>> *accs,
47+
HAPAccessoryServerRef *svr) {
48+
CreateHAPSwitch(1, mgos_sys_config_get_sw1(), nullptr, comps, accs, svr,
49+
true /* to_pri_acc */, s_led_out);
50+
}
51+
52+
} // namespace shelly

0 commit comments

Comments
 (0)