mirror of
https://gitlab.com/wirelos/sprocket-lib.git
synced 2025-12-17 05:36:39 +01:00
cleanup build, examples and library
This commit is contained in:
38
src/firmware/BaseSprocket.h
Normal file
38
src/firmware/BaseSprocket.h
Normal file
@@ -0,0 +1,38 @@
|
||||
#ifndef __BASE_SPROCKET__
|
||||
#define __BASE_SPROCKET__
|
||||
|
||||
#include <ESPAsyncWebServer.h>
|
||||
#include <Sprocket.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace std::placeholders;
|
||||
|
||||
// TODO remove someTask and replace with OTA stuff
|
||||
class BaseSprocket : public Sprocket {
|
||||
public:
|
||||
Task someTask;
|
||||
MeshNet* net;
|
||||
BaseSprocket(SprocketConfig cfg) : Sprocket(cfg) {
|
||||
|
||||
}
|
||||
Sprocket* activate(Scheduler* scheduler, Network* network) {
|
||||
net = static_cast<MeshNet*>(network);
|
||||
net->mesh.onReceive(bind(&BaseSprocket::receivedCallback,this, _1, _2));
|
||||
// add a task that sends stuff to the mesh
|
||||
someTask.set(TASK_SECOND * 5, TASK_FOREVER,
|
||||
bind(&BaseSprocket::heartbeat, this, net));
|
||||
scheduler->addTask(someTask);
|
||||
someTask.enable();
|
||||
} using Sprocket::activate;
|
||||
|
||||
void heartbeat(MeshNet* network){
|
||||
String msg = "{ \"alive \": 1 }";
|
||||
network->broadcast(msg);
|
||||
}
|
||||
|
||||
virtual void receivedCallback( uint32_t from, String &msg ) {
|
||||
Serial.printf("RECV %u = %s\n", from, msg.c_str());
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
28
src/firmware/config.h
Normal file
28
src/firmware/config.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef __BRIDGE_CONFIG__
|
||||
#define __BRIDGE_CONFIG__
|
||||
|
||||
// Scheduler config
|
||||
#define _TASK_SLEEP_ON_IDLE_RUN
|
||||
#define _TASK_STD_FUNCTION
|
||||
|
||||
// Chip config
|
||||
#define SERIAL_BAUD_RATE 115200
|
||||
#define STARTUP_DELAY 3000
|
||||
|
||||
// Mesh config
|
||||
#define STATION_MODE 0 // 1 = connect to AP using STATION params
|
||||
#define WIFI_CHANNEL 11
|
||||
#define MESH_PORT 5555
|
||||
#define MESH_PREFIX "wirelos_contraption"
|
||||
#define MESH_PASSWORD "th3r31sn0sp00n"
|
||||
#define STATION_SSID "Th1ngs4P"
|
||||
#define STATION_PASSWORD "th3r31sn0sp00n"
|
||||
#define HOSTNAME "sprocket"
|
||||
#define MESH_DEBUG_TYPES ERROR | STARTUP | CONNECTION
|
||||
|
||||
#define MQTT_CLIENT_NAME HOSTNAME
|
||||
#define MQTT_BROKER "citadel.lan"
|
||||
#define MQTT_PORT 1883
|
||||
#define MQTT_TOPIC_ROOT "mesh"
|
||||
|
||||
#endif
|
||||
23
src/firmware/main.cpp
Normal file
23
src/firmware/main.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "config.h"
|
||||
#include "MeshNet.h"
|
||||
#include "BaseSprocket.h"
|
||||
|
||||
MeshNet net({
|
||||
STATION_MODE, WIFI_CHANNEL,
|
||||
MESH_PORT, MESH_PREFIX, MESH_PASSWORD,
|
||||
STATION_SSID, STATION_PASSWORD, HOSTNAME,
|
||||
MESH_DEBUG_TYPES
|
||||
});
|
||||
|
||||
BaseSprocket sprocket(
|
||||
{ STARTUP_DELAY, SERIAL_BAUD_RATE }
|
||||
);
|
||||
|
||||
void setup() {
|
||||
sprocket.join(net);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
sprocket.loop();
|
||||
yield();
|
||||
}
|
||||
Reference in New Issue
Block a user