diff --git a/README.md b/README.md index 5f461c5..2f8ce14 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ Arduino ======= -MySensors Arduino Library v1.5 +MySensors Arduino Library v2.0.0-beta Please visit www.mysensors.org for more information diff --git a/libraries/MySensors/MyConfig.h b/libraries/MySensors/MyConfig.h index 37b3cab..6c0b00f 100644 --- a/libraries/MySensors/MyConfig.h +++ b/libraries/MySensors/MyConfig.h @@ -371,7 +371,17 @@ /** * @def MY_RF24_CHANNEL - * @brief RF channel for the sensor net, 0-127. + * @brief RF channel for the sensor net, 0-125. + * Frequence: 2400 Mhz - 2525 Mhz Channels: 126 + * http://www.mysensors.org/radio/nRF24L01Plus.pdf + * 0 => 2400 Mhz (RF24 channel 1) + * 1 => 2401 Mhz (RF24 channel 2) + * 76 => 2476 Mhz (RF24 channel 77) + * 83 => 2483 Mhz (RF24 channel 84) + * 124 => 2524 Mhz (RF24 channel 125) + * 125 => 2525 Mhz (RF24 channel 126) + * In some countries there might be limitations, in Germany for example only the range 2400,0 - 2483,5 Mhz is allowed + * http://www.bundesnetzagentur.de/SharedDocs/Downloads/DE/Sachgebiete/Telekommunikation/Unternehmen_Institutionen/Frequenzen/Allgemeinzuteilungen/2013_10_WLAN_2,4GHz_pdf.pdf */ #ifndef MY_RF24_CHANNEL #define MY_RF24_CHANNEL 76 diff --git a/libraries/MySensors/MySensor.h b/libraries/MySensors/MySensor.h index 9b34525..c562a2a 100644 --- a/libraries/MySensors/MySensor.h +++ b/libraries/MySensors/MySensor.h @@ -85,7 +85,7 @@ #endif // Not necessary to include blinking feature if no LED's are defined! -#if defined(MY_LEDS_BLINKING_FEATURE) && !defined(MY_DEFAULT_RX_LED_PIN) && !defined(MU_DEFAULT_TX_LED_PIN) && !defined(MY_ERR_LED_PIN) +#if defined(MY_LEDS_BLINKING_FEATURE) && !defined(MY_DEFAULT_RX_LED_PIN) && !defined(MY_DEFAULT_TX_LED_PIN) && !defined(MY_ERR_LED_PIN) #undef MY_LEDS_BLINKING_FEATURE #endif @@ -179,9 +179,10 @@ #endif // GATEWAY - COMMON FUNCTIONS // We only support MQTT Client using W5100 and ESP8266 at the moment - #if !defined(MY_CONTROLLER_IP_ADDRESS) - #error You must specify MY_CONTROLLER_IP_ADDRESS (MQTT broker address) + #if !(defined(MY_CONTROLLER_URL_ADDRESS) || defined(MY_CONTROLLER_IP_ADDRESS)) + #error You must specify MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS #endif + #if !defined(MY_MQTT_PUBLISH_TOPIC_PREFIX) #error You must specify a topic publish prefix MY_MQTT_PUBLISH_TOPIC_PREFIX for this MQTT client #endif diff --git a/libraries/MySensors/core/MyGatewayTransportEthernet.cpp b/libraries/MySensors/core/MyGatewayTransportEthernet.cpp index 3bbeb3d..c5b581f 100644 --- a/libraries/MySensors/core/MyGatewayTransportEthernet.cpp +++ b/libraries/MySensors/core/MyGatewayTransportEthernet.cpp @@ -156,7 +156,11 @@ bool gatewayTransportSend(MyMessage &message) ret = _ethernetServer.endPacket(); #else EthernetClient client; - if (client.connect(_ethernetControllerIP, MY_PORT)) { + #if defined(MY_CONTROLLER_URL_ADDRESS) + if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) { + #else + if (client.connect(_ethernetControllerIP, MY_PORT)) { + #endif client.write(_ethernetMsg, strlen(_ethernetMsg)); client.stop(); } diff --git a/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp b/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp index d43091f..3dad8d1 100644 --- a/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp +++ b/libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp @@ -28,12 +28,16 @@ uint8_t protocolH2i(char c); -IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS); +#if defined MY_CONTROLLER_IP_ADDRESS + IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS); +#endif #if defined(MY_GATEWAY_ESP8266) #define EthernetClient WiFiClient - IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS); - IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS); + #if defined(MY_IP_ADDRESS) + IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS); + IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS); + #endif #else byte _clientMAC[] = { MY_MAC_ADDRESS }; #endif @@ -44,6 +48,7 @@ IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS); EthernetClient _ethClient; PubSubClient _client(_ethClient); +bool _connecting = true; bool _available = false; char _convBuffer[MAX_PAYLOAD*2+1]; char _fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH]; @@ -150,7 +155,13 @@ bool reconnectMQTT() { } bool gatewayTransportInit() { - _client.setServer(_brokerIp, MY_PORT); + _connecting = true; + #if defined(MY_CONTROLLER_IP_ADDRESS) + _client.setServer(_brokerIp, MY_PORT); + #else + _client.setServer(MY_CONTROLLER_URL_ADDRESS, MY_PORT); + #endif + _client.setCallback(incomingMQTT); #if defined(MY_GATEWAY_ESP8266) @@ -164,30 +175,42 @@ bool gatewayTransportInit() { MY_SERIALDEVICE.print("."); yield(); } - MY_SERIALDEVICE.print(F("IP: ")); + MY_SERIALDEVICE.print("IP: "); MY_SERIALDEVICE.println(WiFi.localIP()); #else #ifdef MY_IP_ADDRESS Ethernet.begin(_clientMAC, _clientIp); - MY_SERIALDEVICE.print(F("IP: ")); - MY_SERIALDEVICE.println(Ethernet.localIP()); #else // Get IP address from DHCP - Ethernet.begin(_clientMAC); - MY_SERIALDEVICE.print(F("IP: ")); + if (!Ethernet.begin(_clientMAC)) + { + MY_SERIALDEVICE.print("DHCP FAILURE..."); + _connecting = false; + return false; + } + MY_SERIALDEVICE.print("IP: "); MY_SERIALDEVICE.println(Ethernet.localIP()); - #endif /* IP_ADDRESS_DHCP */ + #endif + // give the Ethernet interface a second to initialize // TODO: use HW delay wait(1000); #endif + _connecting = false; return true; } bool gatewayTransportAvailable() { + if (_connecting) + return false; + + //keep lease on dhcp address + //Ethernet.maintain(); if (!_client.connected()) { - reconnectMQTT(); + //reinitialise client + if (gatewayTransportInit()) + reconnectMQTT(); return false; } _client.loop(); diff --git a/libraries/MySensors/core/MySensorCore.cpp b/libraries/MySensors/core/MySensorCore.cpp index 9fea04d..feabd96 100644 --- a/libraries/MySensors/core/MySensorCore.cpp +++ b/libraries/MySensors/core/MySensorCore.cpp @@ -123,8 +123,6 @@ void _begin() { #elif defined(MY_RADIO_FEATURE) // Read settings from eeprom hwReadConfigBlock((void*)&_nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig)); - // Read latest received controller configuration from EEPROM - hwReadConfigBlock((void*)&_cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig)); #ifdef MY_OTA_FIRMWARE_FEATURE // Read firmware config from EEPROM, i.e. type, version, CRC, blocks hwReadConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig)); diff --git a/libraries/MySensors/drivers/RF24/RF24.cpp b/libraries/MySensors/drivers/RF24/RF24.cpp index fc813f0..4941c91 100644 --- a/libraries/MySensors/drivers/RF24/RF24.cpp +++ b/libraries/MySensors/drivers/RF24/RF24.cpp @@ -388,7 +388,7 @@ RF24::RF24(uint8_t _cepin, uint8_t _cspin): void RF24::setChannel(uint8_t channel) { - const uint8_t max_channel = 127; + const uint8_t max_channel = 125; write_register(RF_CH,min(channel,max_channel)); } diff --git a/libraries/MySensors/drivers/RF24/RF24.h b/libraries/MySensors/drivers/RF24/RF24.h index 8cbfc7c..741b3c2 100644 --- a/libraries/MySensors/drivers/RF24/RF24.h +++ b/libraries/MySensors/drivers/RF24/RF24.h @@ -601,7 +601,7 @@ public: /** * Set RF communication channel * - * @param channel Which RF channel to communicate on, 0-127 + * @param channel Which RF channel to communicate on, 0-125 */ void setChannel(uint8_t channel); diff --git a/libraries/MySensors/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino b/libraries/MySensors/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino index 34b5a9a..37c8f26 100644 --- a/libraries/MySensors/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino +++ b/libraries/MySensors/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino @@ -103,8 +103,8 @@ #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 or url. Define one or the other. +//#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com" #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 // The MQTT broker port to to open