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

View File

@@ -9,6 +9,9 @@
using namespace std;
using namespace std::placeholders;
// FIXME move to some global fnc lib
#define ARRAY_LENGTH(array) sizeof(array)/sizeof(array[0])
struct SprocketConfig {
int startupDelay;
int serialBaudRate;
@@ -28,7 +31,8 @@ class Sprocket {
virtual Sprocket* activate();
virtual Sprocket* activate(Scheduler*) { 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

View File

@@ -1,8 +1,6 @@
#ifndef __EXAMPLE_APP__
#define __EXAMPLE_APP__
//#include "Sprocket.h"
#include <ESPAsyncWebServer.h>
#include <Sprocket.h>
using namespace std;
@@ -12,23 +10,17 @@ class ExampleApp : public Sprocket {
public:
Task someTask;
ExampleApp(SprocketConfig cfg) : Sprocket(cfg) {
Serial.println("joo");
Serial.println("init");
}
Sprocket* activate(Scheduler* scheduler) {
Serial.println("activate");
someTask.set(TASK_SECOND, TASK_FOREVER, [this](){
someTask.set(TASK_SECOND, TASK_FOREVER, [](){
Serial.println("do stuff in task");
});
scheduler->addTask(someTask);
someTask.enable();
return this;
} 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

View File

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

View File

@@ -1,4 +1,4 @@
#ifndef __MESH_APP__
#ifndef __MESH_APP__
#define __MESH_APP__
#include <painlessMesh.h>
@@ -15,12 +15,13 @@ class MeshApp : public Sprocket {
MeshApp(SprocketConfig cfg) : Sprocket(cfg) {}
Sprocket* activate(Scheduler* scheduler, Network* 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
someTask.set(TASK_SECOND * 5, TASK_FOREVER,
bind(&MeshApp::heartbeat, this, net));
scheduler->addTask(someTask);
someTask.enable();
return this;
} using Sprocket::activate;
void heartbeat(MeshNet* network){

View File

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

View File

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