Skip to content

Commit b599f1f

Browse files
committed
Create MyMQTT.h
MQTTGateway beta 0.1
1 parent 9eca431 commit b599f1f

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

libraries/MySensors/MyMQTT.h

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
The MySensors library adds a new layer on top of the RF24 library.
3+
It handles radio network routing, relaying and ids.
4+
5+
Created by Henrik Ekblad <[email protected]>
6+
Modified by Daniel Wiegert
7+
This program is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU General Public License
9+
version 2 as published by the Free Software Foundation.
10+
*/
11+
12+
#ifndef MyMQTT_h
13+
#define MyMQTT_h
14+
15+
#include "MySensor.h"
16+
17+
18+
///////////////////////////////////////////////////////////////////////////////////
19+
20+
#ifdef DEBUG
21+
#define TCPDUMP // Dump TCP packages.
22+
#endif
23+
24+
#define MQTT_FIRST_SENSORID 20 // If you want manually configured nodes below this value.
25+
#define MQTT_LAST_SENSORID 254 // 254 is max! 255 reserved.
26+
#define MQTT_BROKER_PREFIX "MyMQTT" // First prefix in MQTT tree, keep short!
27+
#define MQTT_SEND_SUBSCRIPTION 1 // Send empty payload (request) to node upon MQTT client subscribe request.
28+
// NOTE above : Beware to check if there is any length on payload in your incommingMessage code:
29+
// Example: if (msg.type==V_LIGHT && strlen(msg.getString())>0) otherwise the code might do strange things.
30+
31+
///////////////////////////////////////////////////////////////////////////////////
32+
33+
#define EEPROM_LATEST_NODE_ADDRESS EEPROM_LOCAL_CONFIG_ADDRESS+0
34+
#define MQTT_MAX_PACKET_SIZE 100
35+
36+
#define MQTTPROTOCOLVERSION 3
37+
#define MQTTCONNECT 1 // Client request to connect to Server
38+
#define MQTTCONNACK 2 // Connect Acknowledgment
39+
#define MQTTPUBLISH 3 // Publish message
40+
#define MQTTPUBACK 4 // Publish Acknowledgment
41+
#define MQTTPUBREC 5 // Publish Received (assured delivery part 1)
42+
#define MQTTPUBREL 6 // Publish Release (assured delivery part 2)
43+
#define MQTTPUBCOMP 7 // Publish Complete (assured delivery part 3)
44+
#define MQTTSUBSCRIBE 8 // Client Subscribe request
45+
#define MQTTSUBACK 9 // Subscribe Acknowledgment
46+
#define MQTTUNSUBSCRIBE 10 // Client Unsubscribe request
47+
#define MQTTUNSUBACK 11 // Unsubscribe Acknowledgment
48+
#define MQTTPINGREQ 12 // PING Request
49+
#define MQTTPINGRESP 13 // PING Response
50+
#define MQTTDISCONNECT 14 // Client is Disconnecting
51+
#define MQTTReserved 15 // Reserved
52+
53+
#define MQTTQOS0 (0 << 1)
54+
#define MQTTQOS1 (1 << 1)
55+
#define MQTTQOS2 (2 << 1)
56+
57+
class MyMQTT :
58+
public MySensor {
59+
public:
60+
MyMQTT(uint8_t _cepin=9, uint8_t _cspin=10);
61+
62+
void begin(rf24_pa_dbm_e paLevel=RF24_PA_LEVEL_GW, uint8_t channel=RF24_CHANNEL, rf24_datarate_e dataRate=RF24_DATARATE, void (*dataCallback)(char *, int *)=NULL);
63+
void processRadioMessage();
64+
void processMQTTMessage(char *inputString, int inputPos);
65+
66+
private:
67+
bool MQTTClient;
68+
char buffer[MQTT_MAX_PACKET_SIZE];
69+
int buffsize;
70+
char convBuf[MAX_PAYLOAD*2+1];
71+
boolean useWriteCallback;
72+
void (*dataCallback)(char *, int *);
73+
void SendMQTT(MyMessage &msg);
74+
char strncpysType_retL(char *str, char index, char start);
75+
};
76+
77+
78+
79+
#endif
80+

0 commit comments

Comments
 (0)