Merge branch '7-cleanup-examples' into 'develop'

Resolve "Cleanup examples"

Closes #7

See merge request wirelos/sprocket-core!10
This commit is contained in:
Patrick Balsiger
2018-07-19 15:39:51 +00:00
9 changed files with 32 additions and 34 deletions

View File

@@ -8,8 +8,8 @@
; Please visit documentation for the other options and examples ; Please visit documentation for the other options and examples
; http://docs.platformio.org/page/projectconf.html ; http://docs.platformio.org/page/projectconf.html
[platformio] ;[platformio]
env_default = mesh ;env_default = mesh
[common] [common]
framework = arduino framework = arduino
@@ -19,24 +19,22 @@ upload_speed = 921600
monitor_baud = 115200 monitor_baud = 115200
lib_deps = lib_deps =
Hash Hash
ESP Async WebServer
ESPAsyncTCP ESPAsyncTCP
TaskScheduler TaskScheduler
painlessMesh
[env:build] ;[env:build]
src_filter = +<*> -<examples/> ;src_filter = +<*> -<examples/>
#platform = https://github.com/platformio/platform-espressif8266.git#feature/stage ;#platform = https://github.com/platformio/platform-espressif8266.git#feature/stage
#platform = https://github.com/platformio/platform-espressif8266.git ;#platform = https://github.com/platformio/platform-espressif8266.git
#platform = espressif8266@~1.6.0 ;#platform = espressif8266@~1.6.0
platform = ${common.platform} ;platform = ${common.platform}
board = ${common.board} ;board = ${common.board}
upload_speed = ${common.upload_speed} ;upload_speed = ${common.upload_speed}
monitor_baud = ${common.monitor_baud} ;monitor_baud = ${common.monitor_baud}
framework = ${common.framework} ;framework = ${common.framework}
lib_deps = ${common.lib_deps} ;lib_deps = ${common.lib_deps}
#build_flags = -DLED_PIN=2 -g ;build_flags = -DLED_PIN=2 -g
;upload_port = /dev/ttyUSB0 ;upload_port = /dev/ttyUSB0
;upload_port = 192.168.1.168 ;upload_port = 192.168.1.168
@@ -57,13 +55,15 @@ upload_speed = ${common.upload_speed}
monitor_baud = ${common.monitor_baud} monitor_baud = ${common.monitor_baud}
framework = ${common.framework} framework = ${common.framework}
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
painlessMesh
[env:meshMqttBridge] [env:meshMqttBridge]
src_filter = +<*> -<examples/> +<examples/mqttBridge/> src_filter = +<*> -<examples/> +<examples/meshMqttBridge/>
platform = espressif8266 platform = espressif8266
board = esp12e board = esp12e
upload_speed = ${common.upload_speed} upload_speed = ${common.upload_speed}
monitor_baud = ${common.monitor_baud} monitor_baud = ${common.monitor_baud}
framework = ${common.framework} framework = ${common.framework}
lib_deps = ${common.lib_deps} lib_deps = ${common.lib_deps}
painlessMesh
PubSubClient PubSubClient

View File

@@ -9,6 +9,9 @@
using namespace std; using namespace std;
using namespace std::placeholders; using namespace std::placeholders;
// FIXME move to some global fnc lib
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0])
struct SprocketConfig { struct SprocketConfig {
int startupDelay; int startupDelay;
int serialBaudRate; int serialBaudRate;
@@ -28,7 +31,8 @@ class Sprocket {
virtual Sprocket* activate(); virtual Sprocket* activate();
virtual Sprocket* activate(Scheduler*) { return this; } virtual Sprocket* activate(Scheduler*) { return this; }
virtual Sprocket* activate(Scheduler*, Network*) { return this; } virtual Sprocket* activate(Scheduler*, Network*) { return this; }
//virtual void dispatch(uint32_t from, String &msg) {}; // TODO bind onMessage to network->onReceive
//virtual void onMessage(uint32_t from, String &msg) {};
}; };
#endif #endif

View File

@@ -1,8 +1,6 @@
#ifndef __EXAMPLE_APP__ #ifndef __EXAMPLE_APP__
#define __EXAMPLE_APP__ #define __EXAMPLE_APP__
//#include "Sprocket.h"
#include <ESPAsyncWebServer.h>
#include <Sprocket.h> #include <Sprocket.h>
using namespace std; using namespace std;
@@ -12,23 +10,17 @@ class ExampleApp : public Sprocket {
public: public:
Task someTask; Task someTask;
ExampleApp(SprocketConfig cfg) : Sprocket(cfg) { ExampleApp(SprocketConfig cfg) : Sprocket(cfg) {
Serial.println("joo"); Serial.println("init");
} }
Sprocket* activate(Scheduler* scheduler) { Sprocket* activate(Scheduler* scheduler) {
Serial.println("activate"); Serial.println("activate");
someTask.set(TASK_SECOND, TASK_FOREVER, [this](){ someTask.set(TASK_SECOND, TASK_FOREVER, [](){
Serial.println("do stuff in task"); Serial.println("do stuff in task");
}); });
scheduler->addTask(someTask); scheduler->addTask(someTask);
someTask.enable(); someTask.enable();
return this;
} using Sprocket::activate; } using Sprocket::activate;
void server(AsyncWebServer* srv) {
srv->on("/ping", HTTP_POST, bind(&ExampleApp::handlePingRequest, this, _1));
}
void handlePingRequest(AsyncWebServerRequest *request) {
Serial.println("pinged");
request->send(200, "text/html", "pong");
}
}; };
#endif #endif

View File

@@ -1,9 +1,10 @@
#define _TASK_SLEEP_ON_IDLE_RUN #define _TASK_SLEEP_ON_IDLE_RUN
#define _TASK_STD_FUNCTION #define _TASK_STD_FUNCTION
#define SERIAL_BAUD_RATE 115200 #define SERIAL_BAUD_RATE 115200
#define STARTUP_DELAY 3000 #define STARTUP_DELAY 3000
#include "ExampleApp.h" #include "ExampleApp.cpp"
ExampleApp sprocket({ STARTUP_DELAY, SERIAL_BAUD_RATE }); ExampleApp sprocket({ STARTUP_DELAY, SERIAL_BAUD_RATE });

View File

@@ -1,4 +1,4 @@
#ifndef __MESH_APP__ #ifndef __MESH_APP__
#define __MESH_APP__ #define __MESH_APP__
#include <painlessMesh.h> #include <painlessMesh.h>
@@ -15,12 +15,13 @@ class MeshApp : public Sprocket {
MeshApp(SprocketConfig cfg) : Sprocket(cfg) {} MeshApp(SprocketConfig cfg) : Sprocket(cfg) {}
Sprocket* activate(Scheduler* scheduler, Network* network) { Sprocket* activate(Scheduler* scheduler, Network* network) {
net = static_cast<MeshNet*>(network); net = static_cast<MeshNet*>(network);
//net->onReceive(bind(&MeshApp::onReceive,this, _1, _2)); net->onReceive(bind(&MeshApp::dispatch,this, _1, _2));
// add a task that sends stuff to the mesh // add a task that sends stuff to the mesh
someTask.set(TASK_SECOND * 5, TASK_FOREVER, someTask.set(TASK_SECOND * 5, TASK_FOREVER,
bind(&MeshApp::heartbeat, this, net)); bind(&MeshApp::heartbeat, this, net));
scheduler->addTask(someTask); scheduler->addTask(someTask);
someTask.enable(); someTask.enable();
return this;
} using Sprocket::activate; } using Sprocket::activate;
void heartbeat(MeshNet* network){ void heartbeat(MeshNet* network){

View File

@@ -1,6 +1,6 @@
#include "config.h" #include "config.h"
#include "MeshNet.h" #include "MeshNet.h"
#include "MeshApp.h" #include "MeshApp.cpp"
MeshNet net({ MeshNet net({
STATION_MODE, WIFI_CHANNEL, STATION_MODE, WIFI_CHANNEL,

View File

@@ -1,6 +1,6 @@
#include "config.h" #include "config.h"
#include "MeshNet.h" #include "MeshNet.h"
#include "MqttMeshBridge.h" #include "MqttMeshBridge.cpp"
MeshNet net({ MeshNet net({
STATION_MODE, WIFI_CHANNEL, STATION_MODE, WIFI_CHANNEL,