-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples: rename existing, add example for local broker bridge
- Loading branch information
Showing
18 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# SPSP bridge example | ||
|
||
Simple example of how to integrate SPSP framework into ESP-IDF and create | ||
*bridge* node. | ||
|
||
Uses ESP-NOW as *local layer* and [local broker](/#local-broker-far-layer) as *far layer*. |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include "spsp.hpp" | ||
|
||
extern "C" void app_main() | ||
{ | ||
/** | ||
* Config | ||
*/ | ||
|
||
// ESPNOW config | ||
SPSP::LocalLayers::ESPNOW::Config espnowConfig = {}; | ||
espnowConfig.ssid = 0x00000000; | ||
espnowConfig.password = "12345678123456781234567812345678"; | ||
|
||
|
||
/** | ||
* Init | ||
*/ | ||
|
||
// Initialize WiFi | ||
static SPSP::WiFi::Station wifi{{}}; | ||
|
||
// Set WiFi channel | ||
// | ||
// As we use `LocalBroker` far layer, we don't need IP connectivity at all | ||
// and thus WiFi will be used purely by ESP-NOW to receive and send data | ||
// to clients. | ||
// We can set any WiFi channel we want (allowed by local law) and clients | ||
// will discover this bridge automatically. | ||
// | ||
// Remember, however, to use `wifi.setChannelRestrictions(...)` method on | ||
// both bridge and client, if you intend to use channels 12 or 13. | ||
wifi.setChannel(7); | ||
|
||
// Create layers | ||
static SPSP::LocalLayers::ESPNOW::Adapter llAdapter{}; | ||
static SPSP::LocalLayers::ESPNOW::ESPNOW ll{llAdapter, wifi, espnowConfig}; | ||
static SPSP::FarLayers::LocalBroker::LocalBroker fl{}; | ||
|
||
// Create bridge | ||
static SPSP::Nodes::Bridge spsp{&ll, &fl}; | ||
|
||
/** | ||
* Publish and subscribe | ||
* API is the same as for the client. | ||
* Typically, you publish and subscribe on clients only, | ||
* but you can do the same on bridges too. | ||
*/ | ||
|
||
bool delivered = spsp.publish("topic", "payload"); | ||
|
||
if (delivered) { | ||
// ... | ||
} else { | ||
// ... | ||
} | ||
|
||
delivered = spsp.subscribe( | ||
"topic2", | ||
[](const std::string& topic, const std::string& payload) { | ||
// Do something when data on `topic2` are received | ||
// ... | ||
} | ||
); | ||
|
||
// We don't need this subscription anymore | ||
delivered = spsp.unsubscribe("topic2"); | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
|
||
project(spsp_bridge_example) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
idf_component_register(SRCS "main.cpp" | ||
INCLUDE_DIRS ".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dependencies: | ||
spsp: | ||
git: https://github.com/DavidB137/spsp.git |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y | ||
CONFIG_COMPILER_CXX_EXCEPTIONS=y |