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:
committed by
Henrik Ekblad
parent
4820475e5c
commit
95d7c003cb
@@ -28,7 +28,20 @@ IPAddress _ethernetControllerIP(MY_CONTROLLER_IP_ADDRESS);
|
|||||||
|
|
||||||
#if defined(MY_IP_ADDRESS)
|
#if defined(MY_IP_ADDRESS)
|
||||||
IPAddress _ethernetGatewayIP(MY_IP_ADDRESS);
|
IPAddress _ethernetGatewayIP(MY_IP_ADDRESS);
|
||||||
#endif
|
#if defined(MY_IP_GATEWAY_ADDRESS)
|
||||||
|
IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS);
|
||||||
|
#elif defined(MY_GATEWAY_ESP8266) /* Elif part of MY_IP_GATEWAY_ADDRESS */
|
||||||
|
// Assume the gateway will be the machine on the same network as the local IP
|
||||||
|
// but with last octet being '1'
|
||||||
|
IPAddress _gatewayIp(_ethernetGatewayIP[0], _ethernetGatewayIP[1], _ethernetGatewayIP[2], 1);
|
||||||
|
#endif /* End of MY_IP_GATEWAY_ADDRESS */
|
||||||
|
#if defined(MY_IP_SUBNET_ADDRESS)
|
||||||
|
IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS);
|
||||||
|
#elif defined(MY_GATEWAY_ESP8266) /* Elif part of MY_IP_SUBNET_ADDRESS */
|
||||||
|
IPAddress _subnetIp(255, 255, 255, 0);
|
||||||
|
#endif /* End of MY_IP_SUBNET_ADDRESS */
|
||||||
|
#endif /* End of MY_IP_ADDRESS */
|
||||||
|
|
||||||
uint8_t _ethernetGatewayMAC[] = { MY_MAC_ADDRESS };
|
uint8_t _ethernetGatewayMAC[] = { MY_MAC_ADDRESS };
|
||||||
uint16_t _ethernetGatewayPort = MY_PORT;
|
uint16_t _ethernetGatewayPort = MY_PORT;
|
||||||
MyMessage _ethernetMsg;
|
MyMessage _ethernetMsg;
|
||||||
@@ -45,34 +58,33 @@ typedef struct {
|
|||||||
#define EthernetServer WiFiServer
|
#define EthernetServer WiFiServer
|
||||||
#define EthernetClient WiFiClient
|
#define EthernetClient WiFiClient
|
||||||
#define EthernetUDP WiFiUDP
|
#define EthernetUDP WiFiUDP
|
||||||
|
#endif /* End of MY_GATEWAY_ESP8266 */
|
||||||
|
|
||||||
#if defined(MY_IP_ADDRESS)
|
#if defined(MY_GATEWAY_CLIENT_MODE)
|
||||||
IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS);
|
|
||||||
IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(MY_USE_UDP)
|
#if defined(MY_USE_UDP)
|
||||||
EthernetUDP _ethernetServer;
|
EthernetUDP _ethernetServer;
|
||||||
#elif defined(MY_GATEWAY_LINUX)
|
#endif /* End of MY_USE_UDP */
|
||||||
|
#elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_CLIENT_MODE */
|
||||||
EthernetServer _ethernetServer(_ethernetGatewayPort, MY_GATEWAY_MAX_CLIENTS);
|
EthernetServer _ethernetServer(_ethernetGatewayPort, MY_GATEWAY_MAX_CLIENTS);
|
||||||
#elif defined(MY_GATEWAY_CLIENT_MODE)
|
#else /* Else part of MY_GATEWAY_CLIENT_MODE */
|
||||||
// Nothing to do here
|
|
||||||
#else
|
|
||||||
EthernetServer _ethernetServer(_ethernetGatewayPort);
|
EthernetServer _ethernetServer(_ethernetGatewayPort);
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_CLIENT_MODE */
|
||||||
|
|
||||||
#if defined(MY_GATEWAY_CLIENT_MODE)
|
#if defined(MY_GATEWAY_CLIENT_MODE)
|
||||||
static EthernetClient client = EthernetClient();
|
|
||||||
static inputBuffer inputString;
|
static inputBuffer inputString;
|
||||||
#elif defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)
|
#if defined(MY_USE_UDP)
|
||||||
|
// Nothing to do here
|
||||||
|
#else
|
||||||
|
static EthernetClient client = EthernetClient();
|
||||||
|
#endif /* End of MY_USE_UDP */
|
||||||
|
#elif defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_CLIENT_MODE */
|
||||||
static EthernetClient clients[MY_GATEWAY_MAX_CLIENTS];
|
static EthernetClient clients[MY_GATEWAY_MAX_CLIENTS];
|
||||||
static bool clientsConnected[MY_GATEWAY_MAX_CLIENTS];
|
static bool clientsConnected[MY_GATEWAY_MAX_CLIENTS];
|
||||||
static inputBuffer inputString[MY_GATEWAY_MAX_CLIENTS];
|
static inputBuffer inputString[MY_GATEWAY_MAX_CLIENTS];
|
||||||
#else
|
#else /* Else part of MY_GATEWAY_CLIENT_MODE */
|
||||||
static EthernetClient client = EthernetClient();
|
static EthernetClient client = EthernetClient();
|
||||||
static inputBuffer inputString;
|
static inputBuffer inputString;
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_CLIENT_MODE */
|
||||||
|
|
||||||
#ifndef MY_IP_ADDRESS
|
#ifndef MY_IP_ADDRESS
|
||||||
void gatewayTransportRenewIP();
|
void gatewayTransportRenewIP();
|
||||||
@@ -80,7 +92,7 @@ void gatewayTransportRenewIP();
|
|||||||
|
|
||||||
// On W5100 boards with SPI_EN exposed we can use the real SPI bus together with radio
|
// On W5100 boards with SPI_EN exposed we can use the real SPI bus together with radio
|
||||||
// (if we enable it during usage)
|
// (if we enable it during usage)
|
||||||
#ifdef MY_W5100_SPI_EN
|
#if defined(MY_W5100_SPI_EN)
|
||||||
void _w5100_spi_en(bool enable)
|
void _w5100_spi_en(bool enable)
|
||||||
{
|
{
|
||||||
if (enable) {
|
if (enable) {
|
||||||
@@ -103,13 +115,13 @@ bool gatewayTransportInit(void)
|
|||||||
#if defined(MY_GATEWAY_ESP8266)
|
#if defined(MY_GATEWAY_ESP8266)
|
||||||
#if defined(MY_ESP8266_SSID)
|
#if defined(MY_ESP8266_SSID)
|
||||||
// Turn off access point
|
// Turn off access point
|
||||||
WiFi.mode (WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
#if defined(MY_ESP8266_HOSTNAME)
|
#if defined(MY_ESP8266_HOSTNAME)
|
||||||
WiFi.hostname(MY_ESP8266_HOSTNAME);
|
WiFi.hostname(MY_ESP8266_HOSTNAME);
|
||||||
#endif
|
#endif /* End of MY_ESP8266_HOSTNAME */
|
||||||
#ifdef MY_IP_ADDRESS
|
#if defined(MY_IP_ADDRESS)
|
||||||
WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp);
|
WiFi.config(_ethernetGatewayIP, _gatewayIp, _subnetIp);
|
||||||
#endif
|
#endif /* End of MY_IP_ADDRESS */
|
||||||
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD);
|
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD);
|
||||||
while (WiFi.status() != WL_CONNECTED) {
|
while (WiFi.status() != WL_CONNECTED) {
|
||||||
wait(500);
|
wait(500);
|
||||||
@@ -117,35 +129,41 @@ bool gatewayTransportInit(void)
|
|||||||
}
|
}
|
||||||
MY_SERIALDEVICE.print(F("IP: "));
|
MY_SERIALDEVICE.print(F("IP: "));
|
||||||
MY_SERIALDEVICE.println(WiFi.localIP());
|
MY_SERIALDEVICE.println(WiFi.localIP());
|
||||||
#endif
|
#endif /* End of MY_ESP8266_SSID */
|
||||||
#elif defined(MY_GATEWAY_LINUX)
|
#elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_ESP8266 */
|
||||||
// Nothing to do here
|
// Nothing to do here
|
||||||
#else
|
#else /* Else part of MY_GATEWAY_ESP8266 */
|
||||||
#ifdef MY_IP_ADDRESS
|
#if defined(MY_IP_GATEWAY_ADDRESS) && defined(MY_IP_SUBNET_ADDRESS)
|
||||||
|
// DNS server set to gateway ip
|
||||||
|
Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP, _gatewayIp, _gatewayIp, _subnetIp);
|
||||||
|
#elif defined(MY_IP_ADDRESS)
|
||||||
Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP);
|
Ethernet.begin(_ethernetGatewayMAC, _ethernetGatewayIP);
|
||||||
#else
|
#else /* Else part of MY_IP_GATEWAY_ADDRESS && MY_IP_SUBNET_ADDRESS */
|
||||||
// Get IP address from DHCP
|
// Get IP address from DHCP
|
||||||
if (!Ethernet.begin(_ethernetGatewayMAC)) {
|
if (!Ethernet.begin(_ethernetGatewayMAC)) {
|
||||||
MY_SERIALDEVICE.print(F("DHCP FAILURE..."));
|
MY_SERIALDEVICE.print(F("DHCP FAILURE..."));
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* End of MY_IP_GATEWAY_ADDRESS && MY_IP_SUBNET_ADDRESS */
|
||||||
MY_SERIALDEVICE.print(F("IP: "));
|
MY_SERIALDEVICE.print(F("IP: "));
|
||||||
MY_SERIALDEVICE.println(Ethernet.localIP());
|
MY_SERIALDEVICE.println(Ethernet.localIP());
|
||||||
// give the Ethernet interface a second to initialize
|
// give the Ethernet interface a second to initialize
|
||||||
delay(1000);
|
delay(1000);
|
||||||
#endif /* MY_GATEWAY_ESP8266 */
|
#endif /* End of MY_GATEWAY_ESP8266 */
|
||||||
|
|
||||||
#if defined(MY_GATEWAY_CLIENT_MODE)
|
#if defined(MY_GATEWAY_CLIENT_MODE)
|
||||||
|
#if defined(MY_USE_UDP)
|
||||||
|
_ethernetServer.begin(_ethernetGatewayPort);
|
||||||
|
#else /* Else part of MY_USE_UDP */
|
||||||
#if defined(MY_GATEWAY_LINUX) && defined(MY_IP_ADDRESS)
|
#if defined(MY_GATEWAY_LINUX) && defined(MY_IP_ADDRESS)
|
||||||
client.bind(_ethernetGatewayIP);
|
client.bind(_ethernetGatewayIP);
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_LINUX && MY_IP_ADDRESS */
|
||||||
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
||||||
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
||||||
#else
|
#else
|
||||||
if (client.connect(_ethernetControllerIP, MY_PORT)) {
|
if (client.connect(_ethernetControllerIP, MY_PORT)) {
|
||||||
#endif
|
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
|
||||||
debug(PSTR("Eth: connect\n"));
|
debug(PSTR("Eth: connect\n"));
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
||||||
@@ -155,16 +173,15 @@ bool gatewayTransportInit(void)
|
|||||||
client.stop();
|
client.stop();
|
||||||
debug(PSTR("Eth: Failed to connect\n"));
|
debug(PSTR("Eth: Failed to connect\n"));
|
||||||
}
|
}
|
||||||
#elif defined(MY_USE_UDP)
|
#endif /* End of MY_USE_UDP */
|
||||||
_ethernetServer.begin(_ethernetGatewayPort);
|
#else /* Else part of MY_GATEWAY_CLIENT_MODE */
|
||||||
#else
|
|
||||||
#if defined(MY_GATEWAY_LINUX) && defined(MY_IP_ADDRESS)
|
#if defined(MY_GATEWAY_LINUX) && defined(MY_IP_ADDRESS)
|
||||||
_ethernetServer.begin(_ethernetGatewayIP);
|
_ethernetServer.begin(_ethernetGatewayIP);
|
||||||
#else
|
#else
|
||||||
// we have to use pointers due to the constructor of EthernetServer
|
// we have to use pointers due to the constructor of EthernetServer
|
||||||
_ethernetServer.begin();
|
_ethernetServer.begin();
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_LINUX && MY_IP_ADDRESS */
|
||||||
#endif /* USE_UDP */
|
#endif /* End of MY_GATEWAY_CLIENT_MODE */
|
||||||
|
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
return true;
|
return true;
|
||||||
@@ -184,18 +201,18 @@ bool gatewayTransportSend(MyMessage &message)
|
|||||||
_ethernetServer.beginPacket(MY_CONTROLLER_URL_ADDRESS, MY_PORT);
|
_ethernetServer.beginPacket(MY_CONTROLLER_URL_ADDRESS, MY_PORT);
|
||||||
#else
|
#else
|
||||||
_ethernetServer.beginPacket(_ethernetControllerIP, MY_PORT);
|
_ethernetServer.beginPacket(_ethernetControllerIP, MY_PORT);
|
||||||
#endif
|
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
|
||||||
_ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg));
|
_ethernetServer.write(_ethernetMsg, strlen(_ethernetMsg));
|
||||||
// returns 1 if the packet was sent successfully
|
// returns 1 if the packet was sent successfully
|
||||||
nbytes = _ethernetServer.endPacket();
|
nbytes = _ethernetServer.endPacket();
|
||||||
#else
|
#else /* Else part of MY_USE_UDP */
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
client.stop();
|
client.stop();
|
||||||
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
||||||
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
||||||
#else
|
#else
|
||||||
if (client.connect(_ethernetControllerIP, MY_PORT)) {
|
if (client.connect(_ethernetControllerIP, MY_PORT)) {
|
||||||
#endif
|
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
|
||||||
debug(PSTR("Eth: connect\n"));
|
debug(PSTR("Eth: connect\n"));
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
||||||
@@ -209,8 +226,8 @@ bool gatewayTransportSend(MyMessage &message)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
nbytes = client.write((const uint8_t*)_ethernetMsg, strlen(_ethernetMsg));
|
nbytes = client.write((const uint8_t*)_ethernetMsg, strlen(_ethernetMsg));
|
||||||
#endif
|
#endif /* End of MY_USE_UDP */
|
||||||
#else
|
#else /* Else part of MY_GATEWAY_CLIENT_MODE */
|
||||||
// Send message to connected clients
|
// Send message to connected clients
|
||||||
#if defined(MY_GATEWAY_ESP8266)
|
#if defined(MY_GATEWAY_ESP8266)
|
||||||
for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
|
for (uint8_t i = 0; i < ARRAY_SIZE(clients); i++) {
|
||||||
@@ -218,14 +235,17 @@ bool gatewayTransportSend(MyMessage &message)
|
|||||||
nbytes += clients[i].write((uint8_t*)_ethernetMsg, strlen(_ethernetMsg));
|
nbytes += clients[i].write((uint8_t*)_ethernetMsg, strlen(_ethernetMsg));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else /* Else part of MY_GATEWAY_ESP8266 */
|
||||||
nbytes = _ethernetServer.write(_ethernetMsg);
|
nbytes = _ethernetServer.write(_ethernetMsg);
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_ESP8266 */
|
||||||
#endif /* MY_GATEWAY_CLIENT_MODE */
|
#endif /* End of MY_GATEWAY_CLIENT_MODE */
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
return (nbytes > 0);
|
return (nbytes > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(MY_USE_UDP)
|
||||||
|
// Nothing to do here
|
||||||
|
#else
|
||||||
#if (defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)) && !defined(MY_GATEWAY_CLIENT_MODE)
|
#if (defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)) && !defined(MY_GATEWAY_CLIENT_MODE)
|
||||||
bool _readFromClient(uint8_t i)
|
bool _readFromClient(uint8_t i)
|
||||||
{
|
{
|
||||||
@@ -256,7 +276,7 @@ bool _readFromClient(uint8_t i)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#else
|
#else /* Else part of MY_GATEWAY_ESP8266 || MY_GATEWAY_LINUX || !MY_GATEWAY_CLIENT_MODE */
|
||||||
bool _readFromClient(void)
|
bool _readFromClient(void)
|
||||||
{
|
{
|
||||||
while (client.connected() && client.available()) {
|
while (client.connected() && client.available()) {
|
||||||
@@ -286,8 +306,8 @@ bool _readFromClient(void)
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_ESP8266 || MY_GATEWAY_LINUX || !MY_GATEWAY_CLIENT_MODE */
|
||||||
|
#endif /* End of MY_USE_UDP */
|
||||||
|
|
||||||
bool gatewayTransportAvailable(void)
|
bool gatewayTransportAvailable(void)
|
||||||
{
|
{
|
||||||
@@ -297,36 +317,30 @@ bool gatewayTransportAvailable(void)
|
|||||||
gatewayTransportRenewIP();
|
gatewayTransportRenewIP();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MY_USE_UDP
|
#if defined(MY_GATEWAY_CLIENT_MODE)
|
||||||
|
#if defined(MY_USE_UDP)
|
||||||
int packet_size = _ethernetServer.parsePacket();
|
int packet_size = _ethernetServer.parsePacket();
|
||||||
|
|
||||||
if (packet_size) {
|
if (packet_size) {
|
||||||
//debug(PSTR("UDP packet available. Size:%d\n"), packet_size);
|
//debug(PSTR("UDP packet available. Size:%d\n"), packet_size);
|
||||||
#if defined(MY_GATEWAY_ESP8266) && !defined(MY_GATEWAY_CLIENT_MODE)
|
|
||||||
_ethernetServer.read(inputString[0].string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
|
|
||||||
inputString[0].string[packet_size] = 0;
|
|
||||||
debug(PSTR("UDP packet received: %s\n"), inputString[0].string);
|
|
||||||
const bool ok = protocolParse(_ethernetMsg, inputString[0].string);
|
|
||||||
#else
|
|
||||||
_ethernetServer.read(inputString.string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
|
_ethernetServer.read(inputString.string, MY_GATEWAY_MAX_RECEIVE_LENGTH);
|
||||||
inputString.string[packet_size] = 0;
|
inputString.string[packet_size] = 0;
|
||||||
debug(PSTR("UDP packet received: %s\n"), inputString.string);
|
debug(PSTR("UDP packet received: %s\n"), inputString.string);
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
const bool ok = protocolParse(_ethernetMsg, inputString.string);
|
const bool ok = protocolParse(_ethernetMsg, inputString.string);
|
||||||
#endif
|
|
||||||
if (ok) {
|
if (ok) {
|
||||||
setIndication(INDICATION_GW_RX);
|
setIndication(INDICATION_GW_RX);
|
||||||
}
|
}
|
||||||
return ok;
|
return ok;
|
||||||
}
|
}
|
||||||
#elif defined(MY_GATEWAY_CLIENT_MODE)
|
#else /* Else part of MY_USE_UDP */
|
||||||
if (!client.connected()) {
|
if (!client.connected()) {
|
||||||
client.stop();
|
client.stop();
|
||||||
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
#if defined(MY_CONTROLLER_URL_ADDRESS)
|
||||||
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
|
||||||
#else
|
#else
|
||||||
if (client.connect(_ethernetControllerIP, MY_PORT)) {
|
if (client.connect(_ethernetControllerIP, MY_PORT)) {
|
||||||
#endif
|
#endif /* End of MY_CONTROLLER_URL_ADDRESS */
|
||||||
debug(PSTR("Eth: connect\n"));
|
debug(PSTR("Eth: connect\n"));
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
gatewayTransportSend(buildGw(_msgTmp, I_GATEWAY_READY).set(MSG_GW_STARTUP_COMPLETE));
|
||||||
@@ -343,7 +357,8 @@ bool gatewayTransportAvailable(void)
|
|||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#else
|
#endif /* End of MY_USE_UDP */
|
||||||
|
#else /* Else part of MY_GATEWAY_CLIENT_MODE */
|
||||||
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)
|
#if defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX)
|
||||||
// ESP8266: Go over list of clients and stop any that are no longer connected.
|
// ESP8266: Go over list of clients and stop any that are no longer connected.
|
||||||
// If the server has a new client connection it will be assigned to a free slot.
|
// If the server has a new client connection it will be assigned to a free slot.
|
||||||
@@ -382,7 +397,7 @@ bool gatewayTransportAvailable(void)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else /* Else part of MY_GATEWAY_ESP8266 || MY_GATEWAY_LINUX */
|
||||||
// W5100/ENC module does not have hasClient-method. We can only serve one client at the time.
|
// W5100/ENC module does not have hasClient-method. We can only serve one client at the time.
|
||||||
EthernetClient newclient = _ethernetServer.available();
|
EthernetClient newclient = _ethernetServer.available();
|
||||||
// if a new client connects make sure to dispose any previous existing sockets
|
// if a new client connects make sure to dispose any previous existing sockets
|
||||||
@@ -409,8 +424,8 @@ bool gatewayTransportAvailable(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* MY_GATEWAY_ESP8266 */
|
#endif /* End of MY_GATEWAY_ESP8266 || MY_GATEWAY_LINUX */
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_CLIENT_MODE */
|
||||||
_w5100_spi_en(false);
|
_w5100_spi_en(false);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,21 +26,29 @@
|
|||||||
IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS);
|
IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(MY_IP_ADDRESS)
|
||||||
|
IPAddress _MQTT_clientIp(MY_IP_ADDRESS);
|
||||||
|
#if defined(MY_IP_GATEWAY_ADDRESS)
|
||||||
|
IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS);
|
||||||
|
#elif defined(MY_GATEWAY_ESP8266) /* Elif part of MY_IP_GATEWAY_ADDRESS */
|
||||||
|
// Assume the gateway will be the machine on the same network as the local IP
|
||||||
|
// but with last octet being '1'
|
||||||
|
IPAddress _gatewayIp(_MQTT_clientIp[0], _MQTT_clientIp[1], _MQTT_clientIp[2], 1);
|
||||||
|
#endif /* End of MY_IP_GATEWAY_ADDRESS */
|
||||||
|
#if defined(MY_IP_SUBNET_ADDRESS)
|
||||||
|
IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS);
|
||||||
|
#elif defined(MY_GATEWAY_ESP8266) /* Elif part of MY_IP_SUBNET_ADDRESS */
|
||||||
|
IPAddress _subnetIp(255, 255, 255, 0);
|
||||||
|
#endif /* End of MY_IP_SUBNET_ADDRESS */
|
||||||
|
#endif /* End of MY_IP_ADDRESS */
|
||||||
|
|
||||||
#if defined(MY_GATEWAY_ESP8266)
|
#if defined(MY_GATEWAY_ESP8266)
|
||||||
#define EthernetClient WiFiClient
|
#define EthernetClient WiFiClient
|
||||||
#if defined(MY_IP_ADDRESS)
|
|
||||||
IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS);
|
|
||||||
IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS);
|
|
||||||
#endif
|
|
||||||
#elif defined(MY_GATEWAY_LINUX)
|
#elif defined(MY_GATEWAY_LINUX)
|
||||||
// Nothing to do here
|
// Nothing to do here
|
||||||
#else
|
#else
|
||||||
uint8_t _MQTT_clientMAC[] = { MY_MAC_ADDRESS };
|
uint8_t _MQTT_clientMAC[] = { MY_MAC_ADDRESS };
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_ESP8266 */
|
||||||
|
|
||||||
#if defined(MY_IP_ADDRESS)
|
|
||||||
IPAddress _MQTT_clientIp(MY_IP_ADDRESS);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static EthernetClient _MQTT_ethClient;
|
static EthernetClient _MQTT_ethClient;
|
||||||
static PubSubClient _MQTT_client(_MQTT_ethClient);
|
static PubSubClient _MQTT_client(_MQTT_ethClient);
|
||||||
@@ -56,12 +64,12 @@ bool gatewayTransportSend(MyMessage &message)
|
|||||||
setIndication(INDICATION_GW_TX);
|
setIndication(INDICATION_GW_TX);
|
||||||
char *topic = protocolFormatMQTTTopic(MY_MQTT_PUBLISH_TOPIC_PREFIX, message);
|
char *topic = protocolFormatMQTTTopic(MY_MQTT_PUBLISH_TOPIC_PREFIX, message);
|
||||||
debug(PSTR("Sending message on topic: %s\n"), topic);
|
debug(PSTR("Sending message on topic: %s\n"), topic);
|
||||||
#ifdef MY_MQTT_CLIENT_PUBLISH_RETAIN
|
#if defined(MY_MQTT_CLIENT_PUBLISH_RETAIN)
|
||||||
bool retain = mGetCommand(message) == C_SET ||
|
bool retain = mGetCommand(message) == C_SET ||
|
||||||
(mGetCommand(message) == C_INTERNAL && message.type == I_BATTERY_LEVEL);
|
(mGetCommand(message) == C_INTERNAL && message.type == I_BATTERY_LEVEL);
|
||||||
#else
|
#else
|
||||||
bool retain = false;
|
bool retain = false;
|
||||||
#endif
|
#endif /* End of MY_MQTT_CLIENT_PUBLISH_RETAIN */
|
||||||
return _MQTT_client.publish(topic, message.getString(_convBuffer), retain);
|
return _MQTT_client.publish(topic, message.getString(_convBuffer), retain);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,26 +111,26 @@ bool gatewayTransportConnect(void)
|
|||||||
}
|
}
|
||||||
MY_SERIALDEVICE.print(F("IP: "));
|
MY_SERIALDEVICE.print(F("IP: "));
|
||||||
MY_SERIALDEVICE.println(WiFi.localIP());
|
MY_SERIALDEVICE.println(WiFi.localIP());
|
||||||
#elif defined(MY_GATEWAY_LINUX)
|
#elif defined(MY_GATEWAY_LINUX) /* Elif part of MY_GATEWAY_ESP8266 */
|
||||||
#if defined(MY_IP_ADDRESS)
|
#if defined(MY_IP_ADDRESS)
|
||||||
_MQTT_ethClient.bind(_MQTT_clientIp);
|
_MQTT_ethClient.bind(_MQTT_clientIp);
|
||||||
#endif
|
#endif /* End of MY_IP_ADDRESS */
|
||||||
#else
|
#else /* Else part of MY_GATEWAY_ESP8266 */
|
||||||
#ifdef MY_IP_ADDRESS
|
#if defined(MY_IP_ADDRESS)
|
||||||
Ethernet.begin(_MQTT_clientMAC, _MQTT_clientIp);
|
Ethernet.begin(_MQTT_clientMAC, _MQTT_clientIp);
|
||||||
#else
|
#else /* Else part of MY_IP_ADDRESS */
|
||||||
// Get IP address from DHCP
|
// Get IP address from DHCP
|
||||||
if (!Ethernet.begin(_MQTT_clientMAC)) {
|
if (!Ethernet.begin(_MQTT_clientMAC)) {
|
||||||
MY_SERIALDEVICE.print(F("DHCP FAILURE..."));
|
MY_SERIALDEVICE.print(F("DHCP FAILURE..."));
|
||||||
_MQTT_connecting = false;
|
_MQTT_connecting = false;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif /* End of MY_IP_ADDRESS */
|
||||||
MY_SERIALDEVICE.print(F("IP: "));
|
MY_SERIALDEVICE.print(F("IP: "));
|
||||||
MY_SERIALDEVICE.println(Ethernet.localIP());
|
MY_SERIALDEVICE.println(Ethernet.localIP());
|
||||||
// give the Ethernet interface a second to initialize
|
// give the Ethernet interface a second to initialize
|
||||||
delay(1000);
|
delay(1000);
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_ESP8266 */
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -133,7 +141,7 @@ bool gatewayTransportInit(void)
|
|||||||
_MQTT_client.setServer(_brokerIp, MY_PORT);
|
_MQTT_client.setServer(_brokerIp, MY_PORT);
|
||||||
#else
|
#else
|
||||||
_MQTT_client.setServer(MY_CONTROLLER_URL_ADDRESS, MY_PORT);
|
_MQTT_client.setServer(MY_CONTROLLER_URL_ADDRESS, MY_PORT);
|
||||||
#endif
|
#endif /* End of MY_CONTROLLER_IP_ADDRESS */
|
||||||
|
|
||||||
_MQTT_client.setCallback(incomingMQTT);
|
_MQTT_client.setCallback(incomingMQTT);
|
||||||
|
|
||||||
@@ -142,12 +150,12 @@ bool gatewayTransportInit(void)
|
|||||||
WiFi.mode(WIFI_STA);
|
WiFi.mode(WIFI_STA);
|
||||||
#if defined(MY_ESP8266_HOSTNAME)
|
#if defined(MY_ESP8266_HOSTNAME)
|
||||||
WiFi.hostname(MY_ESP8266_HOSTNAME);
|
WiFi.hostname(MY_ESP8266_HOSTNAME);
|
||||||
#endif
|
#endif /* End of MY_ESP8266_HOSTNAME */
|
||||||
#ifdef MY_IP_ADDRESS
|
#if defined(MY_IP_ADDRESS)
|
||||||
WiFi.config(_MQTT_clientIp, _gatewayIp, _subnetIp);
|
WiFi.config(_MQTT_clientIp, _gatewayIp, _subnetIp);
|
||||||
#endif
|
#endif /* End of MY_IP_ADDRESS */
|
||||||
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD);
|
(void)WiFi.begin(MY_ESP8266_SSID, MY_ESP8266_PASSWORD);
|
||||||
#endif
|
#endif /* End of MY_GATEWAY_ESP8266 */
|
||||||
|
|
||||||
gatewayTransportConnect();
|
gatewayTransportConnect();
|
||||||
|
|
||||||
|
|||||||
@@ -65,7 +65,6 @@
|
|||||||
* Make sure to fill in your ssid and WiFi password below for ssid & pass.
|
* Make sure to fill in your ssid and WiFi password below for ssid & pass.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Enable debug prints to serial monitor
|
// Enable debug prints to serial monitor
|
||||||
#define MY_DEBUG
|
#define MY_DEBUG
|
||||||
|
|
||||||
@@ -82,18 +81,18 @@
|
|||||||
#define MY_ESP8266_PASSWORD "MyVerySecretPassword"
|
#define MY_ESP8266_PASSWORD "MyVerySecretPassword"
|
||||||
|
|
||||||
// Enable UDP communication
|
// 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
|
// Set the hostname for the WiFi Client. This is the hostname
|
||||||
// it will pass to the DHCP server if not static.
|
// 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)
|
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
|
||||||
//#define MY_IP_ADDRESS 192,168,178,87
|
//#define MY_IP_ADDRESS 192,168,178,87
|
||||||
|
|
||||||
// If using static ip you need to define Gateway and Subnet address as well
|
// 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_GATEWAY_ADDRESS 192,168,178,1
|
||||||
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
|
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
|
||||||
|
|
||||||
// The port to keep open on node server mode
|
// The port to keep open on node server mode
|
||||||
#define MY_PORT 5003
|
#define MY_PORT 5003
|
||||||
@@ -106,44 +105,43 @@
|
|||||||
//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
|
//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
|
||||||
|
|
||||||
// Enable inclusion mode
|
// Enable inclusion mode
|
||||||
#define MY_INCLUSION_MODE_FEATURE
|
//#define MY_INCLUSION_MODE_FEATURE
|
||||||
|
|
||||||
// Enable Inclusion mode button on gateway
|
// Enable Inclusion mode button on gateway
|
||||||
// #define MY_INCLUSION_BUTTON_FEATURE
|
//#define MY_INCLUSION_BUTTON_FEATURE
|
||||||
// Set inclusion mode duration (in seconds)
|
// 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
|
// Digital pin used for inclusion mode button
|
||||||
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
|
||||||
// Set blinking period
|
// Set blinking period
|
||||||
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
|
//#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
// Flash leds on rx/tx/err
|
// Flash leds on rx/tx/err
|
||||||
// Led pins used if blinking feature is enabled above
|
// Led pins used if blinking feature is enabled above
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
//#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
||||||
#define MY_DEFAULT_RX_LED_PIN 16 // Receive 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_TX_LED_PIN 16 // the PCB, on board LED
|
||||||
|
|
||||||
#if defined(MY_USE_UDP)
|
#if defined(MY_USE_UDP)
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
|
|
||||||
#include <MySensors.h>
|
#include <MySensors.h>
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
// Setup locally attached sensors
|
||||||
}
|
}
|
||||||
|
|
||||||
void presentation()
|
void presentation()
|
||||||
{
|
{
|
||||||
// Present locally attached sensors here
|
// Present locally attached sensors here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
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.
|
* Make sure to fill in your ssid and WiFi password below for ssid & pass.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
// Enable debug prints to serial monitor
|
// Enable debug prints to serial monitor
|
||||||
#define MY_DEBUG
|
#define MY_DEBUG
|
||||||
|
|
||||||
@@ -91,12 +90,11 @@
|
|||||||
// #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway"
|
// #define MY_ESP8266_HOSTNAME "mqtt-sensor-gateway"
|
||||||
|
|
||||||
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
|
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
|
||||||
#define MY_IP_ADDRESS 192,168,178,87
|
//#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.
|
// MQTT broker ip address.
|
||||||
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
|
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
|
||||||
@@ -104,39 +102,38 @@
|
|||||||
// The MQTT broker port to to open
|
// The MQTT broker port to to open
|
||||||
#define MY_PORT 1883
|
#define MY_PORT 1883
|
||||||
|
|
||||||
/*
|
|
||||||
// Enable inclusion mode
|
// Enable inclusion mode
|
||||||
#define MY_INCLUSION_MODE_FEATURE
|
//#define MY_INCLUSION_MODE_FEATURE
|
||||||
// Enable Inclusion mode button on gateway
|
// Enable Inclusion mode button on gateway
|
||||||
#define MY_INCLUSION_BUTTON_FEATURE
|
//#define MY_INCLUSION_BUTTON_FEATURE
|
||||||
// Set inclusion mode duration (in seconds)
|
// 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
|
// Digital pin used for inclusion mode button
|
||||||
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
//#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
// Set blinking period
|
// Set blinking period
|
||||||
#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
//#define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
// Flash leds on rx/tx/err
|
// Flash leds on rx/tx/err
|
||||||
#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
//#define MY_DEFAULT_ERR_LED_PIN 16 // Error led pin
|
||||||
#define MY_DEFAULT_RX_LED_PIN 16 // Receive 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_TX_LED_PIN 16 // the PCB, on board LED
|
||||||
*/
|
|
||||||
|
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <MySensors.h>
|
#include <MySensors.h>
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
// Setup locally attached sensors
|
||||||
}
|
}
|
||||||
|
|
||||||
void presentation()
|
void presentation()
|
||||||
{
|
{
|
||||||
// Present locally attached sensors here
|
// Present locally attached sensors here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
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"
|
// #define MY_ESP8266_HOSTNAME "sensor-ota-gateway"
|
||||||
|
|
||||||
// Enable UDP communication
|
// 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)
|
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
|
||||||
//#define MY_IP_ADDRESS 192,168,178,87
|
//#define MY_IP_ADDRESS 192,168,178,87
|
||||||
|
|
||||||
// If using static ip you need to define Gateway and Subnet address as well
|
// 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_GATEWAY_ADDRESS 192,168,178,1
|
||||||
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
|
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
|
||||||
|
|
||||||
// The port to keep open on node server mode
|
// The port to keep open on node server mode
|
||||||
#define MY_PORT 5003
|
#define MY_PORT 5003
|
||||||
@@ -117,7 +117,6 @@
|
|||||||
// Digital pin used for inclusion mode button
|
// Digital pin used for inclusion mode button
|
||||||
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
#define MY_INCLUSION_MODE_BUTTON_PIN 3
|
||||||
|
|
||||||
|
|
||||||
// Set blinking period
|
// Set blinking period
|
||||||
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
|
// #define MY_DEFAULT_LED_BLINK_PERIOD 300
|
||||||
|
|
||||||
@@ -137,45 +136,41 @@
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
// Setup locally attached sensors
|
||||||
ArduinoOTA.onStart([]() {
|
ArduinoOTA.onStart([]() {
|
||||||
Serial.println("ArduinoOTA start");
|
debug("ArduinoOTA start\n");
|
||||||
});
|
});
|
||||||
ArduinoOTA.onEnd([]() {
|
ArduinoOTA.onEnd([]() {
|
||||||
Serial.println("\nArduinoOTA end");
|
debug("\nArduinoOTA end\n");
|
||||||
});
|
});
|
||||||
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
|
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) {
|
ArduinoOTA.onError([](ota_error_t error) {
|
||||||
Serial.printf("Error[%u]: ", error);
|
debug("Error[%u]: ", error);
|
||||||
if (error == OTA_AUTH_ERROR) {
|
if (error == OTA_AUTH_ERROR) {
|
||||||
Serial.println("Auth Failed");
|
debug("Auth Failed\n");
|
||||||
} else if (error == OTA_BEGIN_ERROR) {
|
} else if (error == OTA_BEGIN_ERROR) {
|
||||||
Serial.println("Begin Failed");
|
debug("Begin Failed\n");
|
||||||
} else if (error == OTA_CONNECT_ERROR) {
|
} else if (error == OTA_CONNECT_ERROR) {
|
||||||
Serial.println("Connect Failed");
|
debug("Connect Failed\n");
|
||||||
} else if (error == OTA_RECEIVE_ERROR) {
|
} else if (error == OTA_RECEIVE_ERROR) {
|
||||||
Serial.println("Receive Failed");
|
debug("Receive Failed\n");
|
||||||
} else if (error == OTA_END_ERROR) {
|
} else if (error == OTA_END_ERROR) {
|
||||||
Serial.println("End Failed");
|
debug("End Failed\n");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ArduinoOTA.begin();
|
ArduinoOTA.begin();
|
||||||
Serial.println("Ready");
|
|
||||||
Serial.print("IP address: ");
|
|
||||||
Serial.println(WiFi.localIP());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void presentation()
|
void presentation()
|
||||||
{
|
{
|
||||||
// Present locally attached sensors here
|
// Present locally attached sensors here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// Send locally attech sensors data here
|
// Send locally attech sensors data here
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -72,12 +72,19 @@
|
|||||||
#define MY_RF24_CS_PIN 6
|
#define MY_RF24_CS_PIN 6
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Enable to UDP
|
// 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,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
|
// Renewal period if using DHCP
|
||||||
//#define MY_IP_RENEWAL_INTERVAL 60000
|
//#define MY_IP_RENEWAL_INTERVAL 60000
|
||||||
|
|
||||||
// The port to keep open on node server mode / or port to contact in client mode
|
// The port to keep open on node server mode / or port to contact in client mode
|
||||||
#define MY_PORT 5003
|
#define MY_PORT 5003
|
||||||
|
|
||||||
@@ -108,18 +115,24 @@
|
|||||||
//#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
|
//#define MY_DEFAULT_RX_LED_PIN 8 // Receive led pin
|
||||||
//#define MY_DEFAULT_TX_LED_PIN 9 // Transmit led pin
|
//#define MY_DEFAULT_TX_LED_PIN 9 // Transmit led pin
|
||||||
|
|
||||||
|
|
||||||
#if defined(MY_USE_UDP)
|
#if defined(MY_USE_UDP)
|
||||||
#include <EthernetUdp.h>
|
#include <EthernetUdp.h>
|
||||||
#endif
|
#endif
|
||||||
#include <Ethernet.h>
|
#include <Ethernet.h>
|
||||||
#include <MySensors.h>
|
#include <MySensors.h>
|
||||||
|
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
// Setup locally attached sensors
|
||||||
|
}
|
||||||
|
|
||||||
|
void presentation()
|
||||||
|
{
|
||||||
|
// Present locally attached sensors here
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop()
|
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)
|
// Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
|
||||||
#define MY_IP_ADDRESS 192,168,178,87
|
#define MY_IP_ADDRESS 192,168,178,87
|
||||||
|
|
||||||
// If using static ip you need to define Gateway and Subnet address as well
|
// 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_GATEWAY_ADDRESS 192,168,178,1
|
||||||
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
|
//#define MY_IP_SUBNET_ADDRESS 255,255,255,0
|
||||||
|
|
||||||
// MQTT broker ip address or url. Define one or the other.
|
// MQTT broker ip address or url. Define one or the other.
|
||||||
//#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
|
//#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
|
||||||
@@ -138,15 +138,16 @@
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
// Setup locally attached sensors
|
||||||
}
|
}
|
||||||
|
|
||||||
void presentation()
|
void presentation()
|
||||||
{
|
{
|
||||||
// Present locally attached sensors here
|
// Present locally attached sensors here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void loop()
|
void loop()
|
||||||
{
|
{
|
||||||
// Send locally attached sensors data here
|
// Send locally attached sensors data here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user