From 6dc77df49828aa4e2b7fb5411aa9bd05fe91e75c Mon Sep 17 00:00:00 2001 From: jptrsn Date: Tue, 2 Oct 2018 19:17:40 -0400 Subject: [PATCH] Fix to watchdog timeout --- ESP32-mqtt-room.ino | 23 ++++++++++++++++------- README.md | 23 +++++++++++++++++++++-- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/ESP32-mqtt-room.ino b/ESP32-mqtt-room.ino index 3a7ae71..8be2b39 100644 --- a/ESP32-mqtt-room.ino +++ b/ESP32-mqtt-room.ino @@ -152,7 +152,7 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { float distance = calculateDistance(rssi, oBeacon.getSignalPower()); Serial.print("RSSI: "); Serial.print(rssi); - Serial.print("\txPower: "); + Serial.print("\ttxPower: "); Serial.print(oBeacon.getSignalPower()); Serial.print("\tDistance: "); Serial.println(distance); @@ -207,8 +207,12 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { String publishTopic = String(channel) + "/" + room; if (client.publish((char *)publishTopic.c_str(), JSONmessageBuffer) == true) { + + vTaskDelay(10); // watchdog timer + // Serial.print("Success sending message to topic: "); Serial.println(publishTopic); // Serial.print("Message: "); Serial.println(JSONmessageBuffer); + } else { Serial.print("Error sending message: "); Serial.println(publishTopic); Serial.print("Message: "); Serial.println(JSONmessageBuffer); @@ -218,15 +222,19 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { void setup() { Serial.begin(115200); - + WiFi.begin(ssid, password); - + WiFi.setHostname(hostname); + + Serial.print("Connecting to WiFi.."); while (WiFi.status() != WL_CONNECTED) { delay(500); - Serial.println("Connecting to WiFi.."); + Serial.print("."); } - Serial.println("Connected to the WiFi network"); + Serial.println(); + Serial.print("Connected to the WiFi network as "); + Serial.println(hostname); client.setServer(mqttServer, mqttPort); reconnect(); @@ -238,6 +246,7 @@ void setup() { Serial.println("Error sending message"); } + BLEDevice::init(""); pBLEScan = BLEDevice::getScan(); //create new scan pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); @@ -251,14 +260,14 @@ void loop() { reconnect(); } client.loop(); - + if (millis() - last > (waitTime * 1000)) { Serial.println("Scanning..."); BLEScanResults foundDevices = pBLEScan->start(scanTime); Serial.printf("\nScan done! Devices found: %d\n",foundDevices.getCount()); last = millis(); } - delay(5); + } char *uint64_to_string(uint64_t input) diff --git a/README.md b/README.md index 77d484d..e2384b9 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,28 @@ # ESP32-mqtt-room An ESP32 based presence detection node for use with the Home Assistant mqtt_room component for localized device presence detection. -This depends heavily on the hard work done by [pcbreflux](https://github.com/pcbreflux) and [nkolban](https://github.com/nkolban) both on GitHub and on their YouTube Channels. +This depends heavily on the hard work done by [pcbreflux](https://github.com/pcbreflux) and [nkolban](https://github.com/nkolban) both on GitHub and on their YouTube Channels. Specifically, it is a modified version of pcbreflux's [ESP32_BLE_beaconscan](https://github.com/pcbreflux/espressif/tree/master/esp32/arduino/sketchbook/ESP32_BLE_beaconscan). + +## Getting Started +1. You can get started by cloning this repository to your local machine using git. Alternatively, you can [download the zip](https://github.com/jptrsn/ESP32-mqtt-room/archive/master.zip). +2. Make a copy of the `Settings.h` file, and rename it `Settings_local.h`. Fill in the required information in your local settings file (the local file is ignored by GitHub, so you won't upload your sensitive information). +3. Set the board variant to ESP32 in the Arduino IDE. -Specifically, it is a modified version of pcbreflux's [ESP32_BLE_beaconscan](https://github.com/pcbreflux/espressif/tree/master/esp32/arduino/sketchbook/ESP32_BLE_beaconscan) ## Configuration Settings are defined in `Settings_local.h` which is not included in the repo by default. You can make a copy of `Settings.h` and rename it `Settings_local.h` in the same folder. + +#### Development Tasks +- [x] Implement basic BLE packet discovery +- [x] Implement iBeacon data packet parsing +- [ ] Setup instructions in README.md +- [ ] Match configuration options to Room Assistant +- [ ] Implement Mi Flora data parsing and reporting +- [ ] Whitelist functionality +- [ ] Blacklist functionality +- [ ] Maximum distance limit +- [ ] Scan interval Settings +- [ ] Configuration via Web UI +- [ ] Wifi Manager for managing access point credentials +- [ ] Implement Over-The-Air (OTA) updates +- [ ] Build and upload via [PlatformIO](platformio.org)