mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-14 20:56:38 +01:00
cleanup examples, build and ci
This commit is contained in:
@@ -34,11 +34,10 @@ firmware-build:
|
|||||||
stage: build
|
stage: build
|
||||||
image: python:2.7-stretch
|
image: python:2.7-stretch
|
||||||
script:
|
script:
|
||||||
- pio run -t clean
|
- pio run --target clean
|
||||||
- pio run --environment basic
|
- pio run --environment basic
|
||||||
- pio run --environment mesh
|
- pio run --environment wifi
|
||||||
- pio run --environment meshMqttBridge
|
- pio run --environment wifiMesh
|
||||||
- pio run --environment standalone
|
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- .pioenvs/*/firmware.*
|
- .pioenvs/*/firmware.*
|
||||||
|
|||||||
@@ -46,8 +46,8 @@ monitor_baud = ${common.monitor_baud}
|
|||||||
framework = ${common.framework}
|
framework = ${common.framework}
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
|
|
||||||
[env:mesh]
|
[env:wifiMesh]
|
||||||
src_filter = +<*> -<examples/> +<examples/mesh/>
|
src_filter = +<*> -<examples/> +<examples/wifiMesh/>
|
||||||
platform = ${common.platform}
|
platform = ${common.platform}
|
||||||
board = ${common.board}
|
board = ${common.board}
|
||||||
upload_speed = ${common.upload_speed}
|
upload_speed = ${common.upload_speed}
|
||||||
@@ -55,19 +55,13 @@ monitor_baud = ${common.monitor_baud}
|
|||||||
framework = ${common.framework}
|
framework = ${common.framework}
|
||||||
lib_deps = ${common.lib_deps}
|
lib_deps = ${common.lib_deps}
|
||||||
painlessMesh
|
painlessMesh
|
||||||
ESP8266mDNS
|
|
||||||
ArduinoOTA
|
|
||||||
ESP Async WebServer
|
|
||||||
ESPAsyncTCP
|
|
||||||
;upload_port = 192.168.1.247
|
|
||||||
|
|
||||||
[env:standalone]
|
[env:wifi]
|
||||||
src_filter = +<*> -<examples/> +<examples/standalone/>
|
src_filter = +<*> -<examples/> +<examples/wifi/>
|
||||||
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}
|
||||||
ArduinoOTA
|
|
||||||
ESP Async WebServer
|
ESP Async WebServer
|
||||||
@@ -28,6 +28,7 @@ int MeshNet::connect(){
|
|||||||
if(config.stationMode){
|
if(config.stationMode){
|
||||||
connectStation();
|
connectStation();
|
||||||
}
|
}
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int MeshNet::connectStation() {
|
int MeshNet::connectStation() {
|
||||||
|
|||||||
@@ -1,46 +0,0 @@
|
|||||||
|
|
||||||
#ifndef __WIFI_APP__
|
|
||||||
#define __WIFI_APP__
|
|
||||||
|
|
||||||
#include <TaskScheduler.h>
|
|
||||||
#include <Sprocket.h>
|
|
||||||
#include <plugins/WebServerConfig.h>
|
|
||||||
//#include <plugins/OtaTcpPlugin.cpp>
|
|
||||||
#include <plugins/WebServerPlugin.cpp>
|
|
||||||
#include <plugins/WebConfigPlugin.cpp>
|
|
||||||
#include "Mediator.h"
|
|
||||||
|
|
||||||
using namespace std;
|
|
||||||
using namespace std::placeholders;
|
|
||||||
|
|
||||||
AsyncWebServer WEBSERVER(80);
|
|
||||||
|
|
||||||
class WiFiApp : public Sprocket {
|
|
||||||
public:
|
|
||||||
Scheduler* ts;
|
|
||||||
Task someTask;
|
|
||||||
WiFiApp(SprocketConfig cfg, /* OtaConfig otaCfg, */ WebServerConfig webCfg) : Sprocket(cfg) {
|
|
||||||
//addPlugin(new OtaTcpPlugin(otaCfg));
|
|
||||||
addPlugin(new WebServerPlugin(webCfg, &WEBSERVER));
|
|
||||||
addPlugin(new WebConfigPlugin(&WEBSERVER));
|
|
||||||
ts = new Scheduler();
|
|
||||||
}
|
|
||||||
|
|
||||||
Sprocket* activate(Scheduler* scheduler) {
|
|
||||||
Sprocket::activate(ts);
|
|
||||||
Serial.println("activate WiFiApp");
|
|
||||||
// add a task
|
|
||||||
someTask.set(TASK_SECOND, TASK_FOREVER, [](){
|
|
||||||
Serial.println("do stuff in task");
|
|
||||||
});
|
|
||||||
//addTask(someTask);
|
|
||||||
return this;
|
|
||||||
} using Sprocket::activate;
|
|
||||||
void loop(){
|
|
||||||
//Sprocket::loop();
|
|
||||||
ts->execute();
|
|
||||||
yield();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
@@ -1,30 +0,0 @@
|
|||||||
#include "config.h"
|
|
||||||
#include "WiFiNet.h"
|
|
||||||
#include "WiFiApp.h"
|
|
||||||
|
|
||||||
/* WiFiConfig wifiCfg = {
|
|
||||||
.stationMode=SPROCKET_MODE,
|
|
||||||
.stationSSID=STATION_SSID,
|
|
||||||
.stationPassword=STATION_PASSWORD,
|
|
||||||
.apSSID=AP_SSID,
|
|
||||||
.apPassword=AP_PASSWORD,
|
|
||||||
.hostname=HOSTNAME,
|
|
||||||
.connectTimeout=CONNECT_TIMEOUT
|
|
||||||
}; */
|
|
||||||
|
|
||||||
WiFiNet net(SPROCKET_MODE,STATION_SSID, STATION_PASSWORD,AP_SSID, AP_PASSWORD,HOSTNAME,CONNECT_TIMEOUT);
|
|
||||||
WiFiApp sprocket(
|
|
||||||
{ STARTUP_DELAY, SERIAL_BAUD_RATE },
|
|
||||||
/* { OTA_PORT, OTA_PASSWORD }, */
|
|
||||||
{ WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE }
|
|
||||||
);
|
|
||||||
|
|
||||||
void setup() {
|
|
||||||
delay(3000);
|
|
||||||
sprocket.join(net);
|
|
||||||
}
|
|
||||||
|
|
||||||
void loop() {
|
|
||||||
sprocket.loop();
|
|
||||||
yield();
|
|
||||||
}
|
|
||||||
24
src/examples/wifi/WiFiApp.h
Normal file
24
src/examples/wifi/WiFiApp.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
#ifndef __WIFI_APP__
|
||||||
|
#define __WIFI_APP__
|
||||||
|
|
||||||
|
#include <TaskScheduler.h>
|
||||||
|
#include <Sprocket.h>
|
||||||
|
#include <plugins/WebServerConfig.h>
|
||||||
|
#include <plugins/WebServerPlugin.cpp>
|
||||||
|
#include <plugins/WebConfigPlugin.cpp>
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
class WiFiApp : public Sprocket {
|
||||||
|
public:
|
||||||
|
AsyncWebServer* server;
|
||||||
|
WiFiApp(SprocketConfig cfg, WebServerConfig webCfg) : Sprocket(cfg) {
|
||||||
|
server = new AsyncWebServer(webCfg.port);
|
||||||
|
addPlugin(new WebServerPlugin(webCfg, server));
|
||||||
|
addPlugin(new WebConfigPlugin(server));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -27,5 +27,6 @@
|
|||||||
#define WEB_CONTEXT_PATH "/"
|
#define WEB_CONTEXT_PATH "/"
|
||||||
#define WEB_DOC_ROOT "/www"
|
#define WEB_DOC_ROOT "/www"
|
||||||
#define WEB_DEFAULT_FILE "index.html"
|
#define WEB_DEFAULT_FILE "index.html"
|
||||||
|
#define WEB_SERVER_PORT 80
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
28
src/examples/wifi/main.cpp
Normal file
28
src/examples/wifi/main.cpp
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#include "config.h"
|
||||||
|
#include "WiFiNet.h"
|
||||||
|
#include "WiFiApp.h"
|
||||||
|
|
||||||
|
WiFiNet wifi(
|
||||||
|
SPROCKET_MODE,
|
||||||
|
STATION_SSID,
|
||||||
|
STATION_PASSWORD,
|
||||||
|
AP_SSID,
|
||||||
|
AP_PASSWORD,
|
||||||
|
HOSTNAME,
|
||||||
|
CONNECT_TIMEOUT);
|
||||||
|
WiFiApp sprocket(
|
||||||
|
{STARTUP_DELAY, SERIAL_BAUD_RATE},
|
||||||
|
{WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE, WEB_SERVER_PORT});
|
||||||
|
|
||||||
|
void setup()
|
||||||
|
{
|
||||||
|
delay(3000);
|
||||||
|
wifi.connect();
|
||||||
|
sprocket.activate();
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop()
|
||||||
|
{
|
||||||
|
sprocket.loop();
|
||||||
|
yield();
|
||||||
|
}
|
||||||
@@ -4,26 +4,18 @@
|
|||||||
#include <Sprocket.h>
|
#include <Sprocket.h>
|
||||||
#include <MeshNet.h>
|
#include <MeshNet.h>
|
||||||
#include <plugins/MeshNetworkPlugin.cpp>
|
#include <plugins/MeshNetworkPlugin.cpp>
|
||||||
#include <plugins/WebServerConfig.h>
|
|
||||||
#include <plugins/WebServerPlugin.cpp>
|
|
||||||
#include <plugins/WebConfigPlugin.cpp>
|
|
||||||
#include "Mediator.h"
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
|
|
||||||
AsyncWebServer WEBSERVER(80);
|
|
||||||
|
|
||||||
class MeshApp : public Sprocket
|
class MeshApp : public Sprocket
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Task heartbeatTask;
|
Task heartbeatTask;
|
||||||
|
|
||||||
MeshApp(SprocketConfig cfg, MeshConfig meshCfg, WebServerConfig webCfg) : Sprocket(cfg)
|
MeshApp(SprocketConfig cfg, MeshConfig meshCfg) : Sprocket(cfg)
|
||||||
{
|
{
|
||||||
addPlugin(new MeshNetworkPlugin(meshCfg));
|
addPlugin(new MeshNetworkPlugin(meshCfg));
|
||||||
addPlugin(new WebServerPlugin(webCfg, &WEBSERVER));
|
|
||||||
addPlugin(new WebConfigPlugin(&WEBSERVER));
|
|
||||||
subscribe("device/heartbeat", bind(&MeshApp::messageHandler, this, _1));
|
subscribe("device/heartbeat", bind(&MeshApp::messageHandler, this, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -6,8 +6,7 @@ MeshApp sprocket(
|
|||||||
{SPROCKET_MODE, WIFI_CHANNEL,
|
{SPROCKET_MODE, WIFI_CHANNEL,
|
||||||
MESH_PORT, MESH_PREFIX, MESH_PASSWORD,
|
MESH_PORT, MESH_PREFIX, MESH_PASSWORD,
|
||||||
STATION_SSID, STATION_PASSWORD, HOSTNAME,
|
STATION_SSID, STATION_PASSWORD, HOSTNAME,
|
||||||
MESH_DEBUG_TYPES},
|
MESH_DEBUG_TYPES});
|
||||||
{WEB_CONTEXT_PATH, WEB_DOC_ROOT, WEB_DEFAULT_FILE});
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
@@ -27,8 +27,8 @@ class MeshNetworkPlugin : public NetworkPlugin
|
|||||||
{
|
{
|
||||||
userScheduler->setHighPriorityScheduler(meshScheduler);
|
userScheduler->setHighPriorityScheduler(meshScheduler);
|
||||||
network->onReceive(bind(&MeshNetworkPlugin::dispatch, this, _1, _2));
|
network->onReceive(bind(&MeshNetworkPlugin::dispatch, this, _1, _2));
|
||||||
// TODO base subscribers
|
|
||||||
subscribe("mesh/broadcast", bind(&MeshNetworkPlugin::broadcast, this, _1));
|
subscribe("mesh/broadcast", bind(&MeshNetworkPlugin::broadcast, this, _1));
|
||||||
|
// TODO mesh/sendTo
|
||||||
NetworkPlugin::activate(meshScheduler);
|
NetworkPlugin::activate(meshScheduler);
|
||||||
}
|
}
|
||||||
void broadcast(String msg)
|
void broadcast(String msg)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ struct WebServerConfig {
|
|||||||
const char* contextPath;
|
const char* contextPath;
|
||||||
const char* docRoot;
|
const char* docRoot;
|
||||||
const char* defaultFile;
|
const char* defaultFile;
|
||||||
|
int port;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
Reference in New Issue
Block a user