xoseperez / espurna

Home automation firmware for ESP8266-based devices
http://tinkerman.cat
GNU General Public License v3.0
2.98k stars 635 forks source link

Using Wemos D1 mini with multiple GPIO inputs #1815

Closed davebuk closed 5 years ago

davebuk commented 5 years ago

I have a D1 mini and plan to use it with MQTT and openHab as the main hardware interface for a house alarm system. The idea is to have the currently installed hard wired PIRs feed their N/C outputs into the GPIO pins and report the 0/1 status for triggering the alarm once armed.

I have used cushom.h file with DIGITAL_PIN definitions but only got GPIO 14 to show in the status page. Another post says I should use EVENTS_PIN instead as this will give a real time MQTT response. Either way, my configuration does not give any more than one reading on the status page, just GPIO 14.

#elif defined(WEMOS_D1_MINI_RELAYSHIELD)

    // Info
    #define MANUFACTURER        "WEMOS"
    #define DEVICE              "D1_MINI_RELAYSHIELD"

    #define ALEXA_SUPPORT           0
    #define DOMOTICZ_SUPPORT        0
    #define HOMEASSISTANT_SUPPORT   0
    #define SCHEDULER_SUPPORT       0
    #define THINGSPEAK_SUPPORT      0
    #define DEBUG_SERIAL_SUPPORT    0

    // Buttons
    // No buttons on the D1 MINI alone, but defining it without adding a button doen't create problems
    #define BUTTON1_PIN          0   // Connect a pushbutton between D3 and GND,
                                     // it's the same as using a Wemos one button shield
    #define BUTTON1_MODE         BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
    #define BUTTON1_RELAY        1

    // Relays
    #define RELAY1_PIN           5  // D1
    #define RELAY1_TYPE          RELAY_TYPE_INVERSE

    // LED
    #define LED1_PIN             2  // D4
    #define LED1_PIN_INVERSE     1

    //Digital Event support

    #define EVENTS_SUPPORT       1
    #define EVENTS_TRIGGER      1
    #define EVENTS_PIN           3  // RX
    #define EVENTS_PIN_MODE      INPUT_PULLUP
    #define EVENTS_INTERRUPT_MODE   CHANGE
    #define EVENTS_PIN           4  // D2
    #define EVENTS_PIN_MODE      INPUT_PULLUP
    #define EVENTS_INTERRUPT_MODE   CHANGE
    #define EVENTS_PIN           12  // D6
    #define EVENTS_PIN_MODE      INPUT_PULLUP
    #define EVENTS_INTERRUPT_MODE   CHANGE
    #define EVENTS_PIN           13  // D7
    #define EVENTS_PIN_MODE      INPUT_PULLUP
    #define EVENTS_INTERRUPT_MODE   CHANGE    
    #define EVENTS_PIN           14  // D5
    #define EVENTS_PIN_MODE      INPUT_PULLUP
    #define EVENTS_INTERRUPT_MODE   CHANGE
ColinShorts commented 5 years ago

Each iteration of the events pin definition overwrites the last, but that would be the expected behaviour of the code.

I.e:

A = 1 A = 2 A = 3 print A

3

davebuk commented 5 years ago

So I can't use digital or events pin definitions for multiple GPIOs?

I guess I could try multiple toggle switch definitions and make sure web GUI or mqtt doesn't change the switch state, just the 0/1 on the GPIO pins?

ColinShorts commented 5 years ago

I don't think you'd have too much of a latency issue using normal button/switch defines over mqtt, the only time I see any lag is from the sonoff pir/door switches connecting via the RF bridge - I usually make it to the bottom of the stairs before the light comes on. The T1's that I use in mqtt groups (additional units as slaves) all switch in around half a second or so.

BUTTON_SWITCH will send an event on opening and closing, BUTTON_PUSHBUTTON will only send an event when it releases (so it might not work as desired). Pushbutton might also give you problems on certain gpio's when using n/c (I use a sonoff dual that's buried in the wall, and so occasionally I forget to switch off the light switches before restoring power to the light circuit. I've got connected to it's gpio... And it goes into programming mode every time 😆

Alternatively, there are a few Arduino based setups that might be more reliable, particularly if you can get it hard wired over Ethernet to your LAN. It should be feasible to use a really cheap spi based module, albeit at a fairly slow speed, which should still be plenty for mqtt. I've used them on rpi's in the past, and they worked first time as soon as spi was enabled ofc.

I wish I had a hard wired alarm system.

davebuk commented 5 years ago

Thanks for the info. I'd planned to use BUTTON_SWITCH so I didn't have any issues with the long click etc. It would be nice to have the actual open/close state via mqtt but know SWITCH can't do that. For my application state toggle should be fine. I'll see how I get on and look at Arduino in the future if I want more capability.

davebuk commented 5 years ago

@mcspr @xoseperez Can multiple digital sensors be added to the sensor.h file? Possibly their status could be used WRT #1747 with an mqtt 'sync' option to read the HIGH/LOW state of a GPIO associated with a button/switch and update everything to match the switch position.

davebuk commented 5 years ago

I have tried with BUTTON_PUSHBUTTON for now, but the following config only gives one switch (Switch#0 at GPIO5). After testing the GPIOs I see the button presses and MQTT appears in the debug screen. I presumed all of the switches would appear on the status page, but this is not the case!

#elif defined(WEMOS_D1_MINI_RELAYSHIELD)

    // Info
    #define MANUFACTURER        "WEMOS"
    #define DEVICE              "D1_MINI_RELAYSHIELD"
    #define BUTTON_EVENT_NONE           0
    #define BUTTON_EVENT_PRESSED        1
    #define BUTTON_EVENT_RELEASED       2

    #define ALEXA_SUPPORT           0
    #define DOMOTICZ_SUPPORT        0
    #define HOMEASSISTANT_SUPPORT   0
    #define SCHEDULER_SUPPORT       0
    #define SENSOR_SUPPORT          0
    #define THINGSPEAK_SUPPORT      0
    #define DEBUG_SERIAL_SUPPORT    0

    // Buttons
    // No buttons on the D1 MINI alone, but defining it without adding a button doen't create problems
    #define BUTTON1_PIN          0   // Connect a pushbutton between D3 and GND,
                                     // it's the same as using a Wemos one button shield
    #define BUTTON1_MODE         BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH
    #define BUTTON1_RELAY        1
    // GPIO Buttons

    #define BUTTON2_PIN         3  //RX
    #define BUTTON2_MODE        BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP
    #define BUTTON2_PRESS       BUTTON_MODE_OFF
    #define BUTTON2_CLICK       BUTTON_MODE_ON
    #define BUTTON2_DBLCLICK        BUTTON_MODE_NONE
    #define BUTTON2_LNGCLICK        BUTTON_MODE_NONE
    #define BUTTON2_LNGLNGCLICK     BUTTON_MODE_NONE

    #define BUTTON3_PIN         4  //D2
    #define BUTTON3_MODE        BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP
    #define BUTTON3_PRESS       BUTTON_MODE_OFF
    #define BUTTON3_CLICK       BUTTON_MODE_ON
    #define BUTTON3_DBLCLICK        BUTTON_MODE_NONE
    #define BUTTON3_LNGCLICK        BUTTON_MODE_NONE
    #define BUTTON3_LNGLNGCLICK     BUTTON_MODE_NONE

    #define BUTTON4_PIN         12  //D6
    #define BUTTON4_MODE        BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP
    #define BUTTON4_PRESS       BUTTON_MODE_OFF
    #define BUTTON4_CLICK       BUTTON_MODE_ON
    #define BUTTON4_DBLCLICK        BUTTON_MODE_NONE
    #define BUTTON4_LNGCLICK        BUTTON_MODE_NONE
    #define BUTTON4_LNGLNGCLICK     BUTTON_MODE_NONE

    #define BUTTON5_PIN         13  //D7
    #define BUTTON5_MODE        BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP 
    #define BUTTON5_PRESS       BUTTON_MODE_OFF
    #define BUTTON5_CLICK       BUTTON_MODE_ON
    #define BUTTON5_DBLCLICK        BUTTON_MODE_NONE
    #define BUTTON5_LNGCLICK        BUTTON_MODE_NONE
    #define BUTTON5_LNGLNGCLICK     BUTTON_MODE_NONE

    #define BUTTON6_PIN         14  //D5
    #define BUTTON6_MODE        BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP
    #define BUTTON6_PRESS       BUTTON_MODE_OFF
    #define BUTTON6_CLICK       BUTTON_MODE_ON
    #define BUTTON6_DBLCLICK        BUTTON_MODE_NONE
    #define BUTTON6_LNGCLICK        BUTTON_MODE_NONE
    #define BUTTON6_LNGLNGCLICK     BUTTON_MODE_NONE

    // Relays
    #define RELAY1_PIN           5  // D1
    #define RELAY1_TYPE          RELAY_TYPE_INVERSE

    // LED
    #define LED1_PIN             2  // D4
    #define LED1_PIN_INVERSE     1

Anyway, pulsing some of the pins to ground and open I get the following in the debug screen. I should be able to use the MQTT button=1 as a trigger.

[035541] [BUTTON] Button #1 event 5
[036172] [BUTTON] Button #1 event 1
[036175] [MQTT] Sending D1mini001/button/1 => 1 (PID 1)
[041234] [BUTTON] Button #1 event 4
[045289] [BUTTON] Button #1 event 1
[045291] [MQTT] Sending D1mini001/button/1 => 1 (PID 1)
[049389] [BUTTON] Button #1 event 4
[051873] [BUTTON] Button #1 event 1
[051876] [MQTT] Sending D1mini001/button/1 => 1 (PID 1)
[060003] [MAIN] System OK
[204849] [BUTTON] Button #2 event 4
[209027] [BUTTON] Button #2 event 1
[209030] [MQTT] Sending D1mini001/button/2 => 1 (PID 1)
[215162] [BUTTON] Button #2 event 4
[217759] [BUTTON] Button #2 event 1
[217761] [MQTT] Sending D1mini001/button/2 => 1 (PID 1)
[227513] [BUTTON] Button #1 event 5
[233342] [BUTTON] Button #1 event 1
[233345] [MQTT] Sending D1mini001/button/1 => 1 (PID 1)
[237624] [BUTTON] Button #1 event 4
[237990] [BUTTON] Button #1 event 1
[237992] [MQTT] Sending D1mini001/button/1 => 1 (PID 1)
[241865] [BUTTON] Button #1 event 4
[242019] [BUTTON] Button #1 event 1
[242021] [MQTT] Sending D1mini001/button/1 => 1 (PID 1)
[242296] [BUTTON] Button #1 event 1
[242298] [MQTT] Sending D1mini001/button/1 => 1 (PID 1)
[244459] [BUTTON] Button #1 event 3
[249385] [BUTTON] Button #1 event 1
[249387] [MQTT] Sending D1mini001/button/1 => 1 (PID 1)
[254689] [BUTTON] Button #3 event 5
[255633] [BUTTON] Button #3 event 1
[255635] [MQTT] Sending D1mini001/button/3 => 1 (PID 1)
[261587] [BUTTON] Button #3 event 4
[261700] [BUTTON] Button #3 event 1
[261703] [MQTT] Sending D1mini001/button/3 => 1 (PID 1)
[263701] [BUTTON] Button #3 event 4
[265498] [BUTTON] Button #3 event 1
mcspr commented 5 years ago

I have tried with BUTTON_PUSHBUTTON for now, but the following config only gives one switch (Switch#0 at GPIO5).

Based on config, 5 buttons are linked to the single switch and expected behaviour is to release the switch when no buttons are pressed? As I understand it, you do run into the same issue as was discussed in the #1747 - buttons handle events, not status. Since you disabled handlers for events 4 and 5 (long clicks), you don't receive them (see BUTTON_MQTT_SEND_ALL_EVENTS) and also don't trigger the relay switch, because button stays pressed for much longer than the short press timeout.

Other issue has a PR linked that proposes sending pressed status instead of event, but not sure how that would work better - as a configuration for type of the thing that gets reported (event number or boolean pressed status), or additional action. Configuration naming too... DigitalSensor is another option, but would require sensor.ino modification to have multiple sensors created instead of just one EventsSensor is more of event counter than something for triggers. It can sort-of do that, but that imo is an overkill for buttons

davebuk commented 5 years ago

Based on config, 5 buttons are linked to the single switch and expected behaviour is to release the switch when no buttons are pressed?

Not quite. I want 5 GPIOs to monitor the state of 5 PIRs (which are NC contacts when no movement detected) and report OPEN/CLOSED using MQTT (and ideally show their status it the web GUI). OpenHAB would then use the state change of a virtual switch when the virtual alarm system is set as 'armed'. If the system is triggered, OpenHAB then switches Switch#0 on, activating the low level trigger relay and applying power to the sounder. After a time period or deactivation of Switch#0, the sounder goes off.

As I understand it, you do run into the same issue as was discussed in the #1747 - buttons handle events, not status. Since you disabled handlers for events 4 and 5 (long clicks), you don't receive them (see BUTTON_MQTT_SEND_ALL_EVENTS) and also don't trigger the relay switch, because button stays pressed for much longer than the short press timeout.

Playing around I saw that and made adjustments. All events now report their status to MQTT. Long and Longlong give 4 and 5 and when open gives 1. OpenHAB can then use, IF switch is NOT 1, no movement (OPEN or OFF), IF 1, movement (CLOSED or ON). I did have the odd event '6' appear. Not sure what state that represents? I also tried BUTTON_SWITCH but of course that only reports event 2, regardless of state.

Other issue has a PR linked that proposes sending pressed status instead of event, but not sure how that would work better - as a configuration for type of the thing that gets reported (event number or boolean pressed status), or additional action. Configuration naming too... DigitalSensor is another option, but would require sensor.ino modification to have multiple sensors created instead of just one EventsSensor is more of event counter than something for triggers. It can sort-of do that, but that imo is an overkill for buttons

Just looking at the Wiki, I assumed DigitalSensor would allow multiple sensors and report 0/1 for each one, but it only allows the one GPIO. I'll look at sensor.ino, but my coding knowledge is pretty limited. :-)

davebuk commented 5 years ago

Next step is to add RFID arm/disarm #1800!

mcspr commented 5 years ago

I did have the odd event '6' appear. Not sure what state that represents?

Sorry to reference code again, but that was triple click: https://github.com/xoseperez/espurna/blob/0998110d869264a893f8a0df6eff833620c7a4cb/code/espurna/config/types.h#L32-L39 (which should probably be printed in the debug log, at the very least. maybe optionally, send this translation instead of evt number to mqtt)

For multiple sensors, this needs to be duplicated per sensor (including curly braces): https://github.com/xoseperez/espurna/blob/1d133bee16b4c953d43959cfceede12eec389e0c/code/espurna/sensor.ino#L576-L582 https://github.com/xoseperez/espurna/blob/1d133bee16b4c953d43959cfceede12eec389e0c/code/espurna/sensor.ino#L469-L476 Which, again, could be configured via settings at runtime whenever DIGITAL_SUPPORT is on. Each header config option could get an index (a-la BMX280 config in the same method)

davebuk commented 5 years ago

@ColinShorts @mcspr Thanks for the info. The Wiki is missing a few things, like event 6 stated above, so your knowledge is invaluable!

I'll try and find some time at the weekend to modify sensor.ino and build using digital sensors again. It seems the best solution for my project.

davebuk commented 5 years ago

For multiple sensors, this needs to be duplicated per sensor (including curly braces): https://github.com/xoseperez/espurna/blob/1d133bee16b4c953d43959cfceede12eec389e0c/code/espurna/sensor.ino#L576-L582

And multiple entries in sensor.h file?

#ifndef DIGITAL_PIN2
#define DIGITAL_PIN2                     3
#endif

#ifndef DIGITAL_PIN_MODE2
#define DIGITAL_PIN_MODE2                INPUT_PULLUP
#endif

#ifndef DIGITAL_DEFAULT_STATE2
#define DIGITAL_DEFAULT_STATE2 

etc...

davebuk commented 5 years ago

Getting there! digital IPs

Last piece of the puzzle. MQTT will only show the digital states with respect to the refresh rate set in the sensor tab of the web GUI. If a sensor goes 1 to 0 and back to 1, MQTT dosen't post that state unless the state is at 0 during its refresh cycle. Is there another setting is sensor.ino to report to MQTT on state change like the EVENT_PIN setup?

davebuk commented 5 years ago

I wonder if DIGITAL_PIN is not supported. WRT #1186, this does seem to be the case. I have added a set of extra EVENT_PIN entries to my sensor.ino and sensor.h files. I now have five Count# entries on the status page. This works well as MQTT reports the change of state as 1 and 0 and will periodically send the current MQTT states as well.

event IPs

The only strange issue is that Count#3 says its @GPIO3, but is set to 13 in custom.h? edit: I had left the number 4 off in sensor.ino configuration. Working now

    #define EVENTS_PIN4           13  // D7
    #define EVENTS_PIN_MODE4      INPUT_PULLUP
    #define EVENTS_INTERRUPT_MODE4  CHANGE
mcspr commented 5 years ago

DigitalSensor is reading every sensor read interval, unlike EventsSensor. Note that with recent change I tried to speed up events processing by removing immediate callback call and caching it for a bit. Hope that works ok (including debounce time, my main worry are missing values)

Digital one could have the same trigger mechanics, imitating the buttons pin reader with some modifications *edit: Something to think about though, because right now it is a separate thing from normal reporting mechanism. But this would allow to have something specifically for this purpose, leaving buttons to events

ColinShorts commented 5 years ago

@davebuk, how long do the pir's hold the "switch" open? I wouldn't imagine that the state would change that rapidly. @mcspr's changes might be good enough for your use case already.

davebuk commented 5 years ago

Probably a maximum of 1 second. Doing a 'walk test', three out of the five show MQTT state changes on every trigger (1) and then 0 when not triggered. I think I need external pull up resistors for the other two PIRs. I'll look to try that this weekend.

davebuk commented 5 years ago

All five PIR's are now working with pull up resistors. A few lines from debug are below, but all Sensors#0-4 give the correct outputs when triggered. Thanks again for all your help.

[708744] [SENSOR] Sensor #4 callback, type 14, payload: '1.00'
[708747] [MQTT] Sending D1mini001/event/4 => 1 (PID 1)
[713047] [SENSOR] Sensor #4 callback, type 14, payload: '0.00'
[713050] [MQTT] Sending D1mini001/event/4 => 0 (PID 1)
[719297] [SENSOR] Sensor #4 callback, type 14, payload: '1.00'
[719299] [MQTT] Sending D1mini001/event/4 => 1 (PID 1)
[720121] [MQTT] Sending D1mini001/count/0 => 0 (PID 1)
[720123] [MQTT] Sending D1mini001/event/0 => 0 (PID 1)
[720126] [MQTT] Sending D1mini001/count/1 => 0 (PID 1)
[720127] [MQTT] Sending D1mini001/event/1 => 0 (PID 1)
[720129] [MQTT] Sending D1mini001/count/2 => 0 (PID 1)
[720132] [MQTT] Sending D1mini001/event/2 => 0 (PID 1)
[720134] [MQTT] Sending D1mini001/count/3 => 0 (PID 1)
[720136] [MQTT] Sending D1mini001/event/3 => 0 (PID 1)
[720140] [MQTT] Sending D1mini001/count/4 => 3 (PID 1)
[720142] [MQTT] Sending D1mini001/event/4 => 0 (PID 1)
[739058] [SENSOR] Sensor #4 callback, type 14, payload: '0.00'
[739061] [MQTT] Sending D1mini001/event/4 => 0 (PID 1)
[748657] [SENSOR] Sensor #0 callback, type 14, payload: '1.00'
[748660] [MQTT] Sending D1mini001/event/0 => 1 (PID 1)
[750123] [MQTT] Sending D1mini001/count/0 => 1 (PID 1)
[750126] [MQTT] Sending D1mini001/event/0 => 0 (PID 1)
ruimarinho commented 4 years ago

@davebuk I'm trying to get the Wemos PIR shield working on a Wemos D1 Mini with the following config:

ESPURNA_FLAGS='-DEVENTS_SUPPORT=1 -DEVENTS1_PIN=0 -DBUTTON_MQTT_SEND_ALL_EVENTS=1'

The PIR is HIGH on GPI0 (D3) when motion is detected. However, the interrupt is not getting triggered with motion:

[001005] [SENSOR] INTERRUPT @ GPIO0 - count: 0

Any ideas?

davebuk commented 4 years ago

I don't know of a specific reason, the only thing I have set differently is to enable INPUT_PULLUP to use the pull up resistors.

davebuk commented 4 years ago

I'm surprised it uses GPIO0 as if that pin in low at boot, the device is being put into flash mode. I don't build using the flags, I use platformio with a custom.h file and build using -DUSE_CUSTOM_H. I then set all the #define options in the custom.h file. See comments in the hardware.h file for info.

ruimarinho commented 4 years ago

What is the expected message I should be seeing? A button sensor log?

davebuk commented 4 years ago

AFAIK the button events flag you have set is for any configured buttons, not the event sensor you have added.

Looking at my output i the debug screen: https://github.com/xoseperez/espurna/issues/1815#issuecomment-511153476 its the 'sensor call back' that that triggers an instantaneous output and MQTT output. The sensor output you have referred to, I believe, its output depends on the Read/Report interval set in the 'SENSORS' tab in the webUI.

You could test the wemos GPIO pin by having the PIR disconnected for now and using a piece of wire to pulse your GPIO to the GND pin or the 3V3 pin and see what happens. Do you have a status page similar to mine: https://github.com/xoseperez/espurna/issues/1815#issuecomment-511028088 When my PIRs go from LOW to HIGH (NC or open circuit) the count goes up on the status page for that configured GPIO.

davebuk commented 4 years ago

The other thing, https://github.com/xoseperez/espurna/wiki/Sensors#counter-sensor states the default trigger is 'rising'. I changed mine in custom.h to use 'change' (not 'both', think wiki is wrong) so it reports all triggers.

ruimarinho commented 4 years ago

I've removed the PIR shield and pulsing GPIO0 to GND gives me some interesting results. Is it normal to crash the Wemos if I keep the "pulse" long enough (e.g. 2 seconds)?

Sometimes only a [BUTTON] event is dispatched, other times I see a [SENSOR] callback as well.

[027140] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[027140] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[028145] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[028145] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[028875] [BUTTON] Button #0 event 1
[029149] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[029149] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[030153] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[030154] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[031158] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[031159] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[032162] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[032163] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[032233] [BUTTON] Button #0 event 4
[032234] [SENSOR] Sensor #0 callback, type 14, payload: '1.00' -- pulse too long here

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09826c6d
~ld
[000371]

With the PIR shield installed, every time there is motion, the Wemos crashes (cc @mcspr):

[001004] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[001004] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[001907] [BUTTON] Button #0 event 1
[002009] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[002009] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[003013] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[003013] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[004017] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[004017] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[005021] [SENSOR] INTERRUPT @ GPIO0 - count: 0
[005022] [SENSOR] INTERRUPT @ GPIO0 - event: 0
[005882] [BUTTON] Button #0 event 4
[005882] [SENSOR] Sensor #0 callback, type 14, payload: '1.00'

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09826c6d
~ld
[000371] [MAIN] System UNSTABLE
[000373]

---8<-------
davebuk commented 4 years ago

See: https://github.com/xoseperez/espurna/blob/274f71d7d9047bb2bdf6b5c2cca7a6ff9d63142b/code/espurna/config/hardware.h#L98 All default builds of wemos devices set GPIO/D3 as a button1. Long press will trigger button events.

I would change the GPIO pin used on your PIR board to another one and configure wemos accordingly.

bluexp1 commented 3 years ago

Getting there! digital IPs

Last piece of the puzzle. MQTT will only show the digital states with respect to the refresh rate set in the sensor tab of the web GUI. If a sensor goes 1 to 0 and back to 1, MQTT dosen't post that state unless the state is at 0 during its refresh cycle. Is there another setting is sensor.ino to report to MQTT on state change like the EVENT_PIN setup?

I have problem activating digital input/event in 1.14.1 version. I have edited arduino.h and sensor.h but digital inputs are not shown in web interface. Is there any steps I missed? arduino.h

//--------------------------------------------------------------------------------
// These settings are normally provided by PlatformIO
// Uncomment the appropiate line(s) to build from the Arduino IDE
//--------------------------------------------------------------------------------

//--------------------------------------------------------------------------------
// Hardware
//--------------------------------------------------------------------------------

//#define AITHINKER_AI_LIGHT
//#define ALLNET_4DUINO_IOT_WLAN_RELAIS
//#define ALLTERCO_SHELLY1
//#define ALLTERCO_SHELLY1PM
//#define ALLTERCO_SHELLY2
//#define ALLTERCO_SHELLY25
//#define ARILUX_AL_LC01
//#define ARILUX_AL_LC02
//#define ARILUX_AL_LC02_V14
//#define ARILUX_AL_LC06
//#define ARILUX_AL_LC11
//#define ARILUX_E27
//#define ARNIEX_SWIFITCH
//#define AUTHOMETION_LYT8266
//#define BESTEK_MRJ1011
//#define BH_ONOFRE
//#define BLITZWOLF_BWSHPX
//#define BLITZWOLF_BWSHPX_V23
//#define BLITZWOLF_BWSHP5
//#define DIGOO_NX_SP202
//#define EHOMEDIY_WT02
//#define EHOMEDIY_WT03
//#define ELECTRODRAGON_WIFI_IOT
//#define ESPURNA_BASE
//#define ESPURNA_CORE
//#define ETEKCITY_ESW01_USA
//#define EUROMATE_WIFI_STECKER_SCHUKO
//#define EUROMATE_WIFI_STECKER_SCHUKO_V2
//#define EXS_WIFI_RELAY_V31
//#define EXS_WIFI_RELAY_V50
//#define FORNORM_ZLD_34EU
//#define FOXEL_LIGHTFOX_DUAL
//#define FS_UAP1
//#define GBLIFE_RGBW_SOCKET
//#define GENERIC_8CH
//#define GENERIC_AG_L4
//#define GENERIC_ECH1560
//#define GENERIC_ESP01S_DHT11_V10
//#define GENERIC_ESP01S_DS18B20_V10
//#define GENERIC_ESP01S_RELAY_V40
//#define GENERIC_ESP01S_RGBLED_V10
//#define GENERIC_GU10
//#define GENERIC_E14
//#define GENERIC_V9261F
//#define GIZWITS_WITTY_CLOUD
//#define GOSUND_WS1
//#define GREEN_ESP8266RELAY
//#define HAMA_WIFI_STECKDOSE_00176533
//#define HELTEC_TOUCHRELAY
//#define HEYGO_HY02
//#define HOMECUBE_16A
//#define HUACANXING_H801
//#define HUACANXING_H802
//#define HYKKER_SMART_HOME_POWER_PLUG
//#define IKE_ESPIKE
//#define INTERMITTECH_QUINLED
//#define ISELECTOR_SM_PW702
//#define ITEAD_1CH_INCHING
//#define ITEAD_BNSZ01
//#define ITEAD_MOTOR
//#define ITEAD_S20
//#define ITEAD_SLAMPHER
//#define ITEAD_SONOFF_4CH
//#define ITEAD_SONOFF_4CH_PRO
//#define ITEAD_SONOFF_B1
//#define ITEAD_SONOFF_BASIC
//#define ITEAD_SONOFF_DUAL
//#define ITEAD_SONOFF_DUAL_R2
//#define ITEAD_SONOFF_IFAN02
//#define ITEAD_SONOFF_LED
//#define ITEAD_SONOFF_MINI
//#define ITEAD_SONOFF_POW
//#define ITEAD_SONOFF_POW_R2
//#define ITEAD_SONOFF_RF
//#define ITEAD_SONOFF_RFBRIDGE
//#define ITEAD_SONOFF_S31
//#define ITEAD_SONOFF_S31_LITE
//#define ITEAD_SONOFF_SV
//#define ITEAD_SONOFF_T1_1CH
//#define ITEAD_SONOFF_T1_2CH
//#define ITEAD_SONOFF_T1_3CH
//#define ITEAD_SONOFF_TH
//#define ITEAD_SONOFF_TOUCH
//#define IWOOLE_LED_TABLE_LAMP
//#define JANGOE_WIFI_RELAY_NC
//#define JANGOE_WIFI_RELAY_NO
//#define JINVOO_VALVE_SM_AW713
//#define JORGEGARCIA_WIFI_RELAYS
//#define KMC_70011
//#define LINGAN_SWA1
//#define LINKSPRITE_LINKNODE_R4
//#define LITESUN_LA_WF3
//#define LOHAS_E27_9W
//#define LOHAS_E26_A19
//#define LOMBEX_LUX_NOVA2_TUNABLE_WHITE
//#define LOMBEX_LUX_NOVA2_WHITE_COLOR
//#define LUANI_HVIO
//#define LYASI_LIGHT
//#define MAGICHOME_LED_CONTROLLER
//#define MAGICHOME_LED_CONTROLLER_20
//#define MAGICHOME_ZJ_ESPM_5CH_B_13
//#define MAGICHOME_ZJ_WFMN_A_11
//#define MAGICHOME_ZJ_WFMN_B_11
//#define MAGICHOME_ZJ_WFMN_C_11
//#define MANCAVEMADE_ESPLIVE
//#define MAXCIO_WDE004
//#define MAXCIO_WUS002S
//#define MUVIT_IO_MIOBULB001
//#define NEO_COOLCAM_NAS_WR01W
//#define NEXETE_A19
//#define NODEMCU_BASIC
#define NODEMCU_LOLIN
//#define OPENENERGYMONITOR_MQTT_RELAY
//#define ORVIBO_B25
//#define OUKITEL_P1
//#define PHYX_ESP12_RGB
//#define PILOTAK_ESP_DIN_V1
//#define PSH_RGBW_CONTROLLER
//#define PSH_WIFI_PLUG
//#define PSH_WIFI_SENSOR
//#define SMARTLIFE_MINI_SMART_SOCKET
//#define STM_RELAY
//#define TECKIN_SP20
//#define TECKIN_SP21
//#define TECKIN_SP22_V14
//#define TFLAG_NX_SMX00
//#define TINKERMAN_ESPURNA_H06
//#define TINKERMAN_ESPURNA_H08
//#define TINKERMAN_ESPURNA_SWITCH
//#define TINKERMAN_RFM69GW
//#define TONBUX_MOSQUITO_KILLER
//#define TONBUX_POWERSTRIP02
//#define TONBUX_XSSSA01
//#define TONBUX_XSSSA06
//#define TUYA_GENERIC_DIMMER
//#define VANZAVANZU_SMART_WIFI_PLUG_MINI
//#define WEMOS_D1_MINI
//#define WEMOS_D1_MINI_RELAYSHIELD
//#define WEMOS_D1_TARPUNA_SHIELD
//#define WION_50055
//#define WORKCHOICE_ECOPLUG
//#define XENON_SM_PW702U
//#define XIAOMI_SMART_DESK_LAMP
//#define YIDIAN_XSSSA05
//#define YJZK_SWITCH_1CH
//#define YJZK_SWITCH_2CH
//#define YJZK_SWITCH_3CH
//#define ZHILDE_EU44_W

//--------------------------------------------------------------------------------
// Features (values below are non-default values)
//--------------------------------------------------------------------------------

//#define ALEXA_SUPPORT          0
//#define API_SUPPORT            0
//#define BROKER_SUPPORT         0
//#define BUTTON_SUPPORT         0
//#define DEBUG_SERIAL_SUPPORT   0
//#define DEBUG_TELNET_SUPPORT   0
//#define DEBUG_UDP_SUPPORT      1
//#define DEBUG_WEB_SUPPORT      0
//#define DOMOTICZ_SUPPORT       0
//#define ENCODER_SUPPORT        1
//#define HOMEASSISTANT_SUPPORT  0
//#define I2C_SUPPORT            1
//#define INFLUXDB_SUPPORT       1
//#define IR_SUPPORT             1
//#define LED_SUPPORT            0
//#define LLMNR_SUPPORT          1  // Only with latest Arduino Core
//#define MDNS_CLIENT_SUPPORT    1
//#define MDNS_SERVER_SUPPORT    0
//#define MQTT_SUPPORT           0
//#define NETBIOS_SUPPORT        1  // Only with latest Arduino Core
//#define NOFUSS_SUPPORT         1
//#define NTP_SUPPORT            0
//#define OTA_ARDUINOOTA_SUPPORT 1
//#define RFM69_SUPPORT          1
//#define RF_SUPPORT             1
//#define RPN_RULES_SUPPORT      0
//#define SCHEDULER_SUPPORT      0
//#define SPIFFS_SUPPORT         1
//#define SSDP_SUPPORT           1
//#define TELNET_SUPPORT         0
//#define TERMINAL_SUPPORT       0
//#define THINGSPEAK_SUPPORT     0
//#define TUYA_SUPPORT           0
//#define UART_MQTT_SUPPORT      1
//#define WEB_SUPPORT            0

//--------------------------------------------------------------------------------
// Sensors (values below are non-default values)
//--------------------------------------------------------------------------------

//#define ADE7953_SUPPORT        1
//#define AM2320_SUPPORT         1
//#define ANALOG_SUPPORT         1
//#define BH1750_SUPPORT         1
//#define BMP180_SUPPORT         1
//#define BMX280_SUPPORT         1
//#define CSE7766_SUPPORT        1
#define DALLAS_SUPPORT         1
#define DHT_SUPPORT            1
#define DIGITAL_SUPPORT        1
//#define ECH1560_SUPPORT        1
//#define EMON_ADC121_SUPPORT    1
//#define EMON_ADS1X15_SUPPORT   1
//#define EMON_ANALOG_SUPPORT    1
#define EVENTS_SUPPORT         1
//#define EZOPH_SUPPORT          1
//#define GEIGER_SUPPORT         1
//#define GUVAS12SD_SUPPORT      1
//#define HLW8012_SUPPORT        1
//#define LDR_SUPPORT            1
//#define MAX6675_SUPPORT        1
//#define MHZ19_SUPPORT          1
//#define MICS2710_SUPPORT       1
//#define MICS5525_SUPPORT       1
//#define NTC_SUPPORT            1
//#define PMSX003_SUPPORT        1
//#define PULSEMETER_SUPPORT     1
//#define PZEM004T_SUPPORT       1
//#define SDS011_SUPPORT         1
//#define SENSEAIR_SUPPORT       1
//#define SHT3X_I2C_SUPPORT      1
//#define SI7021_SUPPORT         1
//#define SONAR_SUPPORT          1
//#define T6613_SUPPORT          1
//#define THERMOSTAT_SUPPORT     1
//#define TMP3X_SUPPORT          1
//#define V9261F_SUPPORT         1
//#define VEML6075_SUPPORT       1
//#define VL53L1X_SUPPORT        1

` sensors.h

// =============================================================================
// SENSORS - General data
// =============================================================================

#define SENSOR_DEBUG                        0               // Debug sensors

#define SENSOR_READ_INTERVAL                6               // Read data from sensors every 6 seconds
#define SENSOR_READ_MIN_INTERVAL            6               // Minimum read interval
#define SENSOR_READ_MAX_INTERVAL            3600            // Maximum read interval
#define SENSOR_INIT_INTERVAL                10000           // Try to re-init non-ready sensors every 10s

#define SENSOR_REPORT_EVERY                 10              // Report every this many readings
#define SENSOR_REPORT_MIN_EVERY             1               // Minimum every value
#define SENSOR_REPORT_MAX_EVERY             60              // Maximum

#define SENSOR_USE_INDEX                    0               // Use the index in topic (i.e. temperature/0)
                                                            // even if just one sensor (0 for backwards compatibility)

#ifndef SENSOR_POWER_CHECK_STATUS
#define SENSOR_POWER_CHECK_STATUS           1               // If set to 1 the reported power/current/energy will be 0 if the relay[0] is OFF
#endif

#ifndef SENSOR_TEMPERATURE_CORRECTION
#define SENSOR_TEMPERATURE_CORRECTION       0.0             // Offset correction
#endif

#ifndef TEMPERATURE_MIN_CHANGE
#define TEMPERATURE_MIN_CHANGE              0.0             // Minimum temperature change to report
#endif

#ifndef SENSOR_HUMIDITY_CORRECTION
#define SENSOR_HUMIDITY_CORRECTION          0.0             // Offset correction
#endif

#ifndef HUMIDITY_MIN_CHANGE
#define HUMIDITY_MIN_CHANGE                 0               // Minimum humidity change to report
#endif

#ifndef ENERGY_MAX_CHANGE
#define ENERGY_MAX_CHANGE                   0               // Maximum energy change to report (if >0 it will allways report when delta(E) is greater than this)
#endif

#ifndef SENSOR_SAVE_EVERY
#define SENSOR_SAVE_EVERY                   0               // Save accumulating values to EEPROM (atm only energy)
                                                            // A 0 means do not save and it's the default value
                                                            // A number different from 0 means it should store the value in EEPROM
                                                            // after these many reports
                                                            // Warning: this might wear out flash fast!
#endif

#define SENSOR_PUBLISH_ADDRESSES            0               // Publish sensor addresses
#define SENSOR_ADDRESS_TOPIC                "address"       // Topic to publish sensor addresses

#ifndef SENSOR_TEMPERATURE_UNITS
#define SENSOR_TEMPERATURE_UNITS            TMP_CELSIUS     // Temperature units (TMP_CELSIUS | TMP_FAHRENHEIT)
#endif

#ifndef SENSOR_ENERGY_UNITS
#define SENSOR_ENERGY_UNITS                 ENERGY_JOULES   // Energy units (ENERGY_JOULES | ENERGY_KWH)
#endif

#ifndef SENSOR_POWER_UNITS
#define SENSOR_POWER_UNITS                  POWER_WATTS     // Power units (POWER_WATTS | POWER_KILOWATTS)
#endif

// =============================================================================
// Specific data for each sensor
// =============================================================================

//------------------------------------------------------------------------------
// AM2320 Humidity & Temperature sensor over I2C
// Enable support by passing AM2320_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef AM2320_SUPPORT
#define AM2320_SUPPORT                  0
#endif

#ifndef AM2320_ADDRESS
#define AM2320_ADDRESS                  0x00    // 0x00 means auto
#endif

//------------------------------------------------------------------------------
// Analog sensor
// Enable support by passing ANALOG_SUPPORT=1 build flag
//--------------------------------------------------------------------------------

#ifndef ANALOG_SUPPORT
#define ANALOG_SUPPORT                  0
#endif

#ifndef ANALOG_SAMPLES
#define ANALOG_SAMPLES                  10      // Number of samples
#endif

#ifndef ANALOG_DELAY
#define ANALOG_DELAY                    0       // Delay between samples in micros
#endif

//Use the following to perform scaling of raw analog values
//   scaledRead = ( factor * rawRead ) + offset
//
//Please take note that the offset is not affected by the scaling factor

#ifndef ANALOG_FACTOR
#define ANALOG_FACTOR                    1.0       // Multiply raw reading by this factor
#endif

#ifndef ANALOG_OFFSET
#define ANALOG_OFFSET                    0.0       // Add this offset to *scaled* value
#endif

// Round to this number of decimals
#ifndef ANALOG_DECIMALS
#define ANALOG_DECIMALS                  2
#endif

//------------------------------------------------------------------------------
// BH1750
// Enable support by passing BH1750_SUPPORT=1 build flag
// http://www.elechouse.com/elechouse/images/product/Digital%20light%20Sensor/bh1750fvi-e.pdf
//------------------------------------------------------------------------------

#ifndef BH1750_SUPPORT
#define BH1750_SUPPORT                  0
#endif

#ifndef BH1750_ADDRESS
#define BH1750_ADDRESS                  0x00    // 0x00 means auto
#endif

#define BH1750_MODE                     BH1750_CONTINUOUS_HIGH_RES_MODE

//------------------------------------------------------------------------------
// BMP085/BMP180
// Enable support by passing BMP180_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef BMP180_SUPPORT
#define BMP180_SUPPORT                  0
#endif

#ifndef BMP180_ADDRESS
#define BMP180_ADDRESS                  0x00    // 0x00 means auto
#endif

#define BMP180_MODE                     3       // 0 for ultra-low power, 1 for standard, 2 for high resolution and 3 for ultrahigh resolution

//------------------------------------------------------------------------------
// BME280/BMP280
// Enable support by passing BMX280_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef BMX280_SUPPORT
#define BMX280_SUPPORT                  0
#endif

#ifndef BMX280_NUMBER
#define BMX280_NUMBER                   1       // Number of sensors present. Either 1 or 2 allowed
#endif
#ifndef BMX280_ADDRESS
#define BMX280_ADDRESS                  0x00    // 0x00 means auto (0x76 or 0x77 allowed) for sensor #0
#endif                                          // If (BMX280_NUMBER == 2) and
                                                //   (BMX280_ADDRESS == 0x00) then sensor #1 is auto-discovered
                                                //   (BMX280_ADDRESS != 0x00) then sensor #1 is the unnamed address

#ifndef BMX280_MODE
#define BMX280_MODE                     1       // 0 for sleep mode, 1 or 2 for forced mode, 3 for normal mode
#endif
#ifndef BMX280_STANDBY
#define BMX280_STANDBY                  0       // 0 for 0.5ms, 1 for 62.5ms, 2 for 125ms
                                                // 3 for 250ms, 4 for 500ms, 5 for 1000ms
                                                // 6 for 10ms, 7 for 20ms
#endif
#ifndef BMX280_FILTER
#define BMX280_FILTER                   0       // 0 for OFF, 1 for 2 values, 2 for 4 values, 3 for 8 values and 4 for 16 values
#endif
#ifndef BMX280_TEMPERATURE
#define BMX280_TEMPERATURE              1       // Oversampling for temperature (set to 0 to disable magnitude)
                                                // 0b000 = 0 = Skip measurement
                                                // 0b001 = 1 = 1x 16bit/0.0050C resolution
                                                // 0b010 = 2 = 2x 17bit/0.0025C
                                                // 0b011 = 3 = 4x 18bit/0.0012C
                                                // 0b100 = 4 = 8x 19bit/0.0006C
                                                // 0b101 = 5 = 16x 20bit/0.0003C
#endif
#ifndef BMX280_HUMIDITY
#define BMX280_HUMIDITY                 1       // Oversampling for humidity (set to 0 to disable magnitude, only for BME280)
                                                // 0b000 = 0 = Skip measurement
                                                // 0b001 = 1 = 1x 0.07% resolution
                                                // 0b010 = 2 = 2x 0.05%
                                                // 0b011 = 3 = 4x 0.04%
                                                // 0b100 = 4 = 8x 0.03%
                                                // 0b101 = 5 = 16x 0.02%
#endif
#ifndef BMX280_PRESSURE
#define BMX280_PRESSURE                 1       // Oversampling for pressure (set to 0 to disable magnitude)
                                                // 0b000 = 0 = Skipped
                                                // 0b001 = 1 = 1x 16bit/2.62 Pa resolution
                                                // 0b010 = 2 = 2x 17bit/1.31 Pa
                                                // 0b011 = 3 = 4x 18bit/0.66 Pa
                                                // 0b100 = 4 = 8x 19bit/0.33 Pa
                                                // 0b101 = 5 = 16x 20bit/0.16 Pa
#endif

//------------------------------------------------------------------------------
// Dallas OneWire temperature sensors
// Enable support by passing DALLAS_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef DALLAS_SUPPORT
#define DALLAS_SUPPORT                  0
#endif

#ifndef DALLAS_PIN
#define DALLAS_PIN                      5
#endif

#define DALLAS_RESOLUTION               9           // Not used atm
#define DALLAS_READ_INTERVAL            2000        // Force sensor read & cache every 2 seconds

//------------------------------------------------------------------------------
// DHTXX temperature/humidity sensor
// Enable support by passing DHT_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef DHT_SUPPORT
#define DHT_SUPPORT                     0
#endif

#ifndef DHT_PIN
#define DHT_PIN                         4
#endif

#ifndef DHT_TYPE
#define DHT_TYPE                        DHT_CHIP_DHT11
#endif

//------------------------------------------------------------------------------
// CSE7766 based power sensor
// Enable support by passing CSE7766_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef CSE7766_SUPPORT
#define CSE7766_SUPPORT                 0
#endif

#ifndef CSE7766_PIN
#define CSE7766_PIN                     1       // TX pin from the CSE7766
#endif

#ifndef CSE7766_PIN_INVERSE
#define CSE7766_PIN_INVERSE             0       // Signal is inverted
#endif

#define CSE7766_SYNC_INTERVAL           300     // Safe time between transmissions (ms)
#define CSE7766_BAUDRATE                4800    // UART baudrate

#define CSE7766_V1R                     1.0     // 1mR current resistor
#define CSE7766_V2R                     1.0     // 1M voltage resistor

//------------------------------------------------------------------------------
// Digital sensor
// Enable support by passing DIGITAL_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef DIGITAL_SUPPORT
#define DIGITAL_SUPPORT                 0
#endif

#ifndef DIGITAL1_PIN
#define DIGITAL1_PIN                     14
#endif

#ifndef DIGITAL1_PIN_MODE
#define DIGITAL1_PIN_MODE                INPUT
#endif

#ifndef DIGITAL1_DEFAULT_STATE
#define DIGITAL1_DEFAULT_STATE           0
#endif

#ifndef DIGITAL2_PIN
#define DIGITAL2_PIN                     2
#endif

#ifndef DIGITAL2_PIN_MODE
#define DIGITAL2_PIN_MODE                INPUT_PULLUP
#endif

#ifndef DIGITAL2_DEFAULT_STATE
#define DIGITAL2_DEFAULT_STATE           1
#endif

#ifndef DIGITAL3_PIN
#define DIGITAL3_PIN                     2
#endif

#ifndef DIGITAL3_PIN_MODE
#define DIGITAL3_PIN_MODE                INPUT_PULLUP
#endif

#ifndef DIGITAL3_DEFAULT_STATE
#define DIGITAL3_DEFAULT_STATE           1
#endif

#ifndef DIGITAL4_PIN
#define DIGITAL4_PIN                     2
#endif

#ifndef DIGITAL4_PIN_MODE
#define DIGITAL4_PIN_MODE                INPUT_PULLUP
#endif

#ifndef DIGITAL4_DEFAULT_STATE
#define DIGITAL4_DEFAULT_STATE           1
#endif

#ifndef DIGITAL5_PIN
#define DIGITAL5_PIN                     2
#endif

#ifndef DIGITAL5_PIN_MODE
#define DIGITAL5_PIN_MODE                INPUT_PULLUP
#endif

#ifndef DIGITAL5_DEFAULT_STATE
#define DIGITAL5_DEFAULT_STATE           1
#endif

#ifndef DIGITAL6_PIN
#define DIGITAL6_PIN                     2
#endif

#ifndef DIGITAL6_PIN_MODE
#define DIGITAL6_PIN_MODE                INPUT_PULLUP
#endif

#ifndef DIGITAL6_DEFAULT_STATE
#define DIGITAL6_DEFAULT_STATE           1
#endif

#ifndef DIGITAL7_PIN
#define DIGITAL7_PIN                     2
#endif

#ifndef DIGITAL7_PIN_MODE
#define DIGITAL7_PIN_MODE                INPUT_PULLUP
#endif

#ifndef DIGITAL7_DEFAULT_STATE
#define DIGITAL7_DEFAULT_STATE           1
#endif

#ifndef DIGITAL8_PIN
#define DIGITAL8_PIN                     2
#endif

#ifndef DIGITAL8_PIN_MODE
#define DIGITAL8_PIN_MODE                INPUT_PULLUP
#endif

#ifndef DIGITAL8_DEFAULT_STATE
#define DIGITAL8_DEFAULT_STATE           1
#endif

//------------------------------------------------------------------------------
// ECH1560 based power sensor
// Enable support by passing ECH1560_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef ECH1560_SUPPORT
#define ECH1560_SUPPORT                 0
#endif

#ifndef ECH1560_CLK_PIN
#define ECH1560_CLK_PIN                 4       // CLK pin for the ECH1560
#endif

#ifndef ECH1560_MISO_PIN
#define ECH1560_MISO_PIN                5       // MISO pin for the ECH1560
#endif

#ifndef ECH1560_INVERTED
#define ECH1560_INVERTED                0       // Signal is inverted
#endif

//------------------------------------------------------------------------------
// Energy Monitor general settings
//------------------------------------------------------------------------------

#define EMON_MAX_SAMPLES                1000        // Max number of samples to get
#define EMON_MAX_TIME                   250         // Max time in ms to sample
#define EMON_FILTER_SPEED               512         // Mobile average filter speed
#define EMON_REFERENCE_VOLTAGE          3.3         // Reference voltage of the ADC

#ifndef EMON_MAINS_VOLTAGE
#define EMON_MAINS_VOLTAGE              230         // Mains voltage
#endif

#ifndef EMON_CURRENT_RATIO
#define EMON_CURRENT_RATIO              30          // Current ratio in the clamp (30A/1V)
#endif

#ifndef EMON_REPORT_CURRENT

#define EMON_REPORT_CURRENT             0           // Report current
#endif

#ifndef EMON_REPORT_POWER
#define EMON_REPORT_POWER               1           // Report power
#endif

#ifndef EMON_REPORT_ENERGY
#define EMON_REPORT_ENERGY              1           // Report energy
#endif

//------------------------------------------------------------------------------
// Energy Monitor based on ADC121
// Enable support by passing EMON_ADC121_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef EMON_ADC121_SUPPORT
#define EMON_ADC121_SUPPORT             0       // Do not build support by default
#endif

#define EMON_ADC121_I2C_ADDRESS         0x00    // 0x00 means auto

//------------------------------------------------------------------------------
// Energy Monitor based on ADS1X15
// Enable support by passing EMON_ADS1X15_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef EMON_ADS1X15_SUPPORT
#define EMON_ADS1X15_SUPPORT            0       // Do not build support by default
#endif

#define EMON_ADS1X15_I2C_ADDRESS        0x00    // 0x00 means auto
#define EMON_ADS1X15_TYPE               ADS1X15_CHIP_ADS1115
#define EMON_ADS1X15_GAIN               ADS1X15_REG_CONFIG_PGA_4_096V
#define EMON_ADS1X15_MASK               0x0F    // A0=1 A1=2 A2=4 A3=8

//------------------------------------------------------------------------------
// Energy Monitor based on interval analog GPIO
// Enable support by passing EMON_ANALOG_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef EMON_ANALOG_SUPPORT
#define EMON_ANALOG_SUPPORT             0       // Do not build support by default
#endif

//------------------------------------------------------------------------------
// Counter sensor
// Enable support by passing EVENTS_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef EVENTS_SUPPORT
#define EVENTS_SUPPORT                  0       // Do not build with counter support by default
#endif

#ifndef EVENTS1_TRIGGER
#define EVENTS1_TRIGGER                  1       // 1 to trigger callback on events,
                                                // 0 to only count them and report periodically
#endif

#ifndef EVENTS1_PIN
#define EVENTS1_PIN                      14       // GPIO to monitor
#endif

#ifndef EVENTS1_PIN_MODE
#define EVENTS1_PIN_MODE                 INPUT   // INPUT, INPUT_PULLUP
#endif

#ifndef EVENTS1_INTERRUPT_MODE
#define EVENTS1_INTERRUPT_MODE           RISING  // RISING, FALLING, CHANGE
#endif

#ifndef EVENTS1_DEBOUNCE
#define EVENTS1_DEBOUNCE                 50      // Do not register events within less than 50 millis
#endif

#ifndef EVENTS2_TRIGGER
#define EVENTS2_TRIGGER                  1       // 1 to trigger callback on events,
                                                // 0 to only count them and report periodically
#endif

#ifndef EVENTS2_PIN
#define EVENTS2_PIN                      2       // GPIO to monitor
#endif

#ifndef EVENTS2_PIN_MODE
#define EVENTS2_PIN_MODE                 INPUT   // INPUT, INPUT_PULLUP
#endif

#ifndef EVENTS2_INTERRUPT_MODE
#define EVENTS2_INTERRUPT_MODE           RISING  // RISING, FALLING, CHANGE
#endif

#ifndef EVENTS2_DEBOUNCE
#define EVENTS2_DEBOUNCE                 50      // Do not register events within less than 50 millis
#endif

#ifndef EVENTS3_TRIGGER
#define EVENTS3_TRIGGER                  1       // 1 to trigger callback on events,
                                                // 0 to only count them and report periodically
#endif

#ifndef EVENTS3_PIN
#define EVENTS3_PIN                      2       // GPIO to monitor
#endif

#ifndef EVENTS3_PIN_MODE
#define EVENTS3_PIN_MODE                 INPUT   // INPUT, INPUT_PULLUP
#endif

#ifndef EVENTS3_INTERRUPT_MODE
#define EVENTS3_INTERRUPT_MODE           RISING  // RISING, FALLING, CHANGE
#endif

#ifndef EVENTS3_DEBOUNCE
#define EVENTS3_DEBOUNCE                 50      // Do not register events within less than 50 millis
#endif

#ifndef EVENTS4_TRIGGER
#define EVENTS4_TRIGGER                  1       // 1 to trigger callback on events,
                                                // 0 to only count them and report periodically
#endif

#ifndef EVENTS4_PIN
#define EVENTS4_PIN                      2       // GPIO to monitor
#endif

#ifndef EVENTS4_PIN_MODE
#define EVENTS4_PIN_MODE                 INPUT   // INPUT, INPUT_PULLUP
#endif

#ifndef EVENTS4_INTERRUPT_MODE
#define EVENTS4_INTERRUPT_MODE           RISING  // RISING, FALLING, CHANGE
#endif

#ifndef EVENTS4_DEBOUNCE
#define EVENTS4_DEBOUNCE                 50      // Do not register events within less than 50 millis
#endif

#ifndef EVENTS5_TRIGGER
#define EVENTS5_TRIGGER                  1       // 1 to trigger callback on events,
                                                // 0 to only count them and report periodically
#endif

#ifndef EVENTS5_PIN
#define EVENTS5_PIN                      2       // GPIO to monitor
#endif

#ifndef EVENTS5_PIN_MODE
#define EVENTS5_PIN_MODE                 INPUT   // INPUT, INPUT_PULLUP
#endif

#ifndef EVENTS5_INTERRUPT_MODE
#define EVENTS5_INTERRUPT_MODE           RISING  // RISING, FALLING, CHANGE
#endif

#ifndef EVENTS5_DEBOUNCE
#define EVENTS5_DEBOUNCE                 50      // Do not register events within less than 50 millis
#endif

#ifndef EVENTS6_TRIGGER
#define EVENTS6_TRIGGER                  1       // 1 to trigger callback on events,
                                                // 0 to only count them and report periodically
#endif

#ifndef EVENTS6_PIN
#define EVENTS6_PIN                      2       // GPIO to monitor
#endif

#ifndef EVENTS6_PIN_MODE
#define EVENTS6_PIN_MODE                 INPUT   // INPUT, INPUT_PULLUP
#endif

#ifndef EVENTS6_INTERRUPT_MODE
#define EVENTS6_INTERRUPT_MODE           RISING  // RISING, FALLING, CHANGE
#endif

#ifndef EVENTS6_DEBOUNCE
#define EVENTS6_DEBOUNCE                 50      // Do not register events within less than 50 millis
#endif

#ifndef EVENTS7_TRIGGER
#define EVENTS7_TRIGGER                  1       // 1 to trigger callback on events,
                                                // 0 to only count them and report periodically
#endif

#ifndef EVENTS7_PIN
#define EVENTS7_PIN                      2       // GPIO to monitor
#endif

#ifndef EVENTS7_PIN_MODE
#define EVENTS7_PIN_MODE                 INPUT   // INPUT, INPUT_PULLUP
#endif

#ifndef EVENTS7_INTERRUPT_MODE
#define EVENTS7_INTERRUPT_MODE           RISING  // RISING, FALLING, CHANGE
#endif

#ifndef EVENTS7_DEBOUNCE
#define EVENTS7_DEBOUNCE                 50      // Do not register events within less than 50 millis
#endif

#ifndef EVENTS8_TRIGGER
#define EVENTS8_TRIGGER                  1       // 1 to trigger callback on events,
                                                // 0 to only count them and report periodically
#endif

#ifndef EVENTS8_PIN
#define EVENTS8_PIN                      2       // GPIO to monitor
#endif

#ifndef EVENTS8_PIN_MODE
#define EVENTS8_PIN_MODE                 INPUT   // INPUT, INPUT_PULLUP
#endif

#ifndef EVENTS8_INTERRUPT_MODE
#define EVENTS8_INTERRUPT_MODE           RISING  // RISING, FALLING, CHANGE
#endif

#ifndef EVENTS8_DEBOUNCE
#define EVENTS8_DEBOUNCE                 50      // Do not register events within less than 50 millis
#endif

//------------------------------------------------------------------------------
// Geiger sensor
// Enable support by passing GEIGER_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef GEIGER_SUPPORT
#define GEIGER_SUPPORT                  0       // Do not build with geiger support by default
#endif

#ifndef GEIGER_PIN
#define GEIGER_PIN                      D1       // GPIO to monitor "D1" => "GPIO5"
#endif

#ifndef GEIGER_PIN_MODE
#define GEIGER_PIN_MODE                 INPUT   // INPUT, INPUT_PULLUP
#endif

#ifndef GEIGER_INTERRUPT_MODE
#define GEIGER_INTERRUPT_MODE           RISING  // RISING, FALLING, CHANGE
#endif

#define GEIGER_DEBOUNCE                 25      // Do not register events within less than 25 millis.
                                                // Value derived here: Debounce time 25ms, because https://github.com/Trickx/espurna/wiki/Geiger-counter

#define GEIGER_CPM2SIEVERT              240     // CPM to µSievert per hour conversion factor
                                                // Typically the literature uses the invers, but I find an integer type more convienient.
#define GEIGER_REPORT_SIEVERTS          1       // Enabler for local dose rate reports in µSv/h
#define GEIGER_REPORT_CPM               1       // Enabler for local dose rate reports in counts per minute

//------------------------------------------------------------------------------
// GUVAS12SD UV Sensor (analog)
// Enable support by passing GUVAS12SD_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef GUVAS12SD_SUPPORT
#define GUVAS12SD_SUPPORT               0
#endif

#ifndef GUVAS12SD_PIN
#define GUVAS12SD_PIN                   14
#endif

//------------------------------------------------------------------------------
// HLW8012 Energy monitor IC
// Enable support by passing HLW8012_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef HLW8012_SUPPORT
#define HLW8012_SUPPORT                 0
#endif

#ifndef HLW8012_SEL_PIN
#define HLW8012_SEL_PIN                 5
#endif

#ifndef HLW8012_CF1_PIN
#define HLW8012_CF1_PIN                 13
#endif

#ifndef HLW8012_CF_PIN
#define HLW8012_CF_PIN                  14
#endif

#ifndef HLW8012_SEL_CURRENT
#define HLW8012_SEL_CURRENT             HIGH    // SEL pin to HIGH to measure current
#endif

#ifndef HLW8012_CURRENT_R
#define HLW8012_CURRENT_R               0.001   // Current resistor
#endif

#ifndef HLW8012_VOLTAGE_R_UP
#define HLW8012_VOLTAGE_R_UP            ( 5 * 470000 )  // Upstream voltage resistor
#endif

#ifndef HLW8012_VOLTAGE_R_DOWN
#define HLW8012_VOLTAGE_R_DOWN          ( 1000 )        // Downstream voltage resistor
#endif

#ifndef HLW8012_CURRENT_RATIO
#define HLW8012_CURRENT_RATIO           0       // Set to 0 to use factory defaults
#endif

#ifndef HLW8012_VOLTAGE_RATIO
#define HLW8012_VOLTAGE_RATIO           0       // Set to 0 to use factory defaults
#endif

#ifndef HLW8012_POWER_RATIO
#define HLW8012_POWER_RATIO             0       // Set to 0 to use factory defaults
#endif

#ifndef HLW8012_USE_INTERRUPTS
#define HLW8012_USE_INTERRUPTS          1       // Use interrupts to trap HLW8012 signals
#endif

#ifndef HLW8012_WAIT_FOR_WIFI
#define HLW8012_WAIT_FOR_WIFI           0       // Weather to enable interrupts only after
                                                // wifi connection has been stablished
#endif

#ifndef HLW8012_INTERRUPT_ON
#define HLW8012_INTERRUPT_ON            CHANGE  // When to trigger the interrupt
                                                // Use CHANGE for HLW8012
                                                // Use FALLING for BL0937 / HJL0
#endif

//------------------------------------------------------------------------------
// LDR sensor
// Enable support by passing LDR_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef SENSOR_LUX_CORRECTION
#define SENSOR_LUX_CORRECTION           0.0     // Offset correction
#endif

#ifndef LDR_SUPPORT
#define LDR_SUPPORT                     0
#endif

#ifndef LDR_SAMPLES
#define LDR_SAMPLES                     10      // Number of samples
#endif

#ifndef LDR_DELAY
#define LDR_DELAY                       0       // Delay between samples in micros
#endif

#ifndef LDR_TYPE
#define LDR_TYPE                        LDR_GL5528
#endif

#ifndef LDR_ON_GROUND
#define LDR_ON_GROUND                   true
#endif

#ifndef LDR_RESISTOR
#define LDR_RESISTOR                    10000   // Resistance
#endif

#ifndef LDR_MULTIPLICATION
#define LDR_MULTIPLICATION              32017200
#endif

#ifndef LDR_POWER
#define LDR_POWER                       1.5832
#endif

//------------------------------------------------------------------------------
// MHZ19 CO2 sensor
// Enable support by passing MHZ19_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef MHZ19_SUPPORT
#define MHZ19_SUPPORT                   0
#endif

#ifndef MHZ19_RX_PIN
#define MHZ19_RX_PIN                    13
#endif

#ifndef MHZ19_TX_PIN
#define MHZ19_TX_PIN                    15
#endif

//------------------------------------------------------------------------------
// MICS-2710 (and MICS-4514) NO2 sensor
// Enable support by passing MICS2710_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef MICS2710_SUPPORT
#define MICS2710_SUPPORT                0
#endif

#ifndef MICS2710_NOX_PIN
#define MICS2710_NOX_PIN                0
#endif

#ifndef MICS2710_PRE_PIN
#define MICS2710_PRE_PIN                4
#endif

#define MICS2710_PREHEAT_TIME           10000   // 10s preheat for NOX read
#define MICS2710_RL                     820     // RL, load resistor
#define MICS2710_R0                     2200    // R0 calibration value for NO2 sensor,
                                                // Typical value as per datasheet

//------------------------------------------------------------------------------
// MICS-5525 (and MICS-4514) CO sensor
// Enable support by passing MICS5525_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef MICS5525_SUPPORT
#define MICS5525_SUPPORT                0
#endif

#ifndef MICS5525_RED_PIN
#define MICS5525_RED_PIN                0
#endif

#define MICS5525_RL                     820     // RL, load resistor
#define MICS5525_R0                     750000  // R0 calibration value for NO2 sensor,
                                                // Typical value as per datasheet

//------------------------------------------------------------------------------
// NTC sensor
// Enable support by passing NTC_SUPPORT=1 build flag
//--------------------------------------------------------------------------------

#ifndef NTC_SUPPORT
#define NTC_SUPPORT                     0
#endif

#ifndef NTC_SAMPLES
#define NTC_SAMPLES                     10      // Number of samples
#endif

#ifndef NTC_DELAY
#define NTC_DELAY                       0       // Delay between samples in micros
#endif

#ifndef NTC_R_UP
#define NTC_R_UP                        0       // Resistor upstream, set to 0 if none
#endif

#ifndef NTC_R_DOWN
#define NTC_R_DOWN                      10000   // Resistor downstream, set to 0 if none
#endif

#ifndef NTC_T0
#define NTC_T0                          298.15  // 25 Celsius
#endif

#ifndef NTC_R0
#define NTC_R0                          10000   // Resistance at T0
#endif

#ifndef NTC_BETA
#define NTC_BETA                        3977    // Beta coeficient
#endif

//------------------------------------------------------------------------------
// Particle Monitor based on Plantower PMS
// Enable support by passing PMSX003_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef PMSX003_SUPPORT
#define PMSX003_SUPPORT                 0
#endif

#ifndef PMS_TYPE
#define PMS_TYPE                        PMS_TYPE_X003
#endif

// You can enable smart sleep (read 6-times then sleep on 24-reading-cycles) to extend PMS sensor's life.
// Otherwise the default lifetime of PMS sensor is about 8000-hours/1-years.
// The PMS's fan will stop working on sleeping cycle, and will wake up on reading cycle.
#ifndef PMS_SMART_SLEEP
#define PMS_SMART_SLEEP                 0
#endif

#ifndef PMS_USE_SOFT
#define PMS_USE_SOFT                    0       // If PMS_USE_SOFT == 1, DEBUG_SERIAL_SUPPORT must be 0
#endif

#ifndef PMS_RX_PIN
#define PMS_RX_PIN                      13      // Software serial RX GPIO (if PMS_USE_SOFT == 1)
#endif

#ifndef PMS_TX_PIN
#define PMS_TX_PIN                      15      // Software serial TX GPIO (if PMS_USE_SOFT == 1)
#endif

#ifndef PMS_HW_PORT
#define PMS_HW_PORT                     Serial  // Hardware serial port (if PMS_USE_SOFT == 0)
#endif

//------------------------------------------------------------------------------
// Pulse Meter Energy monitor
// Enable support by passing PULSEMETER_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef PULSEMETER_SUPPORT
#define PULSEMETER_SUPPORT              0
#endif
#ifndef PULSEMETER_PIN
#define PULSEMETER_PIN                  5
#endif

#ifndef PULSEMETER_ENERGY_RATIO
#define PULSEMETER_ENERGY_RATIO         4000        // In pulses/kWh
#endif

#ifndef PULSEMETER_INTERRUPT_ON
#define PULSEMETER_INTERRUPT_ON         FALLING
#endif

#ifndef PULSEMETER_DEBOUNCE
#define PULSEMETER_DEBOUNCE             50         // Do not register pulses within less than 50 millis
#endif

//------------------------------------------------------------------------------
// PZEM004T based power monitor
// Enable support by passing PZEM004T_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef PZEM004T_SUPPORT
#define PZEM004T_SUPPORT                0
#endif

#ifndef PZEM004T_USE_SOFT
#define PZEM004T_USE_SOFT               0       // Software serial is not working atm, use hardware serial
#endif

#ifndef PZEM004T_RX_PIN
#define PZEM004T_RX_PIN                 13      // Software serial RX GPIO (if PZEM004T_USE_SOFT == 1)
#endif

#ifndef PZEM004T_TX_PIN
#define PZEM004T_TX_PIN                 15      // Software serial TX GPIO (if PZEM004T_USE_SOFT == 1)
#endif

#ifndef PZEM004T_HW_PORT
#define PZEM004T_HW_PORT                Serial  // Hardware serial port (if PZEM004T_USE_SOFT == 0)
#endif

#ifndef PZEM004T_ADDRESSES
#define PZEM004T_ADDRESSES              "192.168.1.1"  // Device(s) address(es), separated by space, "192.168.1.1 192.168.1.2 192.168.1.3"
#endif

#ifndef PZEM004T_READ_INTERVAL
#define PZEM004T_READ_INTERVAL          1500    // Read interval between same device
#endif

#ifndef PZEM004T_MAX_DEVICES
#define PZEM004T_MAX_DEVICES            3
#endif

//------------------------------------------------------------------------------
// SDS011 particulates sensor
// Enable support by passing SDS011_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef SDS011_SUPPORT
#define SDS011_SUPPORT                   0
#endif

#ifndef SDS011_RX_PIN
#define SDS011_RX_PIN                    14
#endif

#ifndef SDS011_TX_PIN
#define SDS011_TX_PIN                    12
#endif

//------------------------------------------------------------------------------
// SenseAir CO2 sensor
// Enable support by passing SENSEAIR_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef SENSEAIR_SUPPORT
#define SENSEAIR_SUPPORT                0
#endif

#ifndef SENSEAIR_RX_PIN
#define SENSEAIR_RX_PIN                 0
#endif

#ifndef SENSEAIR_TX_PIN
#define SENSEAIR_TX_PIN                 2
#endif

//------------------------------------------------------------------------------
// SHT3X I2C (Wemos) temperature & humidity sensor
// Enable support by passing SHT3X_I2C_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef SHT3X_I2C_SUPPORT
#define SHT3X_I2C_SUPPORT               0
#endif

#ifndef SHT3X_I2C_ADDRESS
#define SHT3X_I2C_ADDRESS               0x00    // 0x00 means auto
#endif

//------------------------------------------------------------------------------
// SI7021 temperature & humidity sensor
// Enable support by passing SI7021_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef SI7021_SUPPORT
#define SI7021_SUPPORT                  0
#endif

#ifndef SI7021_ADDRESS
#define SI7021_ADDRESS                  0x00    // 0x00 means auto
#endif

//------------------------------------------------------------------------------
// Sonar
// Enable support by passing SONAR_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef SONAR_SUPPORT
#define SONAR_SUPPORT                  0
#endif

#ifndef SONAR_TRIGGER
#define SONAR_TRIGGER                  12                            // GPIO for the trigger pin (output)
#endif

#ifndef SONAR_ECHO
#define SONAR_ECHO                     14                            // GPIO for the echo pin (input)
#endif

#ifndef SONAR_MAX_DISTANCE
#define SONAR_MAX_DISTANCE             MAX_SENSOR_DISTANCE           // Max sensor distance in cm
#endif

#ifndef SONAR_ITERATIONS
#define SONAR_ITERATIONS               5                             // Number of iterations to ping for
#endif                                                               // error correction.

//------------------------------------------------------------------------------
// T6613 CO2 sensor
// Enable support by passing T6613_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef T6613_SUPPORT
#define T6613_SUPPORT                   0
#endif

#ifndef T6613_RX_PIN
#define T6613_RX_PIN                    4
#endif

#ifndef T6613_TX_PIN
#define T6613_TX_PIN                    5
#endif

//------------------------------------------------------------------------------
// TMP3X analog temperature sensor
// Enable support by passing TMP3X_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef TMP3X_SUPPORT
#define TMP3X_SUPPORT                   0
#endif

#ifndef TMP3X_TYPE
#define TMP3X_TYPE                      TMP3X_TMP35
#endif

//------------------------------------------------------------------------------
// V9261F based power sensor
// Enable support by passing SI7021_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef V9261F_SUPPORT
#define V9261F_SUPPORT                  0
#endif

#ifndef V9261F_PIN
#define V9261F_PIN                      2       // TX pin from the V9261F
#endif

#ifndef V9261F_PIN_INVERSE
#define V9261F_PIN_INVERSE              1       // Signal is inverted
#endif

#define V9261F_SYNC_INTERVAL            600     // Sync signal length (ms)
#define V9261F_BAUDRATE                 4800    // UART baudrate

// Default ratios
#define V9261F_CURRENT_FACTOR           79371434.0
#define V9261F_VOLTAGE_FACTOR           4160651.0
#define V9261F_POWER_FACTOR             153699.0
#define V9261F_RPOWER_FACTOR            V9261F_CURRENT_FACTOR

//------------------------------------------------------------------------------
// VEML6075 based power sensor
// Enable support by passing VEML6075_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef VEML6075_SUPPORT
#define VEML6075_SUPPORT                  0
#endif

#ifndef VEML6075_INTEGRATION_TIME
#define VEML6075_INTEGRATION_TIME         VEML6075::IT_100MS        // The time, in milliseconds, allocated for a single
#endif                                                              // measurement. A longer timing budget allows for more
                                                                    // accurate results at the cost of power.

#ifndef VEML6075_DYNAMIC_MODE
#define VEML6075_DYNAMIC_MODE             VEML6075::DYNAMIC_NORMAL  // The dynamic mode can either be normal or high. In high
#endif                                                              // dynamic mode, the resolution increases by about two
                                                                    // times.
//------------------------------------------------------------------------------
// VL53L1X
// Enable support by passing VL53L1X_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef VL53L1X_SUPPORT
#define VL53L1X_SUPPORT                              0
#endif

#ifndef VL53L1X_I2C_ADDRESS
#define VL53L1X_I2C_ADDRESS                          0x00          // 0x00 means auto
#endif

#ifndef VL53L1X_DISTANCE_MODE
#define VL53L1X_DISTANCE_MODE                        VL53L1X::Long // The distance mode of the sensor. Can be one of
#endif                                                             // `VL53L1X::Short`, `VL53L1X::Medium`, or `VL53L1X::Long.
                                                                   // Shorter distance modes are less affected by ambient light
                                                                   // but have lower maximum ranges, especially in the dark.

#ifndef VL53L1X_MEASUREMENT_TIMING_BUDGET
#define VL53L1X_MEASUREMENT_TIMING_BUDGET            140000        // The time, in microseconds, allocated for a single
                                                                   // measurement. A longer timing budget allows for more
                                                                   // accurate at the cost of power. The minimum budget is
                                                                   // 20 ms (20000 us) in short distance mode and 33 ms for
                                                                   // medium and long distance modes.
#endif

#ifndef VL53L1X_INTER_MEASUREMENT_PERIOD
#define VL53L1X_INTER_MEASUREMENT_PERIOD             50            // Period, in milliseconds, determining how
#endif                                                             // often the sensor takes a measurement.

//------------------------------------------------------------------------------
// MAX6675
// Enable support by passing MAX6675_SUPPORT=1 build flag
//------------------------------------------------------------------------------
#ifndef MAX6675_CS_PIN
#define MAX6675_CS_PIN                               13
#endif

#ifndef MAX6675_SO_PIN
#define MAX6675_SO_PIN                               12
#endif

#ifndef MAX6675_SCK_PIN
#define MAX6675_SCK_PIN                              14
#endif

//------------------------------------------------------------------------------
// EZOPH pH meter
// Enable support by passing EZOPH_SUPPORT=1 build flag
//------------------------------------------------------------------------------

#ifndef EZOPH_SUPPORT
#define EZOPH_SUPPORT                0
#endif

#ifndef EZOPH_RX_PIN
#define EZOPH_RX_PIN                 13      // Software serial RX GPIO
#endif

#ifndef EZOPH_TX_PIN
#define EZOPH_TX_PIN                 15      // Software serial TX GPIO
#endif

#ifndef EZOPH_SYNC_INTERVAL
#define EZOPH_SYNC_INTERVAL          1000    // Amount of time (in ms) sync new readings.
#endif

// =============================================================================
// Sensor helpers configuration - can't move to dependencies.h
// =============================================================================

#ifndef SENSOR_SUPPORT
#define SENSOR_SUPPORT ( \
    AM2320_SUPPORT || \
    ANALOG_SUPPORT || \
    BH1750_SUPPORT || \
    BMP180_SUPPORT || \
    BMX280_SUPPORT || \
    CSE7766_SUPPORT || \
    DALLAS_SUPPORT || \
    DHT_SUPPORT || \
    DIGITAL_SUPPORT || \
    ECH1560_SUPPORT || \
    EMON_ADC121_SUPPORT || \
    EMON_ADS1X15_SUPPORT || \
    EMON_ANALOG_SUPPORT || \
    EVENTS_SUPPORT || \
    EZOPH_SUPPORT || \
    GEIGER_SUPPORT || \
    GUVAS12SD_SUPPORT || \
    HLW8012_SUPPORT || \
    LDR_SUPPORT || \
    MAX6675_SUPPORT || \
    MICS2710_SUPPORT || \
    MICS5525_SUPPORT || \
    MHZ19_SUPPORT || \
    NTC_SUPPORT || \
    SDS011_SUPPORT || \
    SENSEAIR_SUPPORT || \
    PMSX003_SUPPORT || \
    PZEM004T_SUPPORT || \
    PULSEMETER_SUPPORT || \
    SHT3X_I2C_SUPPORT || \
    SI7021_SUPPORT || \
    SONAR_SUPPORT || \
    T6613_SUPPORT || \
    THERMOSTAT_SUPPORT || \
    TMP3X_SUPPORT || \
    V9261F_SUPPORT || \
    VEML6075_SUPPORT || \
    VL53L1X_SUPPORT || \
    ADE7953_SUPPORT \
)
#endif

// -----------------------------------------------------------------------------
// ADC
// -----------------------------------------------------------------------------

// Default ADC mode is to monitor internal power supply
#ifndef ADC_MODE_VALUE
#define ADC_MODE_VALUE                  ADC_VCC
#endif

// -----------------------------------------------------------------------------
// I2C
// -----------------------------------------------------------------------------

#ifndef I2C_SUPPORT
#define I2C_SUPPORT                     0       // I2C enabled (1.98Kb)
#endif

#define I2C_USE_BRZO                    0       // Use brzo_i2c library or standard Wire

#ifndef I2C_SDA_PIN
#define I2C_SDA_PIN                     SDA     // SDA GPIO (Sonoff => 4)
#endif

#ifndef I2C_SCL_PIN
#define I2C_SCL_PIN                     SCL     // SCL GPIO (Sonoff => 14)
#endif

#define I2C_CLOCK_STRETCH_TIME          200     // BRZO clock stretch time
#define I2C_SCL_FREQUENCY               1000    // BRZO SCL frequency
#define I2C_CLEAR_BUS                   0       // Clear I2C bus on boot
#define I2C_PERFORM_SCAN                1       // Perform a bus scan on boot

// -----------------------------------------------------------------------------
// ADE7953 Shelly Sensor
// Enable support by passing ADE7953_SUPPORT=1 build flag
// -----------------------------------------------------------------------------

#ifndef ADE7953_SUPPORT
#define ADE7953_SUPPORT                  0
#endif

#ifndef ADE7953_ADDRESS
#define ADE7953_ADDRESS                  0x38
#endif

//--------------------------------------------------------------------------------
// Class loading
//--------------------------------------------------------------------------------

#if SENSOR_SUPPORT

#if AM2320_SUPPORT
    #include "../sensors/AM2320Sensor.h"
#endif

#if ANALOG_SUPPORT
    #include "../sensors/AnalogSensor.h"
#endif

#if BH1750_SUPPORT
    #include "../sensors/BH1750Sensor.h"
#endif

#if BMP180_SUPPORT
    #include "../sensors/BMP180Sensor.h"
#endif

#if BMX280_SUPPORT
    #include "../sensors/BMX280Sensor.h"
#endif

#if CSE7766_SUPPORT
    #include "../sensors/CSE7766Sensor.h"
#endif

#if DALLAS_SUPPORT
    #include "../sensors/DallasSensor.h"
#endif

#if DHT_SUPPORT
    #include "../sensors/DHTSensor.h"
#endif

#if DIGITAL_SUPPORT
    #include "../sensors/DigitalSensor.h"
#endif

#if ECH1560_SUPPORT
    #include "../sensors/ECH1560Sensor.h"
#endif

#if EMON_ADC121_SUPPORT
    #include "../sensors/EmonADC121Sensor.h"
#endif

#if EMON_ADS1X15_SUPPORT
    #include "../sensors/EmonADS1X15Sensor.h"
#endif

#if EMON_ANALOG_SUPPORT
    #include "../sensors/EmonAnalogSensor.h"
#endif

#if EVENTS_SUPPORT
    #include "../sensors/EventSensor.h"
#endif

#if EZOPH_SUPPORT
    #include "../sensors/EZOPHSensor.h"
#endif

#if GEIGER_SUPPORT
    #include "../sensors/GeigerSensor.h"
#endif

#if GUVAS12SD_SUPPORT
    #include "../sensors/GUVAS12SDSensor.h"
#endif

#if HLW8012_SUPPORT
    #include "../sensors/HLW8012Sensor.h"
#endif

#if LDR_SUPPORT
    #include "../sensors/LDRSensor.h"
#endif

#if MAX6675_SUPPORT
    #include "../sensors/MAX6675Sensor.h"
#endif 

#if MICS2710_SUPPORT
    #include "../sensors/MICS2710Sensor.h"
#endif

#if MICS5525_SUPPORT
    #include "../sensors/MICS5525Sensor.h"
#endif

#if MHZ19_SUPPORT
    #include "../sensors/MHZ19Sensor.h"
#endif

#if NTC_SUPPORT
    #include "../sensors/NTCSensor.h"
#endif

#if SDS011_SUPPORT
    #include "../sensors/SDS011Sensor.h"
#endif

#if SENSEAIR_SUPPORT
    #include "../sensors/SenseAirSensor.h"
#endif

#if PMSX003_SUPPORT
    #include "../sensors/PMSX003Sensor.h"
#endif

#if PULSEMETER_SUPPORT
    #include "../sensors/PulseMeterSensor.h"
#endif

#if PZEM004T_SUPPORT
    #include "../sensors/PZEM004TSensor.h"
#endif

#if SHT3X_I2C_SUPPORT
    #include "../sensors/SHT3XI2CSensor.h"
#endif

#if SI7021_SUPPORT
    #include "../sensors/SI7021Sensor.h"
#endif

#if SONAR_SUPPORT
    #include "../sensors/SonarSensor.h"
#endif

#if T6613_SUPPORT
    #include "../sensors/T6613Sensor.h"
#endif

#if TMP3X_SUPPORT
    #include "../sensors/TMP3XSensor.h"
#endif

#if V9261F_SUPPORT
    #include "../sensors/V9261FSensor.h"
#endif

#if VEML6075_SUPPORT
    #include "../sensors/VEML6075Sensor.h"
#endif

#if VL53L1X_SUPPORT
    #include "../sensors/VL53L1XSensor.h"
#endif

#if ADE7953_SUPPORT
    #include "../sensors/ADE7953Sensor.h"
#endif

#endif // SENSOR_SUPPORT

`

davebuk commented 3 years ago

From those config files above, I would say it looks like you have enabled the following functions.

#define DALLAS_SUPPORT         1
#define DHT_SUPPORT            1
#define DIGITAL_SUPPORT        1
#define EVENTS_SUPPORT         1

I think the problem is the sensors.h has #define DIGITAL1_PIN 14 then later #define EVENTS1_PIN 14 which I believe overwrites the DIGITAL GPIO setting.

Try either editing sensor.h for the GPIOs you are using or look in the wiki about using custom.h file to make your own definitions.

davebuk commented 3 years ago

I would tend to use just the EVENT function and not the DIGITAL one, so you get an immediate response rather than having to wait for the sensor update routine to run.

mcspr commented 3 years ago

I would tend to use just the EVENT function and not the DIGITAL one, so you get an immediate response rather than having to wait for the sensor update routine to run.

Note of the 1.15.0 function of ${magnitude}MinDelta${num} and ${magnitude}MaxDelta${num} settings. e.g. setting digitalMaxDelta0 to 1 will cause MQTT to report every reading interval, when the value changes and without waiting for the specified report time. Min delta works similarly, but the other way around - it will cause the report only when value actually changes for the specified amount. And in case of digital, it is always 1 edit: but, I think I mistaken min with max... I wonder if that naming should be changed before actually commiting the 1.15.0 tag

EVENT was also changed since 1.14.1, since I removed the event trigger function in favour of the min & max delta triggers above. Right now it is expected to be used to count things e.g. water, wind, optical sensors that trigger the pin many times a second

bluexp1 commented 2 years ago

From those config files above, I would say it looks like you have enabled the following functions.

#define DALLAS_SUPPORT         1
#define DHT_SUPPORT            1
#define DIGITAL_SUPPORT        1
#define EVENTS_SUPPORT         1

I think the problem is the sensors.h has #define DIGITAL1_PIN 14 then later #define EVENTS1_PIN 14 which I believe overwrites the DIGITAL GPIO setting.

Try either editing sensor.h for the GPIOs you are using or look in the wiki about using custom.h file to make your own definitions.

I tried with "#define EVENTS_SUPPORT 0" and even changed EVENTS1_PIN but still Digital pin state is not shown on web interface!

mcspr commented 2 years ago

@bluexp1 if you go to the DEBUG panel, and type magnitudes then click send / press enter, do you see digital sensor(s) in the output?

bluexp1 commented 2 years ago

@mcspr I received nothing in debug panel, but in serial terminal I got a "+OK". After reset I see this in terminal log: [000237] [MAIN] Support: ALEXA API BROKER BUTTON DEBUG_SERIAL DEBUG_TELNET DEBUG_WEB DOMOTICZ HOMEASSISTANT LED MDNS_SERVER MQTT NTP SCHEDULER SENSOR TELNET TERMINAL THINGSPEAK WEB. Shouldn't "DIGITAL" be there?

mcspr commented 2 years ago

@bluexp1 should be [MAIN] Sensors: DIGITAL at the very least, check the config flags in the .h

bluexp1 commented 2 years ago

@mcspr it is really strange, cause I already have "#define DIGITAL_SUPPORT 1" in both arduino.h and hardware.h!!!

mcspr commented 2 years ago

@bluexp1 my only other guess is to use #define DIGITAL1_PIN 4, #define DIGITAL2_PIN 5, etc. in the arduino.h b/c you never end up reaching statements wrapped with #ifndef DIGITAL1_PIN b/c they are defined by previously loaded headers

bluexp1 commented 2 years ago

@mcspr Thanks, I added it to hardware.h and it worked!