Merge branch 'development' into development
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
Arduino
|
Arduino
|
||||||
=======
|
=======
|
||||||
|
|
||||||
MySensors Arduino Library v1.5
|
MySensors Arduino Library v2.0.0-beta
|
||||||
|
|
||||||
Please visit www.mysensors.org for more information
|
Please visit www.mysensors.org for more information
|
||||||
|
|
||||||
|
|||||||
@@ -371,7 +371,17 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @def MY_RF24_CHANNEL
|
* @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
|
#ifndef MY_RF24_CHANNEL
|
||||||
#define MY_RF24_CHANNEL 76
|
#define MY_RF24_CHANNEL 76
|
||||||
|
|||||||
@@ -85,7 +85,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Not necessary to include blinking feature if no LED's are defined!
|
// 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
|
#undef MY_LEDS_BLINKING_FEATURE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -179,9 +179,10 @@
|
|||||||
#endif
|
#endif
|
||||||
// GATEWAY - COMMON FUNCTIONS
|
// GATEWAY - COMMON FUNCTIONS
|
||||||
// We only support MQTT Client using W5100 and ESP8266 at the moment
|
// We only support MQTT Client using W5100 and ESP8266 at the moment
|
||||||
#if !defined(MY_CONTROLLER_IP_ADDRESS)
|
#if !(defined(MY_CONTROLLER_URL_ADDRESS) || defined(MY_CONTROLLER_IP_ADDRESS))
|
||||||
#error You must specify MY_CONTROLLER_IP_ADDRESS (MQTT broker address)
|
#error You must specify MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if !defined(MY_MQTT_PUBLISH_TOPIC_PREFIX)
|
#if !defined(MY_MQTT_PUBLISH_TOPIC_PREFIX)
|
||||||
#error You must specify a topic publish prefix MY_MQTT_PUBLISH_TOPIC_PREFIX for this MQTT client
|
#error You must specify a topic publish prefix MY_MQTT_PUBLISH_TOPIC_PREFIX for this MQTT client
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -156,7 +156,11 @@ bool gatewayTransportSend(MyMessage &message)
|
|||||||
ret = _ethernetServer.endPacket();
|
ret = _ethernetServer.endPacket();
|
||||||
#else
|
#else
|
||||||
EthernetClient client;
|
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.write(_ethernetMsg, strlen(_ethernetMsg));
|
||||||
client.stop();
|
client.stop();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,16 @@
|
|||||||
uint8_t protocolH2i(char c);
|
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)
|
#if defined(MY_GATEWAY_ESP8266)
|
||||||
#define EthernetClient WiFiClient
|
#define EthernetClient WiFiClient
|
||||||
IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS);
|
#if defined(MY_IP_ADDRESS)
|
||||||
IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS);
|
IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS);
|
||||||
|
IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS);
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
byte _clientMAC[] = { MY_MAC_ADDRESS };
|
byte _clientMAC[] = { MY_MAC_ADDRESS };
|
||||||
#endif
|
#endif
|
||||||
@@ -44,6 +48,7 @@ IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS);
|
|||||||
|
|
||||||
EthernetClient _ethClient;
|
EthernetClient _ethClient;
|
||||||
PubSubClient _client(_ethClient);
|
PubSubClient _client(_ethClient);
|
||||||
|
bool _connecting = true;
|
||||||
bool _available = false;
|
bool _available = false;
|
||||||
char _convBuffer[MAX_PAYLOAD*2+1];
|
char _convBuffer[MAX_PAYLOAD*2+1];
|
||||||
char _fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH];
|
char _fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH];
|
||||||
@@ -150,7 +155,13 @@ bool reconnectMQTT() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool gatewayTransportInit() {
|
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);
|
_client.setCallback(incomingMQTT);
|
||||||
|
|
||||||
#if defined(MY_GATEWAY_ESP8266)
|
#if defined(MY_GATEWAY_ESP8266)
|
||||||
@@ -164,30 +175,42 @@ bool gatewayTransportInit() {
|
|||||||
MY_SERIALDEVICE.print(".");
|
MY_SERIALDEVICE.print(".");
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
MY_SERIALDEVICE.print(F("IP: "));
|
MY_SERIALDEVICE.print("IP: ");
|
||||||
MY_SERIALDEVICE.println(WiFi.localIP());
|
MY_SERIALDEVICE.println(WiFi.localIP());
|
||||||
#else
|
#else
|
||||||
#ifdef MY_IP_ADDRESS
|
#ifdef MY_IP_ADDRESS
|
||||||
Ethernet.begin(_clientMAC, _clientIp);
|
Ethernet.begin(_clientMAC, _clientIp);
|
||||||
MY_SERIALDEVICE.print(F("IP: "));
|
|
||||||
MY_SERIALDEVICE.println(Ethernet.localIP());
|
|
||||||
#else
|
#else
|
||||||
// Get IP address from DHCP
|
// Get IP address from DHCP
|
||||||
Ethernet.begin(_clientMAC);
|
if (!Ethernet.begin(_clientMAC))
|
||||||
MY_SERIALDEVICE.print(F("IP: "));
|
{
|
||||||
|
MY_SERIALDEVICE.print("DHCP FAILURE...");
|
||||||
|
_connecting = false;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
MY_SERIALDEVICE.print("IP: ");
|
||||||
MY_SERIALDEVICE.println(Ethernet.localIP());
|
MY_SERIALDEVICE.println(Ethernet.localIP());
|
||||||
#endif /* IP_ADDRESS_DHCP */
|
#endif
|
||||||
|
|
||||||
// give the Ethernet interface a second to initialize
|
// give the Ethernet interface a second to initialize
|
||||||
// TODO: use HW delay
|
// TODO: use HW delay
|
||||||
wait(1000);
|
wait(1000);
|
||||||
#endif
|
#endif
|
||||||
|
_connecting = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool gatewayTransportAvailable() {
|
bool gatewayTransportAvailable() {
|
||||||
|
if (_connecting)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
//keep lease on dhcp address
|
||||||
|
//Ethernet.maintain();
|
||||||
if (!_client.connected()) {
|
if (!_client.connected()) {
|
||||||
reconnectMQTT();
|
//reinitialise client
|
||||||
|
if (gatewayTransportInit())
|
||||||
|
reconnectMQTT();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_client.loop();
|
_client.loop();
|
||||||
|
|||||||
@@ -123,8 +123,6 @@ void _begin() {
|
|||||||
#elif defined(MY_RADIO_FEATURE)
|
#elif defined(MY_RADIO_FEATURE)
|
||||||
// Read settings from eeprom
|
// Read settings from eeprom
|
||||||
hwReadConfigBlock((void*)&_nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
|
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
|
#ifdef MY_OTA_FIRMWARE_FEATURE
|
||||||
// Read firmware config from EEPROM, i.e. type, version, CRC, blocks
|
// Read firmware config from EEPROM, i.e. type, version, CRC, blocks
|
||||||
hwReadConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig));
|
hwReadConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig));
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ RF24::RF24(uint8_t _cepin, uint8_t _cspin):
|
|||||||
|
|
||||||
void RF24::setChannel(uint8_t channel)
|
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));
|
write_register(RF_CH,min(channel,max_channel));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -601,7 +601,7 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Set RF communication channel
|
* 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);
|
void setChannel(uint8_t channel);
|
||||||
|
|
||||||
|
|||||||
@@ -103,8 +103,8 @@
|
|||||||
#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.
|
//#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
|
||||||
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
|
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
|
||||||
|
|
||||||
// The MQTT broker port to to open
|
// The MQTT broker port to to open
|
||||||
|
|||||||
Reference in New Issue
Block a user