platformio functionality - moved libraries into folder

This commit is contained in:
jptrsn 2018-10-12 21:37:56 -04:00
parent 1c7425f211
commit 3c24cea706
13 changed files with 275 additions and 25 deletions

3
.gitignore vendored
View File

@ -1,4 +1,5 @@
Settings_local.h Settings_local.h
.pioenvs .pioenvs
.piolibdeps .piolibdeps
lib .clang_complete
.gcc-flags.json

12
.idea/ESP32-mqtt-room.iml Normal file
View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
<excludeFolder url="file://$MODULE_DIR$/temp" />
<excludeFolder url="file://$MODULE_DIR$/tmp" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/ESP32-mqtt-room.iml" filepath="$PROJECT_DIR$/.idea/ESP32-mqtt-room.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

177
.idea/workspace.xml Normal file
View File

@ -0,0 +1,177 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="e2c25526-97df-4285-945a-e164bb95d54f" name="Default" comment="">
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/ESP32-mqtt-room.ino" afterPath="$PROJECT_DIR$/ESP32-mqtt-room.ino" />
</list>
<ignored path="$PROJECT_DIR$/.tmp/" />
<ignored path="$PROJECT_DIR$/temp/" />
<ignored path="$PROJECT_DIR$/tmp/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
<option name="TRACKING_ENABLED" value="true" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="FileEditorManager">
<leaf>
<file leaf-file-name="ESP32-mqtt-room.ino" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/ESP32-mqtt-room.ino">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="493">
<caret line="248" column="12" lean-forward="false" selection-start-line="248" selection-start-column="12" selection-end-line="248" selection-end-column="12" />
<folding />
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/ESP32-mqtt-room.ino" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="ProjectFrameBounds">
<option name="x" value="2286" />
<option name="y" value="267" />
<option name="width" value="1849" />
<option name="height" value="1047" />
</component>
<component name="ProjectInspectionProfilesVisibleTreeState">
<entry key="Project Default">
<profile-state>
<expanded-state>
<State>
<id />
</State>
<State>
<id>General</id>
</State>
<State>
<id>XPath</id>
</State>
</expanded-state>
</profile-state>
</entry>
</component>
<component name="ProjectView">
<navigator currentView="ProjectPane" proportions="" version="1">
<flattenPackages />
<showMembers />
<showModules />
<showLibraryContents />
<hideEmptyPackages />
<abbreviatePackageNames />
<autoscrollToSource />
<autoscrollFromSource />
<sortByType />
<manualOrder />
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="ESP32-mqtt-room" type="b2602c69:ProjectViewProjectNode" />
<item name="ESP32-mqtt-room" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
<pane id="Scratches" />
<pane id="Scope" />
</panes>
</component>
<component name="PropertiesComponent">
<property name="settings.editor.selected.configurable" value="Errors" />
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
</component>
<component name="RunDashboard">
<option name="ruleStates">
<list>
<RuleState>
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
</RuleState>
<RuleState>
<option name="name" value="StatusDashboardGroupingRule" />
</RuleState>
</list>
</option>
</component>
<component name="ShelveChangesManager" show_recycled="false">
<option name="remove_strategy" value="false" />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="e2c25526-97df-4285-945a-e164bb95d54f" name="Default" comment="" />
<created>1538770075726</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1538770075726</updated>
<workItem from="1538770083638" duration="3000" />
<workItem from="1538770105033" duration="88000" />
</task>
<servers />
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="91000" />
</component>
<component name="ToolWindowManager">
<frame x="2286" y="267" width="1849" height="1047" extended-state="0" />
<editor active="true" />
<layout>
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24958587" sideWeight="0.5" order="0" side_tool="false" content_ui="combo" />
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="true" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="2" side_tool="true" content_ui="tabs" />
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager />
<watches-manager />
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/ESP32-mqtt-room.ino">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="493">
<caret line="248" column="12" lean-forward="false" selection-start-line="248" selection-start-column="12" selection-end-line="248" selection-end-column="12" />
<folding />
</state>
</provider>
</entry>
</component>
</project>

View File

@ -1,18 +1,17 @@
/* /*
Major thank you to the following contributors for their efforts: Major thank you to the following contributors for their efforts:
pcbreflux for the original version of this code, as well as the eddystone handlers. pcbreflux for the original version of this code, as well as the eddystone handlers.
Andreis Speiss for his work on YouTube and his invaluable github at sensorsiot Andreis Speiss for his work on YouTube and his invaluable github at sensorsiot
Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
Ported to Arduino ESP32 by Evandro Copercini Ported to Arduino ESP32 by Evandro Copercini
*/ */
#include <WiFi.h> #include <WiFi.h>
#include <PubSubClient.h> #include <PubSubClient.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#include <BLEDevice.h> #include <BLEDevice.h>
#include <BLEUtils.h> #include <BLEUtils.h>
#include <BLEScan.h> #include <BLEScan.h>
@ -23,7 +22,7 @@
#include "Settings_local.h" #include "Settings_local.h"
BLEScan* pBLEScan; BLEScan* pBLEScan;
int scanTime = 5; //In seconds int scanTime = 10; //In seconds
int waitTime = scanInterval; //In seconds int waitTime = scanInterval; //In seconds
uint16_t beconUUID = 0xFEAA; uint16_t beconUUID = 0xFEAA;
@ -104,6 +103,10 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
void onResult(BLEAdvertisedDevice advertisedDevice) { void onResult(BLEAdvertisedDevice advertisedDevice) {
unsigned long started = millis();
Serial.printf("\n\n");
Serial.println("onResult started");
StaticJsonBuffer<500> JSONbuffer; StaticJsonBuffer<500> JSONbuffer;
JsonObject& JSONencoder = JSONbuffer.createObject(); JsonObject& JSONencoder = JSONbuffer.createObject();
@ -116,14 +119,18 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
JSONencoder["uuid"] = mac_address; JSONencoder["uuid"] = mac_address;
JSONencoder["rssi"] = rssi; JSONencoder["rssi"] = rssi;
Serial.println("Parsed id");
if (advertisedDevice.haveName()){ if (advertisedDevice.haveName()){
String nameBLE = String(advertisedDevice.getName().c_str()); String nameBLE = String(advertisedDevice.getName().c_str());
Serial.print("Name: ");
Serial.println(nameBLE);
JSONencoder["name"] = nameBLE; JSONencoder["name"] = nameBLE;
} else { } else {
JSONencoder["name"] = "unknown"; JSONencoder["name"] = "unknown";
} }
Serial.printf("\n\n"); // Serial.printf("\n\n");
Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str()); Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
std::string strServiceData = advertisedDevice.getServiceData(); std::string strServiceData = advertisedDevice.getServiceData();
uint8_t cServiceData[100]; uint8_t cServiceData[100];
@ -153,7 +160,7 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
} else { } else {
if (advertisedDevice.haveManufacturerData()==true) { if (advertisedDevice.haveManufacturerData()==true) {
std::string strManufacturerData = advertisedDevice.getManufacturerData(); std::string strManufacturerData = advertisedDevice.getManufacturerData();
Serial.println("Got manufacturer data");
uint8_t cManufacturerData[100]; uint8_t cManufacturerData[100];
strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0); strManufacturerData.copy((char *)cManufacturerData, strManufacturerData.length(), 0);
@ -198,10 +205,7 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
Serial.printf("strManufacturerData: %d \n",strManufacturerData.length()); Serial.printf("strManufacturerData: %d \n",strManufacturerData.length());
// TODO: parse manufacturer data // TODO: parse manufacturer data
// for (int i=0;i<strManufacturerData.length();i++) {
// Serial.printf("[%X]",cManufacturerData[i]);
// }
// Serial.printf("\n");
} }
} else { } else {
@ -218,12 +222,7 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
} }
} }
Serial.println("wdt"); char JSONmessageBuffer[512];
vTaskDelay(500); // watchdog timer
unsigned long started = millis();
char JSONmessageBuffer[500];
JSONencoder.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer)); JSONencoder.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
String publishTopic = String(channel) + "/" + room; String publishTopic = String(channel) + "/" + room;
@ -231,15 +230,16 @@ class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
if (client.publish((char *)publishTopic.c_str(), JSONmessageBuffer) == true) { if (client.publish((char *)publishTopic.c_str(), JSONmessageBuffer) == true) {
Serial.print("Success sending message to topic: "); Serial.println(publishTopic); Serial.print("Success sending message to topic: "); Serial.println(publishTopic);
unsigned long duration = millis() - started;
Serial.print("duration ");
Serial.println(duration);
// Serial.print("Message: "); Serial.println(JSONmessageBuffer); // Serial.print("Message: "); Serial.println(JSONmessageBuffer);
} else { } else {
Serial.print("Error sending message: "); Serial.println(publishTopic); Serial.print("Error sending message: "); Serial.println(publishTopic);
Serial.print("Message: "); Serial.println(JSONmessageBuffer); Serial.print("Message: "); Serial.println(JSONmessageBuffer);
} }
unsigned long duration = millis() - started;
Serial.print("duration ");
Serial.println(duration);
} }
}; };
@ -294,16 +294,17 @@ void loop() {
if (!client.connected()) { if (!client.connected()) {
reconnect(); reconnect();
} }
client.loop();
if (millis() - last > (waitTime * 1000)) { // vTaskDelay(10); // watchdog timer
if (millis() - last > (waitTime * 1000) || last == 0) {
Serial.println("Scanning..."); Serial.println("Scanning...");
BLEScanResults foundDevices = pBLEScan->start(scanTime); BLEScanResults foundDevices = pBLEScan->start(scanTime);
Serial.printf("\nScan done! Devices found: %d\n",foundDevices.getCount()); Serial.printf("\nScan done! Devices found: %d\n",foundDevices.getCount());
last = millis(); last = millis();
} }
vTaskDelay(10); // watchdog timer
} }

View File

@ -4,7 +4,10 @@ An ESP32 based presence detection node for use with the Home Assistant mqtt_room
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). 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 ## 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).
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). To get the code onto your device, you can load it via the Arduino IDE or, thanks to some great work by [kylegordon](https://github.com/kylegordon), you can now build and upload using PlatformIO.
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). 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).
### Configuration ### Configuration

41
lib/readme.txt Normal file
View File

@ -0,0 +1,41 @@
This directory is intended for project specific (private) libraries.
PlatformIO will compile them to static libraries and link them to executable files.
The source code of each library should be placed in separate directories, like
"lib/private_lib/[here are source files]".
For example, see the structure of the following two libraries `Foo` and `Bar`:
|--lib
| |
| |--Bar
| | |--docs
| | |--examples
| | |--src
| | |- Bar.c
| | |- Bar.h
| | |- library.json (optional, custom build options, etc) https://docs.platformio.org/page/librarymanager/config.html
| |
| |--Foo
| | |- Foo.c
| | |- Foo.h
| |
| |- readme.txt --> THIS FILE
|
|- platformio.ini
|--src
|- main.c
Then in `src/main.c` you should use:
#include <Foo.h>
#include <Bar.h>
// rest H/C/CPP code
PlatformIO will find your libraries automatically, configure preprocessor's
include paths and build them.
More information about PlatformIO Library Dependency Finder
- https://docs.platformio.org/page/librarymanager/ldf.html

View File

@ -15,5 +15,6 @@ src_dir = .
platform = espressif32 platform = espressif32
framework = arduino framework = arduino
board = esp32dev board = esp32dev
lib_deps = PubSubClient, ArduinoJSON lib_deps = PubSubClient@2.6.0, ArduinoJSON@5.13.2, ESP32 BLE Arduino, AsyncMqttClient@0.8.2, AsyncTCP@1.0.1
board_build.partitions = partitions_singleapp.csv board_build.partitions = partitions_singleapp.csv
upload_port = COM13