-
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.
- Loading branch information
Showing
10 changed files
with
230 additions
and
22 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
.. include:: /include/include.rst | ||
:orphan: | ||
|
||
Documentation | ||
|
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
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,44 @@ | ||
.. meta:: | ||
:keywords: DCC-EX DCC DCC++ EX DCC++EX | ||
.. | ||
.. |DCC-EX| raw:: html | ||
|
||
<span class="dccex-suffix">DCC-</span><span class="dccex-prefix">EX</span> | ||
.. | ||
.. |EX-CS| raw:: html | ||
|
||
<span class="ex-prefix">EX</span><span class="ex-suffix">‑CommandStation</span> | ||
.. | ||
.. |EX-PL| raw:: html | ||
|
||
<span class="ex-prefix">DCCEX</span><span class="ex-suffix">Protocol library</span> | ||
.. | ||
.. |EX-NP| raw:: html | ||
|
||
<span class="dccex-suffix">DCC-</span><span class="dccex-prefix">EX</span> | ||
<span class="ex-suffix"> native protocol</span> | ||
.. | ||
.. |br| raw:: html | ||
|
||
<br /> | ||
.. | ||
.. role:: dcc-ex-red | ||
.. role:: dcc-ex-red-bold | ||
.. role:: dcc-ex-red-bold-italic | ||
.. role:: dcc-ex-code | ||
.. | ||
.. role:: dcc-ex-text-size-80pct | ||
.. role:: dcc-ex-text-size-60pct | ||
.. role:: dcc-ex-text-size-200pct | ||
.. | ||
.. |_| unicode:: 0xA0 | ||
:trim: | ||
.. | ||
.. |force-break| raw:: html | ||
|
||
<div style="display:block; box-sizing: border-box; clear: both;"> </div> | ||
.. | ||
.. |image-note| raw:: html | ||
|
||
<span style="font-weight: bold; font-style: italic; color: #767676;" >Note that you can click on any of the images to make them larger.</span> | ||
.. |
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
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 |
---|---|---|
@@ -1,11 +1,5 @@ | ||
Library | ||
======= | ||
|
||
.. sidebar:: | ||
|
||
.. contents:: On this page | ||
:depth: 2 | ||
:local: | ||
|
||
.. doxygenindex:: | ||
:project: DCCEXProtocol |
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
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.. include:: /include/include.rst | ||
|
||
Indices and tables | ||
================== | ||
|
||
|
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
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,137 @@ | ||
// WiThrottleProtocol library: mDNS example | ||
// | ||
// Shows how to retrieve the list of discovered servers | ||
// Tested with ESP32-WROOM board | ||
// | ||
// Peter Akers (Flash62au), Peter Cole (PeteGSX) and Chris Harlow (UKBloke), 2023 | ||
|
||
|
||
#include <ESPmDNS.h> | ||
#include <WiFi.h> | ||
|
||
// If we haven't got a custom config.h, use the example | ||
#if __has_include ("config.h") | ||
#include "config.h" | ||
#else | ||
#warning config.h not found. Using defaults from config.example.h | ||
#include "config.example.h" | ||
#endif | ||
|
||
void printMdnsServers(); | ||
|
||
|
||
#define MAX_SERVERS 20 | ||
|
||
IPAddress foundWitServersIPs[MAX_SERVERS]; | ||
int foundWitServersPorts[MAX_SERVERS]; | ||
String foundWitServersNames[MAX_SERVERS]; | ||
int foundWitServersCount; | ||
|
||
unsigned long lastTime = 0; | ||
|
||
bool mdnsListenerStarted = false; | ||
|
||
// Global objects | ||
WiFiClient client; | ||
|
||
bool setupMdnsListner() { | ||
// setup the bonjour listener | ||
|
||
if (!MDNS.begin("mDNSTest")) { | ||
Serial.println("Error setting up MDNS responder!"); | ||
return false; | ||
} else { | ||
Serial.println("MDNS responder started"); | ||
return true; | ||
} | ||
} | ||
|
||
void printMdnsServers() { | ||
Serial.println(""); | ||
|
||
double startTime = millis(); | ||
double nowTime = startTime; | ||
|
||
const char * service = "withrottle"; | ||
const char * proto= "tcp"; | ||
|
||
Serial.print("Browsing for service "); Serial.print(service); Serial.print("."); Serial.print(proto); Serial.print(".local. on "); Serial.print(ssid); Serial.println(" ... "); | ||
|
||
int noOfWitServices = 0; | ||
while ( (noOfWitServices == 0) && ((nowTime-startTime) <= 5000) ) { // try for 5 seconds | ||
noOfWitServices = MDNS.queryService(service, proto); | ||
if (noOfWitServices == 0 ) { | ||
delay(500); | ||
Serial.print("."); | ||
} | ||
nowTime = millis(); | ||
} | ||
Serial.println(""); | ||
|
||
if (noOfWitServices > 0) { | ||
for (int i = 0; ((i < noOfWitServices) && (i<MAX_SERVERS)); ++i) { | ||
foundWitServersNames[i] = MDNS.hostname(i); | ||
foundWitServersIPs[i] = MDNS.IP(i); | ||
foundWitServersPorts[i] = MDNS.port(i); | ||
if (MDNS.hasTxt(i,"jmri")) { | ||
String node = MDNS.txt(i,"node"); | ||
node.toLowerCase(); | ||
if (foundWitServersNames[i].equals(node)) { | ||
foundWitServersNames[i] = "JMRI (v" + MDNS.txt(i,"jmri") + ")"; | ||
} | ||
} | ||
} | ||
} | ||
foundWitServersCount = noOfWitServices; | ||
|
||
// EX-CommnadStations in Access Point mode cannot advertise via mDNS, | ||
// so we have to guess it based on the SSID name | ||
String ssidString = String(ssid); | ||
if (ssidString == "DCCEX_") { | ||
foundWitServersIPs[foundWitServersCount].fromString("192.168.4.1"); | ||
foundWitServersPorts[foundWitServersCount] = 2560; | ||
foundWitServersNames[foundWitServersCount] = "'Guessed' EX-CS WiT server"; | ||
foundWitServersCount++; | ||
} | ||
|
||
for (int i = 0; ((i < foundWitServersCount) && (i<MAX_SERVERS)); ++i) { | ||
Serial.print("Name: "); Serial.print(foundWitServersNames[i]); | ||
Serial.print(" IP: "); Serial.print(foundWitServersIPs[i]); | ||
Serial.print(" : "); Serial.print(foundWitServersPorts[i]); | ||
Serial.println(); | ||
} | ||
} | ||
|
||
void setup() { | ||
|
||
Serial.begin(115200); | ||
Serial.println("DCCEXProtocol mDNS example"); | ||
Serial.println(); | ||
|
||
// Connect to WiFi network | ||
Serial.println("Connecting to WiFi.."); | ||
WiFi.begin(ssid, password); | ||
while(WiFi.status() != WL_CONNECTED) delay(1000); | ||
Serial.print("Connected with IP: "); Serial.println(WiFi.localIP()); | ||
Serial.println(); | ||
|
||
// setup the mDNS listner | ||
mdnsListenerStarted = setupMdnsListner(); | ||
|
||
// browse for services | ||
if (mdnsListenerStarted) { | ||
printMdnsServers(); | ||
} | ||
|
||
} | ||
|
||
void loop() { | ||
|
||
delay(20000); | ||
// Redo every 20 seconds - For demonstration purposes only! | ||
// Normally this will only be required once, immediately after you connect to the ssid. | ||
if (mdnsListenerStarted) { | ||
printMdnsServers(); | ||
} | ||
|
||
} |
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,7 @@ | ||
// Example user configuration to use with the DCCEXProtocol examples | ||
// Copy this file and rename to config.h | ||
// Replace the variables below with the appropriate values for your environment | ||
const char* ssid = "YOUR_SSID_HERE"; // WiFi SSID name here | ||
const char* password = "YOUR_PASSWORD_HERE"; // WiFi password here | ||
IPAddress serverAddress(192,168,4,1); // IP address of your EX-CommandStation | ||
int serverPort = 2560; // Network port of your EX-CommandStation |