Skip to content

Commit 2ff7c74

Browse files
committed
moved comment and minor ops
1 parent 3af3014 commit 2ff7c74

File tree

3 files changed

+51
-54
lines changed

3 files changed

+51
-54
lines changed

MQTTGateway/MQTTGateway.ino

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
/* MyMQTT Broker Gateway 0.1b
22
3-
Created by Daniel Wiegert <[email protected]>
4-
Based on MySensors Ethernet Gateway by Henrik Ekblad <[email protected]>
5-
http://www.mysensors.org
3+
Created by Daniel Wiegert <[email protected]>
4+
Based on MySensors Ethernet Gateway by Henrik Ekblad <[email protected]>
5+
http://www.mysensors.org
66
7-
Requires MySensors lib 1.4b
7+
Requires MySensors lib 1.4b
88
9-
* Change below; TCP_IP, TCP_PORT, TCP_MAC
10-
This will listen on your selected TCP_IP:TCP_PORT below, Please change TCP_MAC your liking also.
11-
*1 -> NOTE: Keep first byte at x2, x6, xA or xE (replace x with any hex value) for using Local Ranges.
9+
* Change below; TCP_IP, TCP_PORT, TCP_MAC
10+
This will listen on your selected TCP_IP:TCP_PORT below, Please change TCP_MAC your liking also.
11+
*1 -> NOTE: Keep first byte at x2, x6, xA or xE (replace x with any hex value) for using Local Ranges.
1212
13-
*2 You can use standard pin set-up as MySensors recommends or if you own a IBOARD you may change
14-
the radio-pins below if you hardware mod your iBoard. see [URL BELOW] for more details.
15-
http://forum.mysensors.org/topic/224/iboard-cheap-single-board-ethernet-arduino-with-radio/5
13+
*2 You can use standard pin set-up as MySensors recommends or if you own a IBOARD you may change
14+
the radio-pins below if you hardware mod your iBoard. see [URL BELOW] for more details.
15+
http://forum.mysensors.org/topic/224/iboard-cheap-single-board-ethernet-arduino-with-radio/5
1616
17-
* Don't forget to look at the definitions in libraries\MySensors\MyMQTT.h!
17+
* Don't forget to look at the definitions in libraries\MySensors\MyMQTT.h!
1818
1919
define TCPDUMP and connect serial interface if you have problems, please write on
2020
http://forum.mysensors.org/ and explain your problem, include serial output. Don't forget to
@@ -29,8 +29,9 @@
2929
MQTT_SEND_SUBSCRIPTION is if you want the MyMQTT to send a empty payload message to your nodes.
3030
This can be useful if you want to send latest state back to the MQTT client. Just check if incoming
3131
message has any length or not.
32+
Example: if (msg.type==V_LIGHT && strlen(msg.getString())>0) otherwise the code might do strange things.
3233
33-
* Address-layout is : [MQTT_BROKER_PREFIX]/[NodeID]/[SensorID]/[SensorType]
34+
* Address-layout is : [MQTT_BROKER_PREFIX]/[NodeID]/[SensorID]/[SensorType]
3435
NodeID and SensorID is uint8 (0-255) number.
3536
Last segment is translation of the sensor type, look inside MyMQTT.cpp for the definitions.
3637
User can change this to their needs. We have also left some space for custom types.
@@ -39,18 +40,18 @@ Special: (sensor 255 reserved for special commands)
3940
You can receive a node sketch name with MyMQTT/20/255/Sketch_name (or version with _version)
4041
4142
To-do:
42-
Special commands : clear or set EEPROM Values, Send REBOOT and Receive reboot for MyMQTT itself.
43-
Be able to send ACK so client returns the data being sent.
44-
... Please come with ideas!
45-
46-
Test in more MQTT clients, So far tested in openhab and MyMQTT for Android (Not my creation)
47-
- http://www.openhab.org/
48-
- https://play.google.com/store/apps/details?id=at.tripwire.mqtt.client&hl=en
49-
... Please notify me if you use this broker with other software.
50-
51-
52-
* Example Openhab configuration:
53-
openhab.cfg
43+
Special commands : clear or set EEPROM Values, Send REBOOT and Receive reboot for MyMQTT itself.
44+
Be able to send ACK so client returns the data being sent.
45+
... Please come with ideas!
46+
47+
Test in more MQTT clients, So far tested in openhab and MyMQTT for Android (Not my creation)
48+
- http://www.openhab.org/
49+
- https://play.google.com/store/apps/details?id=at.tripwire.mqtt.client&hl=en
50+
... Please notify me if you use this broker with other software.
51+
52+
53+
* Example Openhab configuration:
54+
openhab.cfg
5455
---
5556
mqtt:mysensor.url=tcp://192.168.0.234:1883
5657
mqtt:mysensor.clientId=MQTT
@@ -75,7 +76,7 @@ sitemap/test.site
7576
---
7677
sitemap demo label="Menu"
7778
Frame label="Openhab" {
78-
Group item=test label="Test group"
79+
Group item=test label="Test group"
7980
}
8081
---
8182
@@ -148,7 +149,7 @@ int main(void) {
148149
delay(1000); // Wait for Ethernet to get configured.
149150
gw.begin(RF24_PA_LEVEL_GW, RF24_CHANNEL, RF24_DATARATE, writeEthernet);
150151
server.begin();
151-
// Add led timer interrupt
152+
// Add led timer interrupt
152153
if (gw.isLedMode()) {
153154
MsTimer2::set(200, ledTimersInterrupt);
154155
MsTimer2::start();
@@ -159,4 +160,3 @@ int main(void) {
159160
}
160161
}
161162

162-

libraries/MySensors/MyMQTT.cpp

+21-21
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ char S_50[] PROGMEM = "Sketch_version"; // Does not exist in MyMessage.h!
6767

6868

6969
PROGMEM const char *sType[] = {
70-
S_0, S_1, S_2, S_3, S_4, S_5, S_6, S_7, S_8, S_9, S_10,
70+
S_0, S_1, S_2, S_3, S_4, S_5, S_6, S_7, S_8, S_9, S_10,
7171
S_11, S_12, S_13, S_14, S_15, S_16, S_17, S_18, S_19, S_20,
72-
S_21, S_22, S_23, S_24, S_25, S_26, S_27, S_28, S_29, S_30,
72+
S_21, S_22, S_23, S_24, S_25, S_26, S_27, S_28, S_29, S_30,
7373
S_31, S_32, S_33, S_34, S_35, S_36, S_37, S_38, S_39, S_40,
7474
S_41, S_42, S_43, S_44, S_45, S_46, S_47, S_48, S_49, S_50
7575
};
7676

7777

78-
MyMQTT::MyMQTT(uint8_t _cepin, uint8_t _cspin, uint8_t _rx, uint8_t _tx, uint8_t _er) :
78+
MyMQTT::MyMQTT(uint8_t _cepin, uint8_t _cspin, uint8_t _rx, uint8_t _tx, uint8_t _er) :
7979
MySensor(_cepin, _cspin) {
8080
if (_rx != NULL) {
8181
pinRx = _rx;
@@ -85,7 +85,7 @@ MySensor(_cepin, _cspin) {
8585
if (_tx != NULL) {
8686
pinTx = _tx;
8787
pinMode(pinTx, OUTPUT);
88-
ledMode = true;
88+
ledMode = true;
8989
}
9090
if (_er != NULL) {
9191
pinEr = _er;
@@ -132,7 +132,7 @@ void MyMQTT::processMQTTMessage(char *inputString, int inputPos) {
132132
buffer[0]= 0;
133133
buffsize = 0;
134134
#ifdef TCPDUMP
135-
Serial.print("<<");
135+
Serial.print("<<");
136136
char buf[4];
137137
for (int a=0; a<inputPos; a++) { sprintf(buf,"%02X ",(byte)inputString[a]); Serial.print(buf); } Serial.println("");
138138
#endif
@@ -165,14 +165,14 @@ void MyMQTT::processMQTTMessage(char *inputString, int inputPos) {
165165
}
166166
if (buffsize > 0) {
167167
#ifdef TCPDUMP
168-
Serial.print(">>");
168+
Serial.print(">>");
169169
char buf[4];
170-
for (int a=0; a<buffsize; a++) { sprintf(buf,"%02X ",(byte)buffer[a]); Serial.print(buf); } Serial.println("");
170+
for (int a=0; a<buffsize; a++) { sprintf(buf,"%02X ",(byte)buffer[a]); Serial.print(buf); } Serial.println("");
171171
#endif
172172
dataCallback(buffer,&buffsize);
173173
}
174174
// We publish everything we get, we dont care if its subscribed or not!
175-
if ((byte)inputString[0] >> 4 == MQTTPUBLISH || (MQTT_SEND_SUBSCRIPTION && (byte)inputString[0] >> 4 == MQTTSUBSCRIBE)) {
175+
if ((byte)inputString[0] >> 4 == MQTTPUBLISH || (MQTT_SEND_SUBSCRIPTION && (byte)inputString[0] >> 4 == MQTTSUBSCRIBE)) {
176176
buffer[0]= 0;
177177
buffsize = 0;
178178
if ((byte)inputString[0] >> 4 == MQTTSUBSCRIBE) {
@@ -194,19 +194,19 @@ void MyMQTT::processMQTTMessage(char *inputString, int inputPos) {
194194
} else if (i==3) {
195195
char match=0;
196196
for (int j=0; strcpy_P(convBuf, (char*)pgm_read_word(&(sType[j]))) ; j++) {
197-
if (strcmp(str,convBuf)==0) {
198-
match=j;
197+
if (strcmp(str,convBuf)==0) {
198+
match=j;
199199
break;
200200
}
201-
}
201+
}
202202
msg.type = match;
203203
}
204204
i++;
205205
}
206206
if ((char)inputString[1] > (char)(inputString[3]+2) && !((byte)inputString[0] >> 4 == MQTTSUBSCRIBE)) {
207207
strcpy(convBuf,inputString+(inputString[3]+4));
208208
msg.set(convBuf);
209-
} else {
209+
} else {
210210
msg.set("");
211211
}
212212
msg.sender = GATEWAY_ADDRESS;
@@ -227,7 +227,7 @@ void MyMQTT::SendMQTT(MyMessage &msg) {
227227
if (msg.isAck()) {
228228
Serial.println("msg is ack!");
229229
if (msg.sender==255 && mGetCommand(msg)==C_INTERNAL && msg.type==I_ID_REQUEST) {
230-
// TODO: sending ACK request on id_response fucks node up. doesn't work.
230+
// TODO: sending ACK request on id_response fucks node up. doesn't work.
231231
// The idea was to confirm id and save to EEPROM_LATEST_NODE_ADDRESS.
232232
}
233233
} else {
@@ -239,11 +239,11 @@ void MyMQTT::SendMQTT(MyMessage &msg) {
239239
saveState(EEPROM_LATEST_NODE_ADDRESS,newNodeID);
240240
}
241241
if (mGetCommand(msg)==C_INTERNAL && msg.type==I_CONFIG) { // CONFIG
242-
// As for now there is only one 'config' request.
242+
// As for now there is only one 'config' request.
243243
// We force SI! Resistance is futile!
244244
//
245-
// Todo : Support for more config types, Maybe just read from own EEPROM?
246-
// Use internal EEPROM_CONTROLLER_CONFIG_ADDRESS and special MQTT address to write to
245+
// Todo : Support for more config types, Maybe just read from own EEPROM?
246+
// Use internal EEPROM_CONTROLLER_CONFIG_ADDRESS and special MQTT address to write to
247247
// EEPROM_CONTROLLER_CONFIG_ADDRESS & EEPROM_LOCAL_CONFIG_ADDRESS
248248
msg.destination = msg.sender; //NodeID
249249
msg.sender = GATEWAY_ADDRESS;
@@ -273,10 +273,10 @@ void MyMQTT::SendMQTT(MyMessage &msg) {
273273
mSetVersion(msg, PROTOCOL_VERSION);
274274
txBlink(1);
275275
if (!sendRoute(msg)) errBlink(1);
276-
// if (sendRoute(msg)) saveState(EEPROM_LATEST_NODE_ADDRESS,newNodeID); // If send OK save to eeprom. DOES NOT ALWAYS RETURN 'OK'!?
276+
// if (sendRoute(msg)) saveState(EEPROM_LATEST_NODE_ADDRESS,newNodeID); // If send OK save to eeprom. DOES NOT ALWAYS RETURN 'OK'!?
277277
} else if (mGetCommand(msg)!=0) {
278278
if (mGetCommand(msg)==3) msg.type=msg.type+38;
279-
buffer[buffsize++] = MQTTPUBLISH << 4; // 0:
279+
buffer[buffsize++] = MQTTPUBLISH << 4; // 0:
280280
buffer[buffsize++] = 0x09; // 1: Remaining length with no payload, we'll set this later to correct value, buffsize -2
281281
buffer[buffsize++] = 0x00; // 2: Length MSB (Remaing length can never exceed ff,so MSB must be 0!)
282282
buffer[buffsize++] = 0x08; // 3: Length LSB (ADDR), We'll set this later
@@ -297,11 +297,11 @@ void MyMQTT::SendMQTT(MyMessage &msg) {
297297
#ifdef TCPDUMP
298298
Serial.print(">>");
299299
char buf[4];
300-
for (int a=0; a<buffsize; a++) { sprintf(buf,"%02X ",(byte)buffer[a]); Serial.print(buf); } Serial.println("");
300+
for (int a=0; a<buffsize; a++) { sprintf(buf,"%02X ",(byte)buffer[a]); Serial.print(buf); } Serial.println("");
301301
#endif
302302
dataCallback(buffer,&buffsize);
303303
}
304-
}
304+
}
305305
}
306306

307307
boolean MyMQTT::isLedMode() {
@@ -350,7 +350,7 @@ void MyMQTT::errBlink(uint8_t cnt) {
350350
char MyMQTT::strncpysType_retL(char *str, char index, char start) {
351351
char c;
352352
char l;
353-
char *p = (char *)pgm_read_word(&(sType[index]));
353+
char *p = (char *)pgm_read_word(&(sType[index]));
354354
str+=start;
355355
while ((c = pgm_read_byte(p))) {
356356
*str=c;

libraries/MySensors/MyMQTT.h

+3-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ version 2 as published by the Free Software Foundation.
1818
///////////////////////////////////////////////////////////////////////////////////
1919

2020
#ifdef DEBUG
21-
//#define TCPDUMP // Dump TCP packages.
21+
#define TCPDUMP // Dump TCP packages.
2222
#endif
2323

2424
#define MQTT_FIRST_SENSORID 20 // If you want manually configured nodes below this value. 255 = Disable
@@ -54,9 +54,7 @@ version 2 as published by the Free Software Foundation.
5454
#define MQTTQOS1 (1 << 1)
5555
#define MQTTQOS2 (2 << 1)
5656

57-
#define MyTestVar F("Test")
58-
59-
class MyMQTT :
57+
class MyMQTT :
6058
public MySensor {
6159
public:
6260
MyMQTT(uint8_t _cepin=5, uint8_t _cspin=6, uint8_t _rx=NULL, uint8_t _tx=NULL, uint8_t _er=NULL);
@@ -74,7 +72,7 @@ public MySensor {
7472
void (*dataCallback)(char *, int *);
7573
void SendMQTT(MyMessage &msg);
7674
char strncpysType_retL(char *str, char index, char start);
77-
75+
7876
volatile uint8_t countRx;
7977
volatile uint8_t countTx;
8078
volatile uint8_t countErr;
@@ -91,4 +89,3 @@ public MySensor {
9189

9290

9391
#endif
94-

0 commit comments

Comments
 (0)