diff --git a/README.md b/README.md index 150b45a..64566ab 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,11 @@ Here's some code and schematic to connect your mightyohm.com geiger counter to t ![Schematic](https://raw.githubusercontent.com/schinken/esp8266-geigercounter/master/images/schematic.png "How to connect") +*You can optionally connect PULSE to D2 of the Wemos D1 and enable PIN_PULSE to receive a mqtt event each count!* + ## images -

+

diff --git a/esp8266-geigercounter.ino b/esp8266-geigercounter.ino index 79f7d91..b8ca47e 100644 --- a/esp8266-geigercounter.ino +++ b/esp8266-geigercounter.ino @@ -45,6 +45,7 @@ void setup() { mqttClient.setClient(wifiClient); mqttClient.setServer(MQTT_HOST, 1883); + connectMqtt(); #ifdef OTA_PASSWORD ArduinoOTA.setHostname(hostname); @@ -52,8 +53,18 @@ void setup() { ArduinoOTA.begin(); #endif + #ifdef PIN_PULSE + pinMode(PIN_PULSE, INPUT); + attachInterrupt(PIN_PULSE, onPulse, RISING); + #endif } +#ifdef PIN_PULSE +ICACHE_RAM_ATTR void onPulse() { + mqttClient.publish(MQTT_TOPIC_PULSE, "true"); +} +#endif + void publishValues() { char tmp[8]; diff --git a/images/schematic.png b/images/schematic.png index d333548..5306489 100644 Binary files a/images/schematic.png and b/images/schematic.png differ diff --git a/settings.h.example b/settings.h.example index fca35a6..8d6315c 100644 --- a/settings.h.example +++ b/settings.h.example @@ -8,6 +8,7 @@ #define PIN_UART_RX D1 // 4 #define PIN_UART_TX 13 // UNUSED +//#define PIN_PULSE D2 #define BAUD_GEIGERCOUNTER 9600 @@ -22,6 +23,7 @@ #define MQTT_TOPIC_CPM "sensor/geigercounter/cpm" #define MQTT_TOPIC_USV "sensor/geigercounter/uSv" #define MQTT_TOPIC_LAST_WILL "sensor/geigercounter/status" +#define MQTT_TOPIC_PULSE "sensor/geigercounter/pulse" // Only publishes values if changed since last publish #define MQTT_PUBLISH_INTERVAL_MS (10 * 1000) \ No newline at end of file