mirror of
https://github.com/markqvist/reticulum-cpp.git
synced 2024-10-01 02:55:46 -04:00
WIP: Made UDPInterface configurable
This commit is contained in:
parent
642486ac7e
commit
5443d30282
@ -39,14 +39,13 @@ UDPInterface::UDPInterface(const char* name /*= "UDPInterface"*/) : Interface(na
|
||||
|
||||
}
|
||||
|
||||
UDPInterface::UDPInterface(const char* wifi_ssid, const char* wifi_password, int local_port, const char* local_host /*=nullptr*/, const char* name /*= "UDPInterface"*/) : Interface(name),
|
||||
_local_port(local_port)
|
||||
{
|
||||
|
||||
IN(true);
|
||||
OUT(true);
|
||||
bitrate(BITRATE_GUESS);
|
||||
/*virtual*/ UDPInterface::~UDPInterface() {
|
||||
stop();
|
||||
}
|
||||
|
||||
bool UDPInterface::start(const char* wifi_ssid, const char* wifi_password, int local_port /*= DEFAULT_UDP_PORT*/, const char* local_host /*=nullptr*/) {
|
||||
online(false);
|
||||
|
||||
if (wifi_ssid != nullptr) {
|
||||
_wifi_ssid = wifi_ssid;
|
||||
}
|
||||
@ -56,16 +55,13 @@ UDPInterface::UDPInterface(const char* wifi_ssid, const char* wifi_password, int
|
||||
if (local_host != nullptr) {
|
||||
_local_host = local_host;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*virtual*/ UDPInterface::~UDPInterface() {
|
||||
stop();
|
||||
}
|
||||
|
||||
bool UDPInterface::start() {
|
||||
online(false);
|
||||
|
||||
extreme("UDPInterface: wifi ssid: " + _wifi_ssid);
|
||||
extreme("UDPInterface: wifi password: " + _wifi_password);
|
||||
extreme("UDPInterface: local host: " + _local_host);
|
||||
extreme("UDPInterface: local port: " + std::to_string(_remote_port));
|
||||
extreme("UDPInterface: remote host: " + _local_host);
|
||||
extreme("UDPInterface: remote port: " + std::to_string(_remote_port));
|
||||
|
||||
#ifdef ARDUINO
|
||||
// Connect to the WiFi network
|
||||
WiFi.begin(_wifi_ssid.c_str(), _wifi_password.c_str());
|
||||
|
@ -14,6 +14,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define DEFAULT_UDP_PORT 4242
|
||||
#define DEFAULT_UDP_LOCAL_HOST "0.0.0.0"
|
||||
#define DEFAULT_UDP_REMOTE_HOST "255.255.255.255"
|
||||
|
||||
namespace RNS { namespace Interfaces {
|
||||
|
||||
class UDPInterface : public Interface {
|
||||
@ -27,10 +31,9 @@ namespace RNS { namespace Interfaces {
|
||||
public:
|
||||
//p def __init__(self, owner, name, device=None, bindip=None, bindport=None, forwardip=None, forwardport=None):
|
||||
UDPInterface(const char* name = "UDPInterface");
|
||||
UDPInterface(const char* wifi_ssid, const char* wifi_password, int local_port, const char* local_host = nullptr, const char* name = "UDPInterface");
|
||||
virtual ~UDPInterface();
|
||||
|
||||
bool start();
|
||||
bool start(const char* wifi_ssid, const char* wifi_password, int local_port = DEFAULT_UDP_PORT, const char* local_host = nullptr);
|
||||
void stop();
|
||||
void loop();
|
||||
|
||||
@ -46,16 +49,16 @@ namespace RNS { namespace Interfaces {
|
||||
Bytes _buffer;
|
||||
|
||||
// WiFi network name and password
|
||||
std::string _wifi_ssid = "";
|
||||
std::string _wifi_password = "";
|
||||
std::string _wifi_ssid;
|
||||
std::string _wifi_password;
|
||||
|
||||
// IP address to send UDP data to.
|
||||
// it can be ip address of the server or
|
||||
// broadcast
|
||||
std::string _local_host = "0.0.0.0";
|
||||
int _local_port = 4242;
|
||||
std::string _remote_host = "255.255.255.255";
|
||||
int _remote_port = 4242;
|
||||
std::string _local_host = DEFAULT_UDP_LOCAL_HOST;
|
||||
int _local_port = DEFAULT_UDP_PORT;
|
||||
std::string _remote_host = DEFAULT_UDP_LOCAL_HOST;
|
||||
int _remote_port = DEFAULT_UDP_PORT;
|
||||
|
||||
// create UDP instance
|
||||
#ifdef ARDUINO
|
||||
|
@ -267,7 +267,7 @@ void setup_reticulum() {
|
||||
|
||||
#ifdef UDP_INTERFACE
|
||||
RNS::head("Starting UDPInterface...", RNS::LOG_EXTREME);
|
||||
udp_interface.start();
|
||||
udp_interface.start("some_ssid", "some_password");
|
||||
#endif
|
||||
|
||||
#ifdef LORA_INTERFACE
|
||||
|
Loading…
Reference in New Issue
Block a user