Skip to content

Commit

Permalink
Merge pull request #3408 from CurlyMoo/shelly-ds18b20
Browse files Browse the repository at this point in the history
Support for Shelly 1 temp. addon
  • Loading branch information
TD-er authored Dec 4, 2020
2 parents e8c7781 + 09b737e commit e2fa4e3
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 145 deletions.
9 changes: 8 additions & 1 deletion docs/source/Plugin/P004_DS18b20.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ Sensor
GPIO <--> 1-wire
""""""""""""""""

Pin used for communicating with the Dallas sensor(s).
Pin used for communicating with the Dallas sensor(s). This is the single wire setup so you can leave the TX GPIO empty or set it equal to the RX GPIO.

Please note the pin must be pulled up by a resistor, so only use pins that can be in a pulled up state during boot (thus NOT use GPIO 15 on ESP8266).

GPIO <--> Shelly Temperature add-on
"""""""""""""""""""""""""""""""""""

The Shelly temperature add-on requires a two wire setup. Set TX to GPIO 3 and RX to GPIO 0.

Please note GPIO 3 is normally used by Serial 0 which is enabled by default. You might run into issues when not disabling the Serial port first (Tools > Advanced > Enable Serial port).

Number Output Values
""""""""""""""""""""

Expand Down
33 changes: 21 additions & 12 deletions src/_P004_Dallas.ino
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string)
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_004;
Device[deviceCount].Type = DEVICE_TYPE_SINGLE;
Device[deviceCount].Type = DEVICE_TYPE_DUAL;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Expand Down Expand Up @@ -114,17 +114,22 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string)

case PLUGIN_GET_DEVICEGPIONAMES:
{
event->String1 = formatGpioName_bidirectional(F("1-Wire"));
event->String1 = formatGpioName_RX(false);
event->String2 = formatGpioName_TX(true);
break;
}

case PLUGIN_WEBFORM_LOAD:
{
// Scan the onewire bus and fill dropdown list with devicecount on this GPIO.
int8_t Plugin_004_DallasPin = CONFIG_PIN1;
int8_t Plugin_004_DallasPin_RX = CONFIG_PIN1;
int8_t Plugin_004_DallasPin_TX = CONFIG_PIN2;
if(Plugin_004_DallasPin_TX == -1) {
Plugin_004_DallasPin_TX = Plugin_004_DallasPin_RX;
}

if (Plugin_004_DallasPin != -1) {
Dallas_addr_selector_webform_load(event->TaskIndex, Plugin_004_DallasPin, P004_NR_OUTPUT_VALUES);
if (Plugin_004_DallasPin_RX != -1 && Plugin_004_DallasPin_TX != -1) {
Dallas_addr_selector_webform_load(event->TaskIndex, Plugin_004_DallasPin_RX, Plugin_004_DallasPin_TX, P004_NR_OUTPUT_VALUES);

{
// Device Resolution select
Expand All @@ -134,7 +139,7 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string)
Dallas_plugin_get_addr(savedAddress, event->TaskIndex);

if (savedAddress[0] != 0) {
activeRes = Dallas_getResolution(savedAddress, Plugin_004_DallasPin);
activeRes = Dallas_getResolution(savedAddress, Plugin_004_DallasPin_RX, Plugin_004_DallasPin_TX);
}

int resolutionChoice = P004_RESOLUTION;
Expand Down Expand Up @@ -176,11 +181,15 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string)

case PLUGIN_WEBFORM_SAVE:
{
int8_t Plugin_004_DallasPin = CONFIG_PIN1;
int8_t Plugin_004_DallasPin_RX = CONFIG_PIN1;
int8_t Plugin_004_DallasPin_TX = CONFIG_PIN2;
if(Plugin_004_DallasPin_TX == -1) {
Plugin_004_DallasPin_TX = Plugin_004_DallasPin_RX;
}

if (Plugin_004_DallasPin != -1) {
if (Plugin_004_DallasPin_RX != -1 && Plugin_004_DallasPin_TX != -1) {
// save the address for selected device and store into extra tasksettings
Dallas_addr_selector_webform_save(event->TaskIndex, Plugin_004_DallasPin, P004_NR_OUTPUT_VALUES);
Dallas_addr_selector_webform_save(event->TaskIndex, Plugin_004_DallasPin_RX, Plugin_004_DallasPin_TX, P004_NR_OUTPUT_VALUES);

uint8_t res = getFormItemInt(F("p004_res"));

Expand All @@ -189,7 +198,7 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string)

uint8_t savedAddress[8];
Dallas_plugin_get_addr(savedAddress, event->TaskIndex);
Dallas_setResolution(savedAddress, res, Plugin_004_DallasPin);
Dallas_setResolution(savedAddress, res, Plugin_004_DallasPin_RX, Plugin_004_DallasPin_TX);
}
P004_ERROR_STATE_OUTPUT = getFormItemInt(F("p004_err"));
success = true;
Expand Down Expand Up @@ -220,9 +229,9 @@ boolean Plugin_004(byte function, struct EventStruct *event, String& string)
uint8_t addr[8];
Dallas_plugin_get_addr(addr, event->TaskIndex);

if ((addr[0] != 0) && (CONFIG_PIN1 != -1)) {
if ((addr[0] != 0) && (CONFIG_PIN1 != -1) && (CONFIG_PIN2 != -1)) {
const uint8_t res = P004_RESOLUTION;
initPluginTaskData(event->TaskIndex, new (std::nothrow) P004_data_struct(CONFIG_PIN1, addr, res));
initPluginTaskData(event->TaskIndex, new (std::nothrow) P004_data_struct(CONFIG_PIN1, CONFIG_PIN2, addr, res));
P004_data_struct *P004_data =
static_cast<P004_data_struct *>(getPluginTaskData(event->TaskIndex));

Expand Down
10 changes: 5 additions & 5 deletions src/_P080_DallasIButton.ino
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ boolean Plugin_080(byte function, struct EventStruct *event, String& string)
Plugin_080_DallasPin = CONFIG_PIN1;

if (Plugin_080_DallasPin != -1) {
Dallas_addr_selector_webform_load(event->TaskIndex, Plugin_080_DallasPin);
Dallas_addr_selector_webform_load(event->TaskIndex, Plugin_080_DallasPin, Plugin_080_DallasPin);
}
success = true;
break;
Expand All @@ -74,7 +74,7 @@ boolean Plugin_080(byte function, struct EventStruct *event, String& string)
case PLUGIN_WEBFORM_SAVE:
{
// save the address for selected device and store into extra tasksettings
Dallas_addr_selector_webform_save(event->TaskIndex, CONFIG_PIN1);
Dallas_addr_selector_webform_save(event->TaskIndex, CONFIG_PIN1, CONFIG_PIN1);
success = true;
break;
}
Expand All @@ -95,7 +95,7 @@ boolean Plugin_080(byte function, struct EventStruct *event, String& string)
if (Plugin_080_DallasPin != -1) {
uint8_t addr[8];
Dallas_plugin_get_addr(addr, event->TaskIndex);
Dallas_startConversion(addr, Plugin_080_DallasPin);
Dallas_startConversion(addr, Plugin_080_DallasPin, Plugin_080_DallasPin);

delay(800); // give it time to do intial conversion
}
Expand All @@ -111,7 +111,7 @@ boolean Plugin_080(byte function, struct EventStruct *event, String& string)
if (addr[0] != 0) {
Plugin_080_DallasPin = CONFIG_PIN1;

if (Dallas_readiButton(addr, Plugin_080_DallasPin))
if (Dallas_readiButton(addr, Plugin_080_DallasPin, Plugin_080_DallasPin))
{
UserVar[event->BaseVarIndex] = 1;
success = true;
Expand All @@ -120,7 +120,7 @@ boolean Plugin_080(byte function, struct EventStruct *event, String& string)
{
UserVar[event->BaseVarIndex] = 0;
}
Dallas_startConversion(addr, Plugin_080_DallasPin);
Dallas_startConversion(addr, Plugin_080_DallasPin, Plugin_080_DallasPin);

if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
String log = F("DS : iButton: ");
Expand Down
6 changes: 3 additions & 3 deletions src/_P100_DS2423_counter.ino
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ boolean Plugin_100(byte function, struct EventStruct *event, String& string)
int8_t Plugin_100_DallasPin = CONFIG_PIN1;

if (Plugin_100_DallasPin != -1) {
Dallas_addr_selector_webform_load(event->TaskIndex, Plugin_100_DallasPin);
Dallas_addr_selector_webform_load(event->TaskIndex, Plugin_100_DallasPin, Plugin_100_DallasPin);

// Counter select
String resultsOptions[2] = { F("A"), F("B") };
Expand All @@ -80,7 +80,7 @@ boolean Plugin_100(byte function, struct EventStruct *event, String& string)
PCONFIG(0) = getFormItemInt(F("p100_counter"));

// 1-wire device address
Dallas_addr_selector_webform_save(event->TaskIndex, CONFIG_PIN1);
Dallas_addr_selector_webform_save(event->TaskIndex, CONFIG_PIN1, CONFIG_PIN1);

success = true;
break;
Expand Down Expand Up @@ -115,7 +115,7 @@ boolean Plugin_100(byte function, struct EventStruct *event, String& string)
if (CONFIG_PIN1 != -1) {
float value = 0;

if (Dallas_readCounter(addr, &value, CONFIG_PIN1, PCONFIG(0)))
if (Dallas_readCounter(addr, &value, CONFIG_PIN1, CONFIG_PIN1, PCONFIG(0)))
{
UserVar[event->BaseVarIndex] = UserVar[event->BaseVarIndex + 2] != 0
? value - UserVar[event->BaseVarIndex + 1]
Expand Down
1 change: 1 addition & 0 deletions src/src/CustomBuild/define_plugin_sets.h
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ To create/register a plugin, you have to :
#define PLUGIN_SET_ONLY_SWITCH
#define CONTROLLER_SET_STABLE
#define NOTIFIER_SET_STABLE
#define USES_P004 // DS18B20
#endif

#ifdef PLUGIN_SET_SHELLY_PLUG_S
Expand Down
Loading

0 comments on commit e2fa4e3

Please sign in to comment.