shred / kaminari

AS3935 and ESP8266 based Franklin Lightning Detector
GNU General Public License v3.0
42 stars 10 forks source link

add MQTT support? #5

Closed DarKOrange75 closed 3 years ago

DarKOrange75 commented 3 years ago

Hi, thank you for your nice work! I would like to integrate your sensor into my Home Assistant setup. Could you please add MQTT support when you have time? This would be awesome. Thank you!

shred commented 3 years ago

Yes! This is actually on top of my To-Do list for this project. I will keep this issue open as a reminder and for notifications.

shred commented 3 years ago

MQTT support is added in commit 595fe3a8. It is not thoroughly tested, so I'd appreciate your feedback.

DarKOrange75 commented 3 years ago

Awesome, I'll test it as soon as I can!

DarKOrange75 commented 3 years ago

The serial monitor says that it is connected to MQTT server but nothing is published: 10:43:13.377 -> Calibrated antenna frequency: 499072 Hz 10:43:13.516 -> MDNS responder started 10:43:13.516 -> Server is listening on port 80 10:43:16.535 -> Connected to DKON2 10:43:16.535 -> IP address: 192.168.1.19 10:43:16.535 -> MAC: EC:FA:BC:6E:18:BA 10:43:16.535 -> Successfully connected to MQTT server

The status shows that the sensor was triggered though:

{"lightnings":

[{"age":186,"energy":165851,"distance":6}],"distance":6,"energy":0,"noiseFloorLevel":78,"disturbersPerMinute":7,"watchdogThreshold":0}

DarKOrange75 commented 3 years ago

is this normal?

if (client.connect("kaminari", MY_MQTT_USER, MY_MQTT_PASSWORD))

shred commented 3 years ago

Yes... You are supposed to set the correct MQTT credentials in your myWiFi.h as MY_MQTT_USER and MY_MQTT_PASSWORD. If you don't need to authenticate, set both to NULL.

I was able to receive lightning events in Mosquitto, so it should work in general. Errors while publishing were not logged, so if there was an error, it would go unnoticed. I've added error logging in commit be4ef1d6. The error codes are documented here. Can you check if you get an error instead of a lightning event message?

DarKOrange75 commented 3 years ago

I meant is "kaminari" normal or is it a leftover of your tests in the code ?

shred commented 3 years ago

It's the client ID. But you are right, it should be configurable as well.

DarKOrange75 commented 3 years ago

OK that's weird, it worked only once, I got a notification in mosquito, deleted it and now nothing is published anymore...

DarKOrange75 commented 3 years ago

After some tests, nothing is wrong with the MQTT connection, it looks like this condition is preventing the publishing of the lightning alert:

if (!detector.getLastLightningDetection(0, ledLightning))

shred commented 3 years ago

Strange, I could get lightning events that way. I will have a look at it in the next days.

shred commented 3 years ago

I'm sorry for the delay. I had a hardware issue with my sensor that is hopefully fixed now.

DarKOrange75 commented 3 years ago

No problem Richard

shred commented 3 years ago

Hopefully @gubiq's patch has fixed the MQTT status problem. If not, feel free to reopen this issue. But I will also keep on looking into this issue while I try to get my hardware fixed. (It still does not detect any lightnings any more, not even false positives.)