Added reconnect logic when attempting to report while disconnected from MQTT.

This commit is contained in:
jptrsn 2019-07-10 08:56:25 -04:00
parent 573a815adf
commit 1ac24e3eda
3 changed files with 96 additions and 1 deletions

View File

@ -334,11 +334,12 @@ bool reportDevice(BLEAdvertisedDevice advertisedDevice) {
}
} else if (mqttClient.connected() && distance >= maxDistance) {
// Serial.printf("%f exceeded distance threshold\n", distance);
Serial.printf("%s exceeded distance threshold %f\n\r", mac_address.c_str(), distance);
} else {
Serial.println("MQTT disconnected.");
connectToMqtt();
}
return false;

92
docs/images/github.svg Normal file
View File

@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="43.438667"
height="42.366489"
viewBox="0 0 11.493147 11.209467"
version="1.1"
id="svg8"
inkscape:version="0.92.2 (5c3e80d, 2017-08-06)"
sodipodi:docname="github.svg">
<defs
id="defs2">
<clipPath
id="clipPath4522"
clipPathUnits="userSpaceOnUse">
<path
inkscape:connector-curvature="0"
id="path4520"
d="M 0,551.986 H 530.973 V 0 H 0 Z" />
</clipPath>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="1.979899"
inkscape:cx="91.985265"
inkscape:cy="83.925196"
inkscape:document-units="mm"
inkscape:current-layer="g4518"
showgrid="false"
fit-margin-top="0"
fit-margin-left="0"
fit-margin-right="0"
fit-margin-bottom="0"
units="px"
inkscape:window-width="1075"
inkscape:window-height="844"
inkscape:window-x="3522"
inkscape:window-y="1188"
inkscape:window-maximized="0" />
<metadata
id="metadata5">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-194.17103,-278.56633)">
<g
transform="matrix(0.35277777,0,0,-0.35277777,75.675598,316.02397)"
inkscape:label="GitHub-Mark"
id="g4512">
<g
id="g4516">
<g
clip-path="url(#clipPath4522)"
id="g4518">
<g
transform="translate(352.18058,106.17914)"
id="g4524">
<path
inkscape:connector-curvature="0"
id="path4526"
style="fill:#1b1817;fill-opacity:1;fill-rule:evenodd;stroke:none"
d="m 0,0 c -8.995,0 -16.288,-7.293 -16.288,-16.29 0,-7.197 4.667,-13.302 11.14,-15.457 0.815,-0.149 1.112,0.354 1.112,0.786 0,0.386 -0.014,1.411 -0.022,2.77 -4.531,-0.984 -5.487,2.184 -5.487,2.184 -0.741,1.881 -1.809,2.382 -1.809,2.382 -1.479,1.011 0.112,0.991 0.112,0.991 1.635,-0.116 2.495,-1.679 2.495,-1.679 1.453,-2.489 3.813,-1.77 4.741,-1.354 0.148,1.053 0.568,1.771 1.034,2.178 -3.617,0.411 -7.42,1.809 -7.42,8.051 0,1.778 0.635,3.232 1.677,4.371 -0.168,0.412 -0.727,2.068 0.159,4.311 0,0 1.368,0.438 4.48,-1.67 1.299,0.361 2.693,0.542 4.078,0.548 1.383,-0.006 2.777,-0.187 4.078,-0.548 3.11,2.108 4.475,1.67 4.475,1.67 0.889,-2.243 0.33,-3.899 0.162,-4.311 1.044,-1.139 1.675,-2.593 1.675,-4.371 0,-6.258 -3.809,-7.635 -7.438,-8.038 0.585,-0.503 1.106,-1.497 1.106,-3.017 0,-2.177 -0.02,-3.934 -0.02,-4.468 0,-0.436 0.293,-0.943 1.12,-0.784 6.468,2.159 11.131,8.26 11.131,15.455 C 16.291,-7.293 8.997,0 0,0" />
</g>
</g>
</g>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -1,8 +1,10 @@
![Cover Image](./images/cover.jpg)
# ESP32-mqtt-room
<a href="https://github.com/jptrsn/ESP32-mqtt-room" title="View the project on GitHub"><img src="./images/github.svg" style="float:right;margin:16px"></a>
An ESP32 based presence detection node for use with the [Home Assistant](https://www.home-assistant.io/) [`mqtt_room` component](https://www.home-assistant.io/components/sensor.mqtt_room/) for localized device presence detection.
## Requirements
You're going to need the following items:
* An [ESP32 development board](https://www.amazon.ca/gp/product/B07F1GWJ1N/ref=as_li_tl?ie=UTF8&camp=15121&creative=330641&creativeASIN=B07F1GWJ1N&linkCode=as2&tag=ptrsnja-20&linkId=7ccc8364c8a8961ac9053e03efa91268)