Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Direct node2node traffic #1174

Merged
merged 1 commit into from
Aug 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions core/MyTransport.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
Expand Down Expand Up @@ -546,10 +546,18 @@ bool transportRouteMessage(MyMessage &message)
#endif
}
#else
if (destination > GATEWAY_ADDRESS && destination < BROADCAST_ADDRESS) {
// node2node traffic: assume node is in vincinity. If transmission fails, hand over to parent
if (transportSendWrite(destination, message)) {
TRANSPORT_DEBUG(PSTR("TSF:RTE:N2N OK\n"));
return true;
}
TRANSPORT_DEBUG(PSTR("!TSF:RTE:N2N FAIL\n"));
}
route = _transportConfig.parentNodeId; // not a repeater, all traffic routed via parent
#endif
}
// send message, HAL
// send message
const bool result = transportSendWrite(route, message);
#if !defined(MY_GATEWAY_FEATURE)
// update counter
Expand Down
2 changes: 2 additions & 0 deletions core/MyTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@
* | | TSF | SRT | OK | Saving routing table successful
* |!| TSF | RTE | FPAR ACTIVE | Finding parent active, message not sent
* |!| TSF | RTE | DST %%d UNKNOWN | Routing for destination (DST) unknown, send message to parent
* | | TSF | RTE | N2N OK | Node-to-node communication succeeded
* |!| TSF | RTE | N2N FAIL | Node-to-node communication failed, handing over to parent for re-routing
* | | TSF | RRT | ROUTE N=%%d,R=%%d | Routing table, messages to node (N) are routed via node (R)
* |!| TSF | SND | TNR | Transport not ready, message cannot be sent
* | | TSF | TDI | TSL | Set transport to sleep
Expand Down
68 changes: 68 additions & 0 deletions examples/Node2Node/Node2Node.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
The MySensors Arduino library handles the wireless radio link and protocol
between your home built sensors/actuators and HA controller of choice.
The sensors forms a self healing radio network with optional repeaters. Each
repeater and gateway builds a routing tables in EEPROM which keeps track of the
network topology allowing messages to be routed to nodes.

Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
Copyright (C) 2013-2018 Sensnology AB
Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors

Documentation: http://www.mysensors.org
Support Forum: http://forum.mysensors.org

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.

*/

#define MY_DEBUG
#define MY_RADIO_RF24
#define CHILD_SENSOR_ID 0
#define ACTUATOR_ID 200
//#define SIGNING_ENABLED // enable for secure actuator

#if defined(SIGNING_ENABLED)
// Signing, select soft/hardware signing method
#define MY_SIGNING_SOFT
//#define MY_SIGNING_ATSHA204
#define MY_DEBUG_VERBOSE_SIGNING
// Enable this if you want destination node to sign all messages sent to this node.
//#define MY_SIGNING_REQUEST_SIGNATURES
#endif

// triggering interval
static const uint32_t trigger_ms = 10000;

#include "MySensors.h"
MyMessage msgGeneral(CHILD_SENSOR_ID, V_STATUS);
uint32_t lastTrigger = 0;
bool actuatorStatus = false;

void presentation(void)
{
sendSketchInfo("Node2Node", __DATE__);
present(CHILD_SENSOR_ID, S_BINARY, "Remote");
}

void setup()
{
#if defined(SIGNING_ENABLED)
SET_SIGN(ACTUATOR_ID); // define signing requirements for remote node
#endif
}

void loop()
{
if (millis() - lastTrigger > trigger_ms) {
lastTrigger = millis();
// set destination address
msgGeneral.setDestination(ACTUATOR_ID);
// send message to node
send(msgGeneral.set(actuatorStatus));
// invert status
actuatorStatus ^= true;
}
}