Add optional pulse mqtt event

This commit is contained in:
schinken 2022-03-16 17:07:18 +01:00
parent 6b361a813b
commit 170ebe13af
4 changed files with 16 additions and 1 deletions

View file

@ -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") ![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 ## images
<p float="left"> <p align="middle">
<img src="https://raw.githubusercontent.com/schinken/esp8266-geigercounter/master/images/img-1.jpg" width="32%"> <img src="https://raw.githubusercontent.com/schinken/esp8266-geigercounter/master/images/img-1.jpg" width="32%">
<img src="https://raw.githubusercontent.com/schinken/esp8266-geigercounter/master/images/img-2.jpg" width="32%"> <img src="https://raw.githubusercontent.com/schinken/esp8266-geigercounter/master/images/img-2.jpg" width="32%">
<img src="https://raw.githubusercontent.com/schinken/esp8266-geigercounter/master/images/img-3.jpg" width="32%"> <img src="https://raw.githubusercontent.com/schinken/esp8266-geigercounter/master/images/img-3.jpg" width="32%">

View file

@ -45,6 +45,7 @@ void setup() {
mqttClient.setClient(wifiClient); mqttClient.setClient(wifiClient);
mqttClient.setServer(MQTT_HOST, 1883); mqttClient.setServer(MQTT_HOST, 1883);
connectMqtt();
#ifdef OTA_PASSWORD #ifdef OTA_PASSWORD
ArduinoOTA.setHostname(hostname); ArduinoOTA.setHostname(hostname);
@ -52,8 +53,18 @@ void setup() {
ArduinoOTA.begin(); ArduinoOTA.begin();
#endif #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() { void publishValues() {
char tmp[8]; char tmp[8];

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 KiB

After

Width:  |  Height:  |  Size: 142 KiB

View file

@ -8,6 +8,7 @@
#define PIN_UART_RX D1 // 4 #define PIN_UART_RX D1 // 4
#define PIN_UART_TX 13 // UNUSED #define PIN_UART_TX 13 // UNUSED
//#define PIN_PULSE D2
#define BAUD_GEIGERCOUNTER 9600 #define BAUD_GEIGERCOUNTER 9600
@ -22,6 +23,7 @@
#define MQTT_TOPIC_CPM "sensor/geigercounter/cpm" #define MQTT_TOPIC_CPM "sensor/geigercounter/cpm"
#define MQTT_TOPIC_USV "sensor/geigercounter/uSv" #define MQTT_TOPIC_USV "sensor/geigercounter/uSv"
#define MQTT_TOPIC_LAST_WILL "sensor/geigercounter/status" #define MQTT_TOPIC_LAST_WILL "sensor/geigercounter/status"
#define MQTT_TOPIC_PULSE "sensor/geigercounter/pulse"
// Only publishes values if changed since last publish // Only publishes values if changed since last publish
#define MQTT_PUBLISH_INTERVAL_MS (10 * 1000) #define MQTT_PUBLISH_INTERVAL_MS (10 * 1000)