Fix UDP on Ethernet gateway (#858)

- Fix UDP send
- Add a default value for MY_IP_GATEWAY_ADDRESS and
  MY_IP_SUBNET_ADDRESS, making them optional when using MY_IP_ADDRESS
- Add support for MY_IP_GATEWAY_ADDRESS and MY_IP_SUBNET_ADDRESS to
  W5100
This commit is contained in:
Marcelo Aquino
2017-06-13 22:59:01 +02:00
committed by Henrik Ekblad
parent 4820475e5c
commit 95d7c003cb
7 changed files with 181 additions and 154 deletions
+17 -19
View File
@@ -65,7 +65,6 @@
* Make sure to fill in your ssid and WiFi password below for ssid & pass.
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
@@ -82,18 +81,18 @@
#define MY_ESP8266_PASSWORD "MyVerySecretPassword"
// Enable UDP communication
//#define MY_USE_UDP
//#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
// Set the hostname for the WiFi Client. This is the hostname
// it will pass to the DHCP server if not static.
// #define MY_ESP8266_HOSTNAME "sensor-gateway"
//#define MY_ESP8266_HOSTNAME "sensor-gateway"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
//#define MY_IP_ADDRESS 192,168,178,87
// If using static ip you need to define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// If using static ip you can define Gateway and Subnet address as well
//#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// The port to keep open on node server mode
#define MY_PORT 5003
@@ -106,44 +105,43 @@
//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
//#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
// #define MY_INCLUSION_BUTTON_FEATURE
//#define MY_INCLUSION_BUTTON_FEATURE
// Set inclusion mode duration (in seconds)
#define MY_INCLUSION_MODE_DURATION 60
//#define MY_INCLUSION_MODE_DURATION 60
// Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
//#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
// Led pins used if blinking feature is enabled above
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
//#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
//#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
//#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
#if defined(MY_USE_UDP)
#include <WiFiUdp.h>
#endif
#include <ESP8266WiFi.h>
#include <MySensors.h>
void setup()
{
// Setup locally attached sensors
}
void presentation()
{
// Present locally attached sensors here
// Present locally attached sensors here
}
void loop()
{
// Send locally attached sensors data here
// Send locally attached sensors data here
}
@@ -57,7 +57,6 @@
* Make sure to fill in your ssid and WiFi password below for ssid & pass.
*/
// Enable debug prints to serial monitor
#define MY_DEBUG
@@ -91,12 +90,11 @@
// #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway"
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,178,87
// If using static ip you need to define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
//#define MY_IP_ADDRESS 192,168,178,87
// If using static ip you can define Gateway and Subnet address as well
//#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// MQTT broker ip address.
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
@@ -104,39 +102,38 @@
// The MQTT broker port to to open
#define MY_PORT 1883
/*
// Enable inclusion mode
#define MY_INCLUSION_MODE_FEATURE
//#define MY_INCLUSION_MODE_FEATURE
// Enable Inclusion mode button on gateway
#define MY_INCLUSION_BUTTON_FEATURE
//#define MY_INCLUSION_BUTTON_FEATURE
// Set inclusion mode duration (in seconds)
#define MY_INCLUSION_MODE_DURATION 60
//#define MY_INCLUSION_MODE_DURATION 60
// Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
#define MY_DEFAULT_LED_BLINK_PERIOD 300
//#define MY_DEFAULT_LED_BLINK_PERIOD 300
// Flash leds on rx/tx/err
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
*/
//#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
//#define MY_DEFAULT_RX_LED_PIN 16 // Receive led pin
//#define MY_DEFAULT_TX_LED_PIN 16 // the PCB, on board LED
#include <ESP8266WiFi.h>
#include <MySensors.h>
void setup()
{
// Setup locally attached sensors
}
void presentation()
{
// Present locally attached sensors here
// Present locally attached sensors here
}
void loop()
{
// Send locally attech sensors data here
// Send locally attech sensors data here
}
@@ -88,14 +88,14 @@
// #define MY_ESP8266_HOSTNAME "sensor-ota-gateway"
// Enable UDP communication
//#define MY_USE_UDP
//#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
//#define MY_IP_ADDRESS 192,168,178,87
// If using static ip you need to define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// If using static ip you can define Gateway and Subnet address as well
//#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// The port to keep open on node server mode
#define MY_PORT 5003
@@ -117,7 +117,6 @@
// Digital pin used for inclusion mode button
#define MY_INCLUSION_MODE_BUTTON_PIN 3
// Set blinking period
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
@@ -137,45 +136,41 @@
void setup()
{
// Setup locally attached sensors
ArduinoOTA.onStart([]() {
Serial.println("ArduinoOTA start");
debug("ArduinoOTA start\n");
});
ArduinoOTA.onEnd([]() {
Serial.println("\nArduinoOTA end");
debug("\nArduinoOTA end\n");
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
Serial.printf("OTA Progress: %u%%\r", (progress / (total / 100)));
debug("OTA Progress: %u%%\r", (progress / (total / 100)));
});
ArduinoOTA.onError([](ota_error_t error) {
Serial.printf("Error[%u]: ", error);
debug("Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) {
Serial.println("Auth Failed");
debug("Auth Failed\n");
} else if (error == OTA_BEGIN_ERROR) {
Serial.println("Begin Failed");
debug("Begin Failed\n");
} else if (error == OTA_CONNECT_ERROR) {
Serial.println("Connect Failed");
debug("Connect Failed\n");
} else if (error == OTA_RECEIVE_ERROR) {
Serial.println("Receive Failed");
debug("Receive Failed\n");
} else if (error == OTA_END_ERROR) {
Serial.println("End Failed");
debug("End Failed\n");
}
});
ArduinoOTA.begin();
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
void presentation()
{
// Present locally attached sensors here
// Present locally attached sensors here
}
void loop()
{
// Send locally attech sensors data here
// Send locally attech sensors data here
ArduinoOTA.handle();
}
+18 -5
View File
@@ -72,12 +72,19 @@
#define MY_RF24_CS_PIN 6
#endif
// Enable to UDP
//#define MY_USE_UDP
// Enable UDP communication
//#define MY_USE_UDP // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS below
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,178,66
// If using static ip you can define Gateway and Subnet address as well
//#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
#define MY_IP_ADDRESS 192,168,178,66 // If this is disabled, DHCP is used to retrieve address
// Renewal period if using DHCP
//#define MY_IP_RENEWAL_INTERVAL 60000
// The port to keep open on node server mode / or port to contact in client mode
#define MY_PORT 5003
@@ -108,18 +115,24 @@
//#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
//#define MY_DEFAULT_TX_LED_PIN 9 // Transmit led pin
#if defined(MY_USE_UDP)
#include <EthernetUdp.h>
#endif
#include <Ethernet.h>
#include <MySensors.h>
void setup()
{
// Setup locally attached sensors
}
void presentation()
{
// Present locally attached sensors here
}
void loop()
{
// Send locally attached sensors data here
}
@@ -102,9 +102,9 @@
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
#define MY_IP_ADDRESS 192,168,178,87
// If using static ip you need to define Gateway and Subnet address as well
#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// If using static ip you can define Gateway and Subnet address as well
//#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
// MQTT broker ip address or url. Define one or the other.
//#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
@@ -138,15 +138,16 @@
void setup()
{
// Setup locally attached sensors
}
void presentation()
{
// Present locally attached sensors here
// Present locally attached sensors here
}
void loop()
{
// Send locally attached sensors data here
// Send locally attached sensors data here
}