mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-16 13:25:03 +01:00
fix basic example
This commit is contained in:
35
.gitlab-ci.yml
Normal file
35
.gitlab-ci.yml
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
platformio:
|
||||||
|
before_script:
|
||||||
|
- apt-get update -qq && apt-get install -y -qq python-pip
|
||||||
|
- pip install platformio
|
||||||
|
- platformio lib --global install ArduinoJson TaskScheduler PubSubClient ESPAsyncTCP AsyncTCP
|
||||||
|
script:
|
||||||
|
- platformio ci --lib="." --board=nodemcuv2 examples/basic/basic.ino -O "build_flags = -Werror"
|
||||||
|
- platformio ci --lib="." --board=nodemcuv2 examples/mesh/mesh.ino -O "build_flags = -Wall -Wextra -Wno-unused-parameter -Werror"
|
||||||
|
|
||||||
|
arduino:
|
||||||
|
before_script:
|
||||||
|
- wget https://downloads.arduino.cc/arduino-1.8.5-linux64.tar.xz
|
||||||
|
- tar xvfJ arduino-1.8.5-linux64.tar.xz
|
||||||
|
- cd arduino-1.8.5
|
||||||
|
- ./arduino --pref "boardsmanager.additional.urls=https://adafruit.github.io/arduino-board-index/package_adafruit_index.json,http://arduino.esp8266.com/stable/package_esp8266com_index.json" --save-prefs
|
||||||
|
- ./arduino --install-boards esp8266:esp8266
|
||||||
|
- ./arduino --install-library TaskScheduler
|
||||||
|
- ./arduino --install-library ArduinoJson
|
||||||
|
- git clone https://github.com/me-no-dev/ESPAsyncTCP; cp -r ESPAsyncTCP/src ~/Arduino/libraries/ESPAsyncTCP
|
||||||
|
- git clone https://github.com/me-no-dev/AsyncTCP; cp -r AsyncTCP/src ~/Arduino/libraries/AsyncTCP
|
||||||
|
- cp -r ../src ~/Arduino/libraries/painlessMesh
|
||||||
|
script:
|
||||||
|
- ./arduino -v --board esp8266:esp8266:d1_mini:CpuFrequency=80,FlashSize=4M1M --verify ../examples/startHere/basic.ino
|
||||||
|
- ./arduino -v --board esp8266:esp8266:d1_mini:CpuFrequency=80,FlashSize=4M1M --verify ../examples/startHere/startHere.ino
|
||||||
|
|
||||||
|
pages:
|
||||||
|
script:
|
||||||
|
- apt-get update && apt-get install -y doxygen
|
||||||
|
- doxygen doxygen/Doxyfile
|
||||||
|
- mv doxygen/documentation/html/ public/
|
||||||
|
artifacts:
|
||||||
|
paths:
|
||||||
|
- public
|
||||||
|
only:
|
||||||
|
- master
|
||||||
@@ -9,12 +9,11 @@
|
|||||||
; http://docs.platformio.org/page/projectconf.html
|
; http://docs.platformio.org/page/projectconf.html
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
env_default = mesh
|
env_default = basic
|
||||||
|
|
||||||
[common]
|
[common]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
lib_deps =
|
lib_deps =
|
||||||
ESPAsyncWifiManager
|
|
||||||
ESP Async WebServer
|
ESP Async WebServer
|
||||||
ESPAsyncTCP
|
ESPAsyncTCP
|
||||||
TaskScheduler
|
TaskScheduler
|
||||||
@@ -34,6 +33,17 @@ lib_deps = ${common.lib_deps}
|
|||||||
;upload_port = /dev/ttyUSB0
|
;upload_port = /dev/ttyUSB0
|
||||||
;upload_port = 192.168.1.168
|
;upload_port = 192.168.1.168
|
||||||
|
|
||||||
|
[env:basic]
|
||||||
|
src_filter = +<*> +<examples/basic/> -<examples/mesh/>
|
||||||
|
platform = espressif8266
|
||||||
|
board = esp12e
|
||||||
|
upload_speed = 921600
|
||||||
|
monitor_baud = 115200
|
||||||
|
framework = ${common.framework}
|
||||||
|
lib_deps = ${common.lib_deps}
|
||||||
|
ESPAsyncWifiManager
|
||||||
|
|
||||||
|
|
||||||
[env:mesh]
|
[env:mesh]
|
||||||
src_filter = +<*> +<examples/mesh/> -<examples/basic/>
|
src_filter = +<*> +<examples/mesh/> -<examples/basic/>
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
|
|||||||
22
src/App.h
22
src/App.h
@@ -2,27 +2,15 @@
|
|||||||
#define _APP_H_
|
#define _APP_H_
|
||||||
|
|
||||||
#include <TaskSchedulerDeclarations.h>
|
#include <TaskSchedulerDeclarations.h>
|
||||||
//#include "Sprocket.h"
|
#include "Sprocket.h"
|
||||||
#include "AppStack.h"
|
#include "AppStack.h"
|
||||||
|
#include "Network.h"
|
||||||
/* template <class T>
|
|
||||||
class App {
|
|
||||||
private:
|
|
||||||
T* stack;
|
|
||||||
public:
|
|
||||||
App();
|
|
||||||
App(T* stack);
|
|
||||||
};
|
|
||||||
*/
|
|
||||||
|
|
||||||
class App {
|
class App {
|
||||||
protected:
|
|
||||||
//Sprocket* sprocket;
|
|
||||||
public:
|
public:
|
||||||
/* App(Sprocket* sprkt){
|
virtual void join(Network& network) {};
|
||||||
sprocket = sprkt;
|
virtual void activate(Scheduler* scheduler, Network* network) {};
|
||||||
} */
|
virtual void activate(Scheduler* scheduler) {};
|
||||||
virtual void activate(Scheduler* scheduler);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,10 +1,56 @@
|
|||||||
#ifndef __MESHNET_H__
|
#ifndef __MESHNET_H__
|
||||||
#define __MESHNET_H__
|
#define __MESHNET_H__
|
||||||
|
|
||||||
|
#include <painlessMesh.h>
|
||||||
|
|
||||||
#include "Network.h"
|
#include "Network.h"
|
||||||
|
|
||||||
class MeshNet : public Network {
|
using namespace std;
|
||||||
|
using namespace std::placeholders;
|
||||||
|
|
||||||
|
|
||||||
|
#define MESH_PREFIX "whateverYouLike"
|
||||||
|
#define MESH_PASSWORD "somethingSneaky"
|
||||||
|
#define MESH_PORT 5555
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MeshNet : public Network {
|
||||||
|
public:
|
||||||
|
painlessMesh mesh;
|
||||||
|
Network* init(){
|
||||||
|
Serial.println("init mesh");
|
||||||
|
mesh.setDebugMsgTypes( ERROR | STARTUP | CONNECTION ); // set before init() so that you can see startup messages
|
||||||
|
mesh.init( MESH_PREFIX, MESH_PASSWORD, scheduler, MESH_PORT, WIFI_AP_STA, 11 );
|
||||||
|
mesh.onReceive(bind(&MeshNet::receivedCallback,this, _1, _2));
|
||||||
|
mesh.onNewConnection(bind(&MeshNet::newConnectionCallback, this, _1));
|
||||||
|
mesh.onChangedConnections(bind(&MeshNet::changedConnectionCallback, this));
|
||||||
|
mesh.onNodeTimeAdjusted(bind(&MeshNet::nodeTimeAdjustedCallback, this, _1));
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
Network* connect(){
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
void update(){
|
||||||
|
Serial.println("update mesh");
|
||||||
|
mesh.update();
|
||||||
|
}
|
||||||
|
void receivedCallback( uint32_t from, String &msg ) {
|
||||||
|
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void newConnectionCallback(uint32_t nodeId) {
|
||||||
|
Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void changedConnectionCallback() {
|
||||||
|
Serial.printf("Changed connections %s\n",mesh.subConnectionJson().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void nodeTimeAdjustedCallback(int32_t offset) {
|
||||||
|
Serial.printf("Adjusted time %u. Offset = %d\n", mesh.getNodeTime(),offset);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
#ifndef __NETWORK_H__
|
#ifndef __NETWORK_H__
|
||||||
#define __NETWORK_H__
|
#define __NETWORK_H__
|
||||||
|
|
||||||
|
#include <TaskSchedulerDeclarations.h>
|
||||||
|
|
||||||
class Network {
|
class Network {
|
||||||
|
protected:
|
||||||
|
Scheduler* scheduler;
|
||||||
public:
|
public:
|
||||||
Network(){}
|
Network(){}
|
||||||
virtual Network* connect();
|
virtual Network* init() { return this; };
|
||||||
|
virtual Network* connect() { return this; };
|
||||||
|
virtual void update() {};
|
||||||
|
Network* setScheduler(Scheduler* s) {
|
||||||
|
scheduler = s;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -9,7 +9,15 @@ Sprocket* Sprocket::init(SprocketConfig cfg){
|
|||||||
SPIFFS.begin();
|
SPIFFS.begin();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
Sprocket* Sprocket::join(Network& net){
|
||||||
|
//network = net;
|
||||||
|
Serial.println("join network");
|
||||||
|
net.setScheduler(&scheduler);
|
||||||
|
net.init();
|
||||||
|
net.connect();
|
||||||
|
Serial.println("connected");
|
||||||
|
return this;
|
||||||
|
}
|
||||||
Sprocket* Sprocket::use(AppStack* stk){
|
Sprocket* Sprocket::use(AppStack* stk){
|
||||||
stack = stk;
|
stack = stk;
|
||||||
return this;
|
return this;
|
||||||
@@ -21,12 +29,15 @@ Sprocket* Sprocket::addTask(Task& tsk){
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
Sprocket* Sprocket::registerApp(App& app){
|
Sprocket* Sprocket::app(App& app){
|
||||||
|
//app.join(&network);
|
||||||
|
//app.activate(&scheduler, network);
|
||||||
app.activate(&scheduler);
|
app.activate(&scheduler);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprocket::loop(){
|
void Sprocket::loop(){
|
||||||
|
//network->update();
|
||||||
scheduler.execute();
|
scheduler.execute();
|
||||||
//stack->loop();
|
//stack->loop();
|
||||||
}
|
}
|
||||||
@@ -5,9 +5,9 @@
|
|||||||
#include <TaskSchedulerDeclarations.h>
|
#include <TaskSchedulerDeclarations.h>
|
||||||
|
|
||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
#include "WiFiNet.h"
|
|
||||||
#include "AppStack.h"
|
#include "AppStack.h"
|
||||||
#include "App.h"
|
#include "App.h"
|
||||||
|
#include "Network.h"
|
||||||
|
|
||||||
struct SprocketConfig {
|
struct SprocketConfig {
|
||||||
int serialBaudRate;
|
int serialBaudRate;
|
||||||
@@ -17,12 +17,14 @@ class Sprocket {
|
|||||||
private:
|
private:
|
||||||
AppStack* stack;
|
AppStack* stack;
|
||||||
Scheduler scheduler;
|
Scheduler scheduler;
|
||||||
|
Network* network;
|
||||||
public:
|
public:
|
||||||
Sprocket();
|
Sprocket();
|
||||||
Sprocket* init(SprocketConfig);
|
Sprocket* init(SprocketConfig);
|
||||||
|
Sprocket* join(Network&);
|
||||||
Sprocket* use(AppStack*);
|
Sprocket* use(AppStack*);
|
||||||
Sprocket* addTask(Task&);
|
Sprocket* addTask(Task&);
|
||||||
Sprocket* registerApp(App&);
|
Sprocket* app(App&);
|
||||||
void loop();
|
void loop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,8 @@ class WiFiNet : public Network {
|
|||||||
server = stack->server;
|
server = stack->server;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
WiFiNet* connect(){
|
WiFiNet* init(){}
|
||||||
|
WiFiNet* connect(){
|
||||||
server = new AsyncWebServer(80);
|
server = new AsyncWebServer(80);
|
||||||
dns = new DNSServer();
|
dns = new DNSServer();
|
||||||
wifiManager = new AsyncWiFiManager(server, dns);
|
wifiManager = new AsyncWiFiManager(server, dns);
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
#include <TaskScheduler.h>
|
#include <TaskScheduler.h>
|
||||||
#include "Sprocket.h"
|
#include "Sprocket.h"
|
||||||
#include "AppStack.h"
|
#include "AppStack.h"
|
||||||
//#include "WiFiNet.h"
|
#include "WiFiNet.h"
|
||||||
|
|
||||||
#include "ExampleApp.h"
|
#include "ExampleApp.h"
|
||||||
|
|
||||||
@@ -13,9 +13,9 @@
|
|||||||
|
|
||||||
SprocketConfig config = { SERIAL_BAUD_RATE };
|
SprocketConfig config = { SERIAL_BAUD_RATE };
|
||||||
|
|
||||||
Sprocket sprocket;
|
|
||||||
AppStack stack;
|
|
||||||
WiFiNet net;
|
WiFiNet net;
|
||||||
|
Sprocket sprocket;
|
||||||
|
//AppStack stack;
|
||||||
|
|
||||||
ExampleApp app;
|
ExampleApp app;
|
||||||
|
|
||||||
@@ -23,20 +23,17 @@ void setup() {
|
|||||||
|
|
||||||
delay(STARTUP_DELAY);
|
delay(STARTUP_DELAY);
|
||||||
|
|
||||||
Serial.println("setup");
|
|
||||||
|
|
||||||
//sprocket.use(&stack);
|
//sprocket.use(&stack);
|
||||||
sprocket.init(config);
|
sprocket.init(config);
|
||||||
sprocket.registerApp(app);
|
sprocket.app(app);
|
||||||
|
sprocket.join(net);
|
||||||
net.connect();
|
|
||||||
|
|
||||||
|
|
||||||
|
//net.connect();
|
||||||
//stack.begin();
|
//stack.begin();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
sprocket.loop();
|
sprocket.loop();
|
||||||
|
net.update();
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
59
src/examples/mesh/MeshApp.h
Normal file
59
src/examples/mesh/MeshApp.h
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
#ifndef __MESH_APP__
|
||||||
|
#define __MESH_APP__
|
||||||
|
|
||||||
|
//#include "Sprocket.h"
|
||||||
|
#include <painlessMesh.h>
|
||||||
|
|
||||||
|
#include "App.h"
|
||||||
|
|
||||||
|
#define MESH_PREFIX "whateverYouLike"
|
||||||
|
#define MESH_PASSWORD "somethingSneaky"
|
||||||
|
#define MESH_PORT 5555
|
||||||
|
|
||||||
|
class MeshApp : public App {
|
||||||
|
public:
|
||||||
|
Task someTask;
|
||||||
|
MeshNet* net;
|
||||||
|
MeshApp() /* App(sprkt) */ {
|
||||||
|
Serial.println("joo");
|
||||||
|
}
|
||||||
|
|
||||||
|
void activate(Scheduler* scheduler, MeshNet* network) {
|
||||||
|
Serial.println("activate");
|
||||||
|
net = network;
|
||||||
|
Serial.println("join mesh");
|
||||||
|
/* net->mesh.onReceive(bind(&MeshApp::receivedCallback,this, _1, _2));
|
||||||
|
net->mesh.onNewConnection(bind(&MeshApp::newConnectionCallback, this, _1));
|
||||||
|
net->mesh.onChangedConnections(bind(&MeshApp::changedConnectionCallback, this));
|
||||||
|
net->mesh.onNodeTimeAdjusted(bind(&MeshApp::nodeTimeAdjustedCallback, this, _1)); */
|
||||||
|
join();
|
||||||
|
/* someTask.set(TASK_SECOND * 5, TASK_FOREVER, [this, network](){
|
||||||
|
Serial.println("task triggered");
|
||||||
|
String msg = "Hello from node ";
|
||||||
|
msg += network.mesh.getNodeId();
|
||||||
|
network.mesh.sendBroadcast( msg );
|
||||||
|
});
|
||||||
|
scheduler->addTask(someTask);
|
||||||
|
someTask.enable(); */
|
||||||
|
}
|
||||||
|
void join(){
|
||||||
|
|
||||||
|
}
|
||||||
|
void receivedCallback( uint32_t from, String &msg ) {
|
||||||
|
Serial.printf("startHere: Received from %u msg=%s\n", from, msg.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void newConnectionCallback(uint32_t nodeId) {
|
||||||
|
Serial.printf("--> startHere: New Connection, nodeId = %u\n", nodeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
void changedConnectionCallback() {
|
||||||
|
Serial.printf("Changed connections %s\n",net->mesh.subConnectionJson().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
void nodeTimeAdjustedCallback(int32_t offset) {
|
||||||
|
Serial.printf("Adjusted time %u. Offset = %d\n", net->mesh.getNodeTime(),offset);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
35
src/examples/mesh/mesh.cpp
Normal file
35
src/examples/mesh/mesh.cpp
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||||
|
#define _TASK_STD_FUNCTION
|
||||||
|
|
||||||
|
#include "Network.h"
|
||||||
|
#include "MeshNet.h"
|
||||||
|
#include "Sprocket.h"
|
||||||
|
#include "AppStack.h"
|
||||||
|
#include "MeshApp.h"
|
||||||
|
|
||||||
|
#define SERIAL_BAUD_RATE 115200
|
||||||
|
#define STARTUP_DELAY 3000
|
||||||
|
|
||||||
|
SprocketConfig config = { SERIAL_BAUD_RATE };
|
||||||
|
|
||||||
|
Sprocket sprocket;
|
||||||
|
AppStack stack;
|
||||||
|
MeshNet net;
|
||||||
|
MeshApp app;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
|
||||||
|
delay(STARTUP_DELAY);
|
||||||
|
|
||||||
|
sprocket.init(config);
|
||||||
|
sprocket.join(&net);
|
||||||
|
//sprocket.app(app);
|
||||||
|
//sprocket.use(&stack);
|
||||||
|
//stack.begin();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
sprocket.loop();
|
||||||
|
yield();
|
||||||
|
}
|
||||||
@@ -50,7 +50,7 @@ void setup() {
|
|||||||
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
|
//mesh.setDebugMsgTypes( ERROR | MESH_STATUS | CONNECTION | SYNC | COMMUNICATION | GENERAL | MSG_TYPES | REMOTE ); // all types on
|
||||||
mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see startup messages
|
mesh.setDebugMsgTypes( ERROR | STARTUP ); // set before init() so that you can see startup messages
|
||||||
|
|
||||||
mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT );
|
mesh.init( MESH_PREFIX, MESH_PASSWORD, &userScheduler, MESH_PORT, WIFI_AP_STA, 6 );
|
||||||
mesh.onReceive(&receivedCallback);
|
mesh.onReceive(&receivedCallback);
|
||||||
mesh.onNewConnection(&newConnectionCallback);
|
mesh.onNewConnection(&newConnectionCallback);
|
||||||
mesh.onChangedConnections(&changedConnectionCallback);
|
mesh.onChangedConnections(&changedConnectionCallback);
|
||||||
Reference in New Issue
Block a user