fix basic example

This commit is contained in:
2018-06-09 18:56:59 +02:00
parent c51183b093
commit e9a04ac827
12 changed files with 232 additions and 38 deletions

35
.gitlab-ci.yml Normal file
View 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

View File

@@ -9,12 +9,11 @@
; http://docs.platformio.org/page/projectconf.html
[platformio]
env_default = mesh
env_default = basic
[common]
framework = arduino
lib_deps =
ESPAsyncWifiManager
ESP Async WebServer
ESPAsyncTCP
TaskScheduler
@@ -34,6 +33,17 @@ lib_deps = ${common.lib_deps}
;upload_port = /dev/ttyUSB0
;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]
src_filter = +<*> +<examples/mesh/> -<examples/basic/>
platform = espressif8266

View File

@@ -2,27 +2,15 @@
#define _APP_H_
#include <TaskSchedulerDeclarations.h>
//#include "Sprocket.h"
#include "Sprocket.h"
#include "AppStack.h"
/* template <class T>
class App {
private:
T* stack;
public:
App();
App(T* stack);
};
*/
#include "Network.h"
class App {
protected:
//Sprocket* sprocket;
public:
/* App(Sprocket* sprkt){
sprocket = sprkt;
} */
virtual void activate(Scheduler* scheduler);
virtual void join(Network& network) {};
virtual void activate(Scheduler* scheduler, Network* network) {};
virtual void activate(Scheduler* scheduler) {};
};
#endif

View File

@@ -1,10 +1,56 @@
#ifndef __MESHNET_H__
#define __MESHNET_H__
#include <painlessMesh.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

View File

@@ -1,10 +1,20 @@
#ifndef __NETWORK_H__
#define __NETWORK_H__
#include <TaskSchedulerDeclarations.h>
class Network {
protected:
Scheduler* scheduler;
public:
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

View File

@@ -9,7 +9,15 @@ Sprocket* Sprocket::init(SprocketConfig cfg){
SPIFFS.begin();
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){
stack = stk;
return this;
@@ -21,12 +29,15 @@ Sprocket* Sprocket::addTask(Task& tsk){
return this;
}
Sprocket* Sprocket::registerApp(App& app){
Sprocket* Sprocket::app(App& app){
//app.join(&network);
//app.activate(&scheduler, network);
app.activate(&scheduler);
return this;
}
void Sprocket::loop(){
//network->update();
scheduler.execute();
//stack->loop();
}

View File

@@ -5,9 +5,9 @@
#include <TaskSchedulerDeclarations.h>
#include <Arduino.h>
#include "WiFiNet.h"
#include "AppStack.h"
#include "App.h"
#include "Network.h"
struct SprocketConfig {
int serialBaudRate;
@@ -17,12 +17,14 @@ class Sprocket {
private:
AppStack* stack;
Scheduler scheduler;
Network* network;
public:
Sprocket();
Sprocket* init(SprocketConfig);
Sprocket* join(Network&);
Sprocket* use(AppStack*);
Sprocket* addTask(Task&);
Sprocket* registerApp(App&);
Sprocket* app(App&);
void loop();
};

View File

@@ -29,7 +29,8 @@ class WiFiNet : public Network {
server = stack->server;
return this;
}
WiFiNet* connect(){
WiFiNet* init(){}
WiFiNet* connect(){
server = new AsyncWebServer(80);
dns = new DNSServer();
wifiManager = new AsyncWiFiManager(server, dns);

View File

@@ -4,7 +4,7 @@
#include <TaskScheduler.h>
#include "Sprocket.h"
#include "AppStack.h"
//#include "WiFiNet.h"
#include "WiFiNet.h"
#include "ExampleApp.h"
@@ -13,9 +13,9 @@
SprocketConfig config = { SERIAL_BAUD_RATE };
Sprocket sprocket;
AppStack stack;
WiFiNet net;
Sprocket sprocket;
//AppStack stack;
ExampleApp app;
@@ -23,20 +23,17 @@ void setup() {
delay(STARTUP_DELAY);
Serial.println("setup");
//sprocket.use(&stack);
sprocket.init(config);
sprocket.registerApp(app);
sprocket.app(app);
sprocket.join(net);
net.connect();
//net.connect();
//stack.begin();
}
void loop() {
sprocket.loop();
net.update();
yield();
}

View 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

View 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();
}

View File

@@ -50,7 +50,7 @@ void setup() {
//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.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.onNewConnection(&newConnectionCallback);
mesh.onChangedConnections(&changedConnectionCallback);
@@ -63,4 +63,4 @@ void setup() {
void loop() {
userScheduler.execute(); // it will run mesh scheduler as well
mesh.update();
}
}