Skip to content

Commit 4c3d700

Browse files
committed
Merge pull request arduino#375 from mysensors/bring-old-prs-up-to-date
Bring old prs up to date
2 parents 4b90e15 + 242d0a9 commit 4c3d700

File tree

9 files changed

+59
-23
lines changed

9 files changed

+59
-23
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Arduino
22
=======
33

4-
MySensors Arduino Library v1.5
4+
MySensors Arduino Library v2.0.0-beta
55

66
Please visit www.mysensors.org for more information
77

libraries/MySensors/MyConfig.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,17 @@
371371

372372
/**
373373
* @def MY_RF24_CHANNEL
374-
* @brief RF channel for the sensor net, 0-127.
374+
* @brief RF channel for the sensor net, 0-125.
375+
* Frequence: 2400 Mhz - 2525 Mhz Channels: 126
376+
* http://www.mysensors.org/radio/nRF24L01Plus.pdf
377+
* 0 => 2400 Mhz (RF24 channel 1)
378+
* 1 => 2401 Mhz (RF24 channel 2)
379+
* 76 => 2476 Mhz (RF24 channel 77)
380+
* 83 => 2483 Mhz (RF24 channel 84)
381+
* 124 => 2524 Mhz (RF24 channel 125)
382+
* 125 => 2525 Mhz (RF24 channel 126)
383+
* In some countries there might be limitations, in Germany for example only the range 2400,0 - 2483,5 Mhz is allowed
384+
* http://www.bundesnetzagentur.de/SharedDocs/Downloads/DE/Sachgebiete/Telekommunikation/Unternehmen_Institutionen/Frequenzen/Allgemeinzuteilungen/2013_10_WLAN_2,4GHz_pdf.pdf
375385
*/
376386
#ifndef MY_RF24_CHANNEL
377387
#define MY_RF24_CHANNEL 76

libraries/MySensors/MySensor.h

+4-3
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
#endif
8686

8787
// Not necessary to include blinking feature if no LED's are defined!
88-
#if defined(MY_LEDS_BLINKING_FEATURE) && !defined(MY_DEFAULT_RX_LED_PIN) && !defined(MU_DEFAULT_TX_LED_PIN) && !defined(MY_ERR_LED_PIN)
88+
#if defined(MY_LEDS_BLINKING_FEATURE) && !defined(MY_DEFAULT_RX_LED_PIN) && !defined(MY_DEFAULT_TX_LED_PIN) && !defined(MY_ERR_LED_PIN)
8989
#undef MY_LEDS_BLINKING_FEATURE
9090
#endif
9191

@@ -179,9 +179,10 @@
179179
#endif
180180
// GATEWAY - COMMON FUNCTIONS
181181
// We only support MQTT Client using W5100 and ESP8266 at the moment
182-
#if !defined(MY_CONTROLLER_IP_ADDRESS)
183-
#error You must specify MY_CONTROLLER_IP_ADDRESS (MQTT broker address)
182+
#if !(defined(MY_CONTROLLER_URL_ADDRESS) || defined(MY_CONTROLLER_IP_ADDRESS))
183+
#error You must specify MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS
184184
#endif
185+
185186
#if !defined(MY_MQTT_PUBLISH_TOPIC_PREFIX)
186187
#error You must specify a topic publish prefix MY_MQTT_PUBLISH_TOPIC_PREFIX for this MQTT client
187188
#endif

libraries/MySensors/core/MyGatewayTransportEthernet.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,11 @@ bool gatewayTransportSend(MyMessage &message)
156156
ret = _ethernetServer.endPacket();
157157
#else
158158
EthernetClient client;
159-
if (client.connect(_ethernetControllerIP, MY_PORT)) {
159+
#if defined(MY_CONTROLLER_URL_ADDRESS)
160+
if (client.connect(MY_CONTROLLER_URL_ADDRESS, MY_PORT)) {
161+
#else
162+
if (client.connect(_ethernetControllerIP, MY_PORT)) {
163+
#endif
160164
client.write(_ethernetMsg, strlen(_ethernetMsg));
161165
client.stop();
162166
}

libraries/MySensors/core/MyGatewayTransportMQTTClient.cpp

+34-11
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,16 @@
2828
uint8_t protocolH2i(char c);
2929

3030

31-
IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS);
31+
#if defined MY_CONTROLLER_IP_ADDRESS
32+
IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS);
33+
#endif
3234

3335
#if defined(MY_GATEWAY_ESP8266)
3436
#define EthernetClient WiFiClient
35-
IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS);
36-
IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS);
37+
#if defined(MY_IP_ADDRESS)
38+
IPAddress _gatewayIp(MY_IP_GATEWAY_ADDRESS);
39+
IPAddress _subnetIp(MY_IP_SUBNET_ADDRESS);
40+
#endif
3741
#else
3842
byte _clientMAC[] = { MY_MAC_ADDRESS };
3943
#endif
@@ -44,6 +48,7 @@ IPAddress _brokerIp(MY_CONTROLLER_IP_ADDRESS);
4448

4549
EthernetClient _ethClient;
4650
PubSubClient _client(_ethClient);
51+
bool _connecting = true;
4752
bool _available = false;
4853
char _convBuffer[MAX_PAYLOAD*2+1];
4954
char _fmtBuffer[MY_GATEWAY_MAX_SEND_LENGTH];
@@ -150,7 +155,13 @@ bool reconnectMQTT() {
150155
}
151156

152157
bool gatewayTransportInit() {
153-
_client.setServer(_brokerIp, MY_PORT);
158+
_connecting = true;
159+
#if defined(MY_CONTROLLER_IP_ADDRESS)
160+
_client.setServer(_brokerIp, MY_PORT);
161+
#else
162+
_client.setServer(MY_CONTROLLER_URL_ADDRESS, MY_PORT);
163+
#endif
164+
154165
_client.setCallback(incomingMQTT);
155166

156167
#if defined(MY_GATEWAY_ESP8266)
@@ -164,30 +175,42 @@ bool gatewayTransportInit() {
164175
MY_SERIALDEVICE.print(".");
165176
yield();
166177
}
167-
MY_SERIALDEVICE.print(F("IP: "));
178+
MY_SERIALDEVICE.print("IP: ");
168179
MY_SERIALDEVICE.println(WiFi.localIP());
169180
#else
170181
#ifdef MY_IP_ADDRESS
171182
Ethernet.begin(_clientMAC, _clientIp);
172-
MY_SERIALDEVICE.print(F("IP: "));
173-
MY_SERIALDEVICE.println(Ethernet.localIP());
174183
#else
175184
// Get IP address from DHCP
176-
Ethernet.begin(_clientMAC);
177-
MY_SERIALDEVICE.print(F("IP: "));
185+
if (!Ethernet.begin(_clientMAC))
186+
{
187+
MY_SERIALDEVICE.print("DHCP FAILURE...");
188+
_connecting = false;
189+
return false;
190+
}
191+
MY_SERIALDEVICE.print("IP: ");
178192
MY_SERIALDEVICE.println(Ethernet.localIP());
179-
#endif /* IP_ADDRESS_DHCP */
193+
#endif
194+
180195
// give the Ethernet interface a second to initialize
181196
// TODO: use HW delay
182197
wait(1000);
183198
#endif
199+
_connecting = false;
184200
return true;
185201
}
186202

187203

188204
bool gatewayTransportAvailable() {
205+
if (_connecting)
206+
return false;
207+
208+
//keep lease on dhcp address
209+
//Ethernet.maintain();
189210
if (!_client.connected()) {
190-
reconnectMQTT();
211+
//reinitialise client
212+
if (gatewayTransportInit())
213+
reconnectMQTT();
191214
return false;
192215
}
193216
_client.loop();

libraries/MySensors/core/MySensorCore.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ void _begin() {
123123
#elif defined(MY_RADIO_FEATURE)
124124
// Read settings from eeprom
125125
hwReadConfigBlock((void*)&_nc, (void*)EEPROM_NODE_ID_ADDRESS, sizeof(NodeConfig));
126-
// Read latest received controller configuration from EEPROM
127-
hwReadConfigBlock((void*)&_cc, (void*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
128126
#ifdef MY_OTA_FIRMWARE_FEATURE
129127
// Read firmware config from EEPROM, i.e. type, version, CRC, blocks
130128
hwReadConfigBlock((void*)&_fc, (void*)EEPROM_FIRMWARE_TYPE_ADDRESS, sizeof(NodeFirmwareConfig));

libraries/MySensors/drivers/RF24/RF24.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ RF24::RF24(uint8_t _cepin, uint8_t _cspin):
388388

389389
void RF24::setChannel(uint8_t channel)
390390
{
391-
const uint8_t max_channel = 127;
391+
const uint8_t max_channel = 125;
392392
write_register(RF_CH,min(channel,max_channel));
393393
}
394394

libraries/MySensors/drivers/RF24/RF24.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ class RF24
601601
/**
602602
* Set RF communication channel
603603
*
604-
* @param channel Which RF channel to communicate on, 0-127
604+
* @param channel Which RF channel to communicate on, 0-125
605605
*/
606606
void setChannel(uint8_t channel);
607607

libraries/MySensors/examples/GatewayW5100MQTTClient/GatewayW5100MQTTClient.ino

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@
103103
#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
104104
#define MY_IP_SUBNET_ADDRESS 255,255,255,0
105105

106-
107-
// MQTT broker ip address.
106+
// MQTT broker ip address or url. Define one or the other.
107+
//#define MY_CONTROLLER_URL_ADDRESS "m20.cloudmqtt.com"
108108
#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68
109109

110110
// The MQTT broker port to to open

0 commit comments

Comments
 (0)