-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
; PlatformIO Project Configuration File | ||
; | ||
; Build options: build flags, source filter | ||
; Upload options: custom upload port, speed and extra flags | ||
; Library options: dependencies, extra library storages | ||
; Advanced options: extra scripting | ||
; | ||
; Please visit documentation for the other options and examples | ||
; https://docs.platformio.org/page/projectconf.html | ||
|
||
[env:esp8266dev] | ||
|
||
# Define platform and framework. | ||
platform = espressif8266 | ||
board = esp12e | ||
framework = arduino | ||
|
||
# Define cpu and flash configuration. | ||
upload_speed = 921600 | ||
monitor_speed = 9600 | ||
board_build.f_cpu = 80000000L | ||
board_build.f_flash = 80000000L | ||
board_build.flash_mode = qio | ||
board_build.ldscript = eagle.flash.4m1m.ld | ||
|
||
# Define library dependencies. | ||
lib_deps = | ||
ksIotFrameworkLib=https://github.com/cziter15/ksIotFrameworkLib | ||
|
||
# Define build flags. | ||
build_flags = | ||
-DPIO_FRAMEWORK_ARDUINO_LWIP2_HIGHER_BANDWIDTH | ||
-DPIO_FRAMEWORK_ARDUINO_ESPRESSIF_SDK305 | ||
|
||
# Define OTA parameters. | ||
upload_protocol = espota | ||
upload_port = BasicConfigDevice.local | ||
upload_flags = | ||
--port=8266 | ||
--auth=ota_ksiotframework |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#include "ConfigApp.h" | ||
#include "board.h" | ||
|
||
namespace apps | ||
{ | ||
const char ConfigApp::myDeviceName[] = "ExampleDevice"; | ||
|
||
bool ConfigApp::init() | ||
{ | ||
addComponent<ksf::comps::ksWifiConfigurator>(myDeviceName); | ||
addComponent<ksf::comps::ksMqttConfigProvider>(); | ||
|
||
addComponent<ksf::comps::ksLed>(CFG_STATUS_LED); | ||
|
||
return true; | ||
} | ||
|
||
bool ConfigApp::loop() | ||
{ | ||
return ksApplication::loop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#pragma once | ||
|
||
#include <ksIotFrameworkLib.h> | ||
|
||
namespace apps | ||
{ | ||
class ConfigApp : public ksf::ksApplication | ||
{ | ||
public: | ||
static const char myDeviceName[]; | ||
|
||
bool init() override; | ||
bool loop() override; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#include "ConfigApp.h" | ||
#include "DeviceFunctionsApp.h" | ||
|
||
#include "../board.h" | ||
|
||
namespace apps | ||
{ | ||
bool DeviceFunctionsApp::init() | ||
{ | ||
/* Create required components (Wifi and Mqtt debug). */ | ||
addComponent<ksf::comps::ksWifiConnector>(ConfigApp::myDeviceName); | ||
addComponent<ksf::comps::ksDevStatMqttReporter>(); | ||
|
||
/* Create mqttConnector component. */ | ||
mqttConnWp = addComponent<ksf::comps::ksMqttConnector>(); | ||
|
||
/* Create LED components. */ | ||
wifiLedWp = addComponent<ksf::comps::ksLed>(CFG_STATUS_LED); | ||
|
||
/* Bind to MQTT callbacks. */ | ||
if (auto mqttConnSp{mqttConnWp.lock()}) | ||
{ | ||
mqttConnSp->onConnected->registerEvent(connEventHandleSp, std::bind(&DeviceFunctionsApp::onMqttConnected, this)); | ||
mqttConnSp->onDisconnected->registerEvent(disEventHandleSp, std::bind(&DeviceFunctionsApp::onMqttDisconnected, this)); | ||
} | ||
|
||
/* Start LED blinking on finished init. */ | ||
if (auto statusLed_sp{wifiLedWp.lock()}) | ||
statusLed_sp->setBlinking(500); | ||
|
||
/* Application finished initialization, return true as it succedeed. */ | ||
return true; | ||
} | ||
|
||
void DeviceFunctionsApp::onMqttDisconnected() | ||
{ | ||
if (auto wifiLedSp{wifiLedWp.lock()}) | ||
wifiLedSp->setBlinking(500); | ||
} | ||
|
||
void DeviceFunctionsApp::onMqttConnected() | ||
{ | ||
if (auto wifiLedSp{wifiLedWp.lock()}) | ||
wifiLedSp->setBlinking(0); | ||
} | ||
|
||
bool DeviceFunctionsApp::loop() | ||
{ | ||
/* | ||
Return to superclass application loop. | ||
It handles all our components and whole app logic. | ||
*/ | ||
return ksApplication::loop(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include <ksIotFrameworkLib.h> | ||
|
||
namespace apps | ||
{ | ||
class DeviceFunctionsApp : public ksf::ksApplication | ||
{ | ||
protected: | ||
|
||
std::weak_ptr<ksf::comps::ksLed> wifiLedWp; // Weeak pointer to WiFi status LED component. | ||
std::weak_ptr<ksf::comps::ksMqttConnector> mqttConnWp; // Weeak pointer to MQTT component. | ||
|
||
std::unique_ptr<ksf::evt::ksEventHandle> connEventHandleSp, disEventHandleSp; // Handles to MQTT events. | ||
|
||
void onMqttConnected(); | ||
void onMqttDisconnected(); | ||
|
||
public: | ||
bool init() override; | ||
bool loop() override; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#pragma once | ||
|
||
#define CFG_STATUS_LED 6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include "apps/ConfigApp.h" | ||
#include "apps/DeviceFunctionsApp.h" | ||
|
||
using namespace apps; | ||
|
||
KSF_IMPLEMENT_APP_ROTATOR | ||
( | ||
ConfigApp, | ||
DeviceFunctionsApp | ||
) |