mirror of
https://github.com/eclipse/paho.mqtt-sn.embedded-c.git
synced 2025-12-13 23:46:51 +01:00
Add: Two Gateway Test programs
BugFix: invalid pointer Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
This commit is contained in:
@@ -66,7 +66,7 @@
|
|||||||
</toolChain>
|
</toolChain>
|
||||||
</folderInfo>
|
</folderInfo>
|
||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
<entry excluding="MQTTSNGateway/src/linux/udp|MQTTSNGateway/src/tests|MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples/mainTest.cpp|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/src/tests/mainTestProcessFramework.cpp|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNPacket/test|MQTTSNPacket/samples" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
<entry excluding="MQTTSNGateway/src/linux/xbee|MQTTSNGateway/src/linux/udp6|MQTTSNGateway/src/tests|MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples/mainTest.cpp|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/src/tests/mainTestProcessFramework.cpp|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNPacket/test|MQTTSNPacket/samples" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||||
</sourceEntries>
|
</sourceEntries>
|
||||||
</configuration>
|
</configuration>
|
||||||
</storageModule>
|
</storageModule>
|
||||||
@@ -138,7 +138,7 @@
|
|||||||
<sourceEntries>
|
<sourceEntries>
|
||||||
<entry excluding="MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples/mainTest.cpp|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNPacket/src|MQTTSNGateway/src|MQTTSNGateway/src/linux|MQTTSNGateway/src/linux/udp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNPacket/test|MQTTSNPacket/samples" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
<entry excluding="MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples/mainTest.cpp|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNPacket/src|MQTTSNGateway/src|MQTTSNGateway/src/linux|MQTTSNGateway/src/linux/udp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNPacket/test|MQTTSNPacket/samples" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name=""/>
|
||||||
<entry excluding="tests|tests/mainTestProcessFramework.cpp|mainLogmonitor.cpp|linux|linux/udp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src"/>
|
<entry excluding="tests|tests/mainTestProcessFramework.cpp|mainLogmonitor.cpp|linux|linux/udp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src"/>
|
||||||
<entry excluding="udp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src/linux"/>
|
<entry excluding="xbee|udp6" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/src/linux"/>
|
||||||
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket/src"/>
|
<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket/src"/>
|
||||||
</sourceEntries>
|
</sourceEntries>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -1,12 +1,18 @@
|
|||||||
PROGNAME := MQTT-SNGatewayTester
|
PROGTEST := MQTT-SNGatewayTester
|
||||||
APPL := mainTest
|
TESTAPPL := mainTest
|
||||||
|
|
||||||
|
PRGPUB := MQTT-SNPub
|
||||||
|
PUBAPPL := mainPub
|
||||||
|
|
||||||
|
PRGSUB := MQTT-SNSub
|
||||||
|
SUBAPPL := mainSub
|
||||||
|
|
||||||
SRCDIR := samples
|
SRCDIR := samples
|
||||||
|
SRCPUB := ClientPub
|
||||||
|
SRCSUB := ClientSub
|
||||||
SUBDIR := src
|
SUBDIR := src
|
||||||
|
|
||||||
CPPSRCS := \
|
CPPSRCS := \
|
||||||
$(SRCDIR)/$(APPL).cpp \
|
|
||||||
$(SUBDIR)/LGwProxy.cpp \
|
$(SUBDIR)/LGwProxy.cpp \
|
||||||
$(SUBDIR)/LMqttsnClient.cpp \
|
$(SUBDIR)/LMqttsnClient.cpp \
|
||||||
$(SUBDIR)/LNetworkUdp.cpp \
|
$(SUBDIR)/LNetworkUdp.cpp \
|
||||||
@@ -19,7 +25,9 @@ $(SUBDIR)/LTopicTable.cpp \
|
|||||||
$(SUBDIR)/LScreen.cpp \
|
$(SUBDIR)/LScreen.cpp \
|
||||||
$(SUBDIR)/Payload.cpp \
|
$(SUBDIR)/Payload.cpp \
|
||||||
$(SUBDIR)/Util.cpp \
|
$(SUBDIR)/Util.cpp \
|
||||||
|
#$(SRCDIR)/$(TESTAPPL).cpp \
|
||||||
|
#$(SRCDIR)/$(SRCPUB)/$(PUBAPPL).cpp \
|
||||||
|
#$(SRCDIR)/$(SRCSUB)/$(SUBAPPL).cpp \
|
||||||
|
|
||||||
CXX := g++
|
CXX := g++
|
||||||
CPPFLAGS +=
|
CPPFLAGS +=
|
||||||
@@ -32,21 +40,29 @@ CXXFLAGS := -Wall -O3 -std=c++11
|
|||||||
LDADD :=
|
LDADD :=
|
||||||
OUTDIR := Build
|
OUTDIR := Build
|
||||||
|
|
||||||
PROG := $(OUTDIR)/$(PROGNAME)
|
PROG := $(OUTDIR)/$(PROGTEST)
|
||||||
OBJS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.o)
|
OBJS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.o)
|
||||||
DEPS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.d)
|
DEPS := $(CPPSRCS:%.cpp=$(OUTDIR)/%.d)
|
||||||
|
|
||||||
|
PROGPUB := $(OUTDIR)/$(PRGPUB)
|
||||||
|
PROGSUB := $(OUTDIR)/$(PRGSUB)
|
||||||
|
|
||||||
.PHONY: install clean
|
.PHONY: install clean
|
||||||
|
|
||||||
all: $(PROG)
|
all: $(PROG) $(PROGPUB) $(PROGSUB)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
-include $(DEPS)
|
-include $(DEPS)
|
||||||
|
|
||||||
$(PROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(APPL).o
|
$(PROG): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(TESTAPPL).o
|
||||||
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) $(LDADD)
|
$(CXX) $(LDFLAGS) -o $(PROG) $(OUTDIR)/$(SRCDIR)/$(TESTAPPL).o $(OBJS) $(LIBS) $(LDADD)
|
||||||
|
|
||||||
|
$(PROGPUB): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(SRCPUB)/$(PUBAPPL).o
|
||||||
|
$(CXX) $(LDFLAGS) -o $(PROGPUB) $(OUTDIR)/$(SRCDIR)/$(SRCPUB)/$(PUBAPPL).o $(OBJS) $(LIBS) $(LDADD)
|
||||||
|
|
||||||
|
$(PROGSUB): $(OBJS) $(OUTDIR)/$(SRCDIR)/$(SRCSUB)/$(SUBAPPL).o
|
||||||
|
$(CXX) $(LDFLAGS) -o $(PROGSUB) $(OUTDIR)/$(SRCDIR)/$(SRCSUB)/$(SUBAPPL).o $(OBJS) $(LIBS) $(LDADD)
|
||||||
|
|
||||||
|
|
||||||
$(OUTDIR)/$(SUBDIR)/%.o:$(SUBDIR)/%.cpp
|
$(OUTDIR)/$(SUBDIR)/%.o:$(SUBDIR)/%.cpp
|
||||||
@@ -57,13 +73,19 @@ $(OUTDIR)/$(SRCDIR)/%.o:$(SRCDIR)/%.cpp
|
|||||||
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
|
|
||||||
|
$(OUTDIR)/$(SRCDIR)/$(SRCPUB)/%.o:$(SRCDIR)/$(SRCPUB)%.cpp
|
||||||
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
|
|
||||||
|
$(OUTDIR)/$(SRCDIR)/$(SRCSUB)/%.o:$(SRCDIR)/$(SRCSUB)%.cpp
|
||||||
|
@if [ ! -e `dirname $@` ]; then mkdir -p `dirname $@`; fi
|
||||||
|
$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) $(DEFS) -o $@ -c -MMD -MP -MF $(@:%.o=%.d) $<
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf $(OUTDIR)
|
rm -rf $(OUTDIR)
|
||||||
|
|
||||||
install:
|
install:
|
||||||
cp -pf $(PROG) ../../../
|
cp -pf $(PROG) ../../../
|
||||||
|
cp -pf $(PROGPUB) ../../../
|
||||||
|
cp -pf $(PROGSUB) ../../../
|
||||||
|
|
||||||
|
|||||||
157
MQTTSNGateway/GatewayTester/samples/ClientPub/mainPub.cpp
Normal file
157
MQTTSNGateway/GatewayTester/samples/ClientPub/mainPub.cpp
Normal file
@@ -0,0 +1,157 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
*---------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* MQTT-SN GATEWAY TEST CLIENT
|
||||||
|
*
|
||||||
|
* Supported functions.
|
||||||
|
*
|
||||||
|
* void PUBLISH ( const char* topicName, uint8_t* payload,
|
||||||
|
* uint16_t len, uint8_t qos, bool retain = false );
|
||||||
|
*
|
||||||
|
* void PUBLISH ( uint16_t topicId, uint8_t* payload,
|
||||||
|
* uint16_t len, uint8_t qos, bool retain = false );
|
||||||
|
*
|
||||||
|
* void SUBSCRIBE ( const char* topicName, TopicCallback onPublish,
|
||||||
|
* uint8_t qos );
|
||||||
|
*
|
||||||
|
* void UNSUBSCRIBE( const char* topicName );
|
||||||
|
*
|
||||||
|
* void DISCONNECT ( uint16_t sleepInSecs );
|
||||||
|
*
|
||||||
|
* void CONNECT ( void );
|
||||||
|
*
|
||||||
|
* void DISPLAY( format, .....); <== instead of printf()
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "LMqttsnClientApp.h"
|
||||||
|
#include "LMqttsnClient.h"
|
||||||
|
#include "LScreen.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace linuxAsyncClient;
|
||||||
|
extern LMqttsnClient* theClient;
|
||||||
|
extern LScreen* theScreen;
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* UDP Configuration (theNetcon)
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
UDPCONF = {
|
||||||
|
"GatewayTestPubClient", // ClientId
|
||||||
|
{225,1,1,1}, // Multicast group IP
|
||||||
|
1883, // Multicast group Port
|
||||||
|
20001, // Local PortNo
|
||||||
|
};
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Client Configuration (theMqcon)
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
MQTTSNCONF = {
|
||||||
|
300, //KeepAlive [seconds]
|
||||||
|
true, //Clean session
|
||||||
|
300, //Sleep duration [seconds]
|
||||||
|
"", //WillTopic
|
||||||
|
"", //WillMessage
|
||||||
|
0, //WillQos
|
||||||
|
false //WillRetain
|
||||||
|
};
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Define Topics
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
const char* topic1 = "ty4tw/topic1";
|
||||||
|
const char* topic2 = "ty4tw/topic2";
|
||||||
|
const char* topic3 = "ty4tw/topic3";
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Callback routines for Subscribed Topics
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* A Link list of Callback routines and Topics
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
|
SUBSCRIBE_LIST = {// e.g. SUB(topic, callback, QoS),
|
||||||
|
END_OF_SUBSCRIBE_LIST
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Test functions
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
|
void publishTopic1(void)
|
||||||
|
{
|
||||||
|
char payload[300];
|
||||||
|
sprintf(payload, "publish \"ty4tw/Topic1\" \n");
|
||||||
|
uint8_t qos = 0;
|
||||||
|
PUBLISH(topic1,(uint8_t*)payload, strlen(payload), qos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void publishTopic2(void)
|
||||||
|
{
|
||||||
|
char payload[300];
|
||||||
|
sprintf(payload, "publish \"ty4tw/topic2\" \n");
|
||||||
|
uint8_t qos = 0;
|
||||||
|
PUBLISH(topic2,(uint8_t*)payload, strlen(payload), qos);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void disconnect(void)
|
||||||
|
{
|
||||||
|
DISCONNECT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* A List of Test functions is valid in case of
|
||||||
|
* line 23 of LMqttsnClientApp.h is commented out.
|
||||||
|
* //#define CLIENT_MODE
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
|
TEST_LIST = {// e.g. TEST( Label, Test),
|
||||||
|
TEST("Step1:Publish topic1", publishTopic1),
|
||||||
|
TEST("Step2:Publish topic2", publishTopic2),
|
||||||
|
TEST("Step3:Publish topic2", publishTopic2),
|
||||||
|
TEST("Step4:Disconnect", disconnect),
|
||||||
|
END_OF_TEST_LIST
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* List of tasks is valid in case of line23 of
|
||||||
|
* LMqttsnClientApp.h is uncommented.
|
||||||
|
* #define CLIENT_MODE
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
TASK_LIST = {// e.g. TASK( task, executing duration in second),
|
||||||
|
TASK(publishTopic1, 4), // publishTopic1() is executed every 4 seconds
|
||||||
|
TASK(publishTopic2, 7), // publishTopic2() is executed every 7 seconds
|
||||||
|
END_OF_TASK_LIST
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Initialize function
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
void setup(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************** END OF PROGRAM ********************/
|
||||||
188
MQTTSNGateway/GatewayTester/samples/ClientSub/mainSub.cpp
Normal file
188
MQTTSNGateway/GatewayTester/samples/ClientSub/mainSub.cpp
Normal file
@@ -0,0 +1,188 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* Copyright (c) 2016, Tomoaki Yamaguchi
|
||||||
|
*
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* and Eclipse Distribution License v1.0 which accompany this distribution.
|
||||||
|
*
|
||||||
|
* The Eclipse Public License is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
* and the Eclipse Distribution License is available at
|
||||||
|
* http://www.eclipse.org/org/documents/edl-v10.php.
|
||||||
|
*
|
||||||
|
*---------------------------------------------------------------------------
|
||||||
|
*
|
||||||
|
* MQTT-SN GATEWAY TEST CLIENT
|
||||||
|
*
|
||||||
|
* Supported functions.
|
||||||
|
*
|
||||||
|
* void PUBLISH ( const char* topicName, uint8_t* payload,
|
||||||
|
* uint16_t len, uint8_t qos, bool retain = false );
|
||||||
|
*
|
||||||
|
* void PUBLISH ( uint16_t topicId, uint8_t* payload,
|
||||||
|
* uint16_t len, uint8_t qos, bool retain = false );
|
||||||
|
*
|
||||||
|
* void SUBSCRIBE ( const char* topicName, TopicCallback onPublish,
|
||||||
|
* uint8_t qos );
|
||||||
|
*
|
||||||
|
* void UNSUBSCRIBE( const char* topicName );
|
||||||
|
*
|
||||||
|
* void DISCONNECT ( uint16_t sleepInSecs );
|
||||||
|
*
|
||||||
|
* void CONNECT ( void );
|
||||||
|
*
|
||||||
|
* void DISPLAY( format, .....); <== instead of printf()
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Tomoaki Yamaguchi - initial API and implementation
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#include "LMqttsnClientApp.h"
|
||||||
|
#include "LMqttsnClient.h"
|
||||||
|
#include "LScreen.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
using namespace linuxAsyncClient;
|
||||||
|
extern LMqttsnClient* theClient;
|
||||||
|
extern LScreen* theScreen;
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* UDP Configuration (theNetcon)
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
UDPCONF = {
|
||||||
|
"ty4twGatewaySubClient", // ClientId
|
||||||
|
{225,1,1,1}, // Multicast group IP
|
||||||
|
1883, // Multicast group Port
|
||||||
|
20002, // Local PortNo
|
||||||
|
};
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Client Configuration (theMqcon)
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
MQTTSNCONF = {
|
||||||
|
300, //KeepAlive [seconds]
|
||||||
|
false, //Clean session
|
||||||
|
300, //Sleep duration [seconds]
|
||||||
|
"", //WillTopic
|
||||||
|
"", //WillMessage
|
||||||
|
0, //WillQos
|
||||||
|
false //WillRetain
|
||||||
|
};
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Define Topics
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
const char* topic1 = "ty4tw/topic1";
|
||||||
|
const char* topic2 = "ty4tw/topic2";
|
||||||
|
const char* topic3 = "ty4tw/topic3";
|
||||||
|
const char* topic4 = "a";
|
||||||
|
const char* topic5 = "#";
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Callback routines for Subscribed Topics
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
int on_Topic01(uint8_t* pload, uint16_t ploadlen)
|
||||||
|
{
|
||||||
|
DISPLAY("\n\nTopic1 recv.\n");
|
||||||
|
char c = pload[ploadlen-1];
|
||||||
|
pload[ploadlen-1]= 0; // set null terminator
|
||||||
|
DISPLAY("Payload -->%s%c<--\n\n",pload, c);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int on_Topic02(uint8_t* pload, uint16_t ploadlen)
|
||||||
|
{
|
||||||
|
DISPLAY("\n\nTopic2 recv.\n");
|
||||||
|
pload[ploadlen-1]= 0; // set null terminator
|
||||||
|
DISPLAY("Payload -->%s <--\n\n",pload);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int on_Topic03(uint8_t* pload, uint16_t ploadlen)
|
||||||
|
{
|
||||||
|
DISPLAY("\n\nNew callback recv TopicA\n");
|
||||||
|
pload[ploadlen-1]= 0; // set null terminator
|
||||||
|
DISPLAY("Payload -->%s <--\n\n",pload);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* A Link list of Callback routines and Topics
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
|
SUBSCRIBE_LIST = {// e.g. SUB(topic, callback, QoS),
|
||||||
|
//SUB(topic1, on_Topic01, 1),
|
||||||
|
//SUB(topic4, on_Topic03, 1),
|
||||||
|
END_OF_SUBSCRIBE_LIST
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Test functions
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
|
void subscribeTopic1(void)
|
||||||
|
{
|
||||||
|
uint8_t qos = 1;
|
||||||
|
SUBSCRIBE(topic1, on_Topic01, qos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void subscribeTopic2(void)
|
||||||
|
{
|
||||||
|
uint8_t qos = 1;
|
||||||
|
SUBSCRIBE(topic2, on_Topic02, qos);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void disconnect(void)
|
||||||
|
{
|
||||||
|
DISCONNECT(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void connect(void)
|
||||||
|
{
|
||||||
|
CONNECT();
|
||||||
|
}
|
||||||
|
|
||||||
|
void asleep(void)
|
||||||
|
{
|
||||||
|
DISCONNECT(theMqcon.sleepDuration);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* A List of Test functions is valid in case of
|
||||||
|
* line 23 of LMqttsnClientApp.h is commented out.
|
||||||
|
* //#define CLIENT_MODE
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
|
||||||
|
TEST_LIST = {// e.g. TEST( Label, Test),
|
||||||
|
TEST("Step1:Subscribe topic1", subscribeTopic1),
|
||||||
|
//TEST("Step2:Subscribe topic2", subscribeTopic2),
|
||||||
|
TEST("Step2:Disconnect", disconnect),
|
||||||
|
END_OF_TEST_LIST
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* List of tasks is valid in case of line23 of
|
||||||
|
* LMqttsnClientApp.h is uncommented.
|
||||||
|
* #define CLIENT_MODE
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
TASK_LIST = {// e.g. TASK( task, executing duration in second),
|
||||||
|
END_OF_TASK_LIST
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/*------------------------------------------------------
|
||||||
|
* Initialize function
|
||||||
|
*------------------------------------------------------*/
|
||||||
|
void setup(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***************** END OF PROGRAM ********************/
|
||||||
@@ -29,6 +29,8 @@
|
|||||||
*
|
*
|
||||||
* void DISCONNECT ( uint16_t sleepInSecs );
|
* void DISCONNECT ( uint16_t sleepInSecs );
|
||||||
*
|
*
|
||||||
|
* void CONNECT ( void );
|
||||||
|
*
|
||||||
* void DISPLAY( format, .....); <== instead of printf()
|
* void DISPLAY( format, .....); <== instead of printf()
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ LGwProxy::LGwProxy(){
|
|||||||
_connectRetry = MQTTSN_RETRY_COUNT;
|
_connectRetry = MQTTSN_RETRY_COUNT;
|
||||||
_tSleep = 0;
|
_tSleep = 0;
|
||||||
_tWake = 0;
|
_tWake = 0;
|
||||||
|
_initialized = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
LGwProxy::~LGwProxy(){
|
LGwProxy::~LGwProxy(){
|
||||||
@@ -72,6 +73,7 @@ void LGwProxy::initialize(LUdpConfig netconf, LMqttsnConfig mqconf){
|
|||||||
_retainWill = mqconf.willRetain;
|
_retainWill = mqconf.willRetain;
|
||||||
_cleanSession = mqconf.cleanSession;
|
_cleanSession = mqconf.cleanSession;
|
||||||
_tkeepAlive = mqconf.keepAlive;
|
_tkeepAlive = mqconf.keepAlive;
|
||||||
|
_initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LGwProxy::connect(){
|
void LGwProxy::connect(){
|
||||||
@@ -170,8 +172,13 @@ int LGwProxy::getConnectResponce(void){
|
|||||||
_tSleep = 0;
|
_tSleep = 0;
|
||||||
}else{
|
}else{
|
||||||
DISPLAY("\033[0m\033[0;32m\n\n Connected to the Broker\033[0m\033[0;37m\n\n");
|
DISPLAY("\033[0m\033[0;32m\n\n Connected to the Broker\033[0m\033[0;37m\n\n");
|
||||||
_topicTbl.clearTopic();
|
|
||||||
theClient->onConnect(); // SUBSCRIBEs are conducted
|
if ( _cleanSession || _initialized == 1 )
|
||||||
|
{
|
||||||
|
_topicTbl.clearTopic();
|
||||||
|
_initialized = 0;
|
||||||
|
theClient->onConnect(); // SUBSCRIBEs are conducted
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
_status = GW_CONNECTING;
|
_status = GW_CONNECTING;
|
||||||
@@ -483,3 +490,5 @@ void LGwProxy::setPingReqTimer(void){
|
|||||||
const char* LGwProxy::getClientId(void) {
|
const char* LGwProxy::getClientId(void) {
|
||||||
return _clientId;
|
return _clientId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -88,6 +88,7 @@ private:
|
|||||||
const char* _willTopic;
|
const char* _willTopic;
|
||||||
const char* _willMsg;
|
const char* _willMsg;
|
||||||
uint8_t _cleanSession;
|
uint8_t _cleanSession;
|
||||||
|
uint8_t _initialized;
|
||||||
uint8_t _retainWill;
|
uint8_t _retainWill;
|
||||||
uint8_t _qosWill;
|
uint8_t _qosWill;
|
||||||
uint8_t _gwId;
|
uint8_t _gwId;
|
||||||
|
|||||||
@@ -222,7 +222,7 @@ void LMqttsnClient::setSleepDuration(uint32_t duration)
|
|||||||
|
|
||||||
void LMqttsnClient::onConnect(void)
|
void LMqttsnClient::onConnect(void)
|
||||||
{
|
{
|
||||||
_subMgr.onConnect();
|
_subMgr.onConnect();
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* LMqttsnClient::getClientId(void)
|
const char* LMqttsnClient::getClientId(void)
|
||||||
@@ -230,6 +230,8 @@ const char* LMqttsnClient::getClientId(void)
|
|||||||
return _gwProxy.getClientId();
|
return _gwProxy.getClientId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint16_t LMqttsnClient::getTopicId(const char* topicName)
|
||||||
|
{
|
||||||
|
return _gwProxy.getTopicTable()->getTopicId(topicName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ public:
|
|||||||
void setSleepMode(uint32_t duration);
|
void setSleepMode(uint32_t duration);
|
||||||
void sleep(void);
|
void sleep(void);
|
||||||
const char* getClientId(void);
|
const char* getClientId(void);
|
||||||
|
uint16_t getTopicId(const char* topicName);
|
||||||
LGwProxy* getGwProxy(void);
|
LGwProxy* getGwProxy(void);
|
||||||
LPublishManager* getPublishManager(void);
|
LPublishManager* getPublishManager(void);
|
||||||
LSubscribeManager* getSubscribeManager(void);
|
LSubscribeManager* getSubscribeManager(void);
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ struct LUdpConfig{
|
|||||||
#define MQTTSN_CONFIG MqttsnConfig theMqttsnConfig
|
#define MQTTSN_CONFIG MqttsnConfig theMqttsnConfig
|
||||||
#define NETWORK_CONFIG UdpConfig theNetworkConfig
|
#define NETWORK_CONFIG UdpConfig theNetworkConfig
|
||||||
|
|
||||||
|
#define CONNECT(...) theClient->getGwProxy()->connect(__VA_ARGS__)
|
||||||
#define PUBLISH(...) theClient->publish(__VA_ARGS__)
|
#define PUBLISH(...) theClient->publish(__VA_ARGS__)
|
||||||
#define SUBSCRIBE(...) theClient->subscribe(__VA_ARGS__)
|
#define SUBSCRIBE(...) theClient->subscribe(__VA_ARGS__)
|
||||||
#define UNSUBSCRIBE(...) theClient->unsubscribe(__VA_ARGS__)
|
#define UNSUBSCRIBE(...) theClient->unsubscribe(__VA_ARGS__)
|
||||||
|
|||||||
@@ -441,6 +441,15 @@ PubElement* LPublishManager::add(const char* topicName, uint16_t topicId, uint8_
|
|||||||
elm->status = TOPICID_IS_READY;
|
elm->status = TOPICID_IS_READY;
|
||||||
elm->topicId = topicId;
|
elm->topicId = topicId;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
uint16_t id = theClient->getTopicId(topicName);
|
||||||
|
if ( id )
|
||||||
|
{
|
||||||
|
elm->status = TOPICID_IS_READY;
|
||||||
|
elm->topicId = id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
elm->payloadlen = len;
|
elm->payloadlen = len;
|
||||||
elm->msgId = msgId;
|
elm->msgId = msgId;
|
||||||
|
|||||||
@@ -103,7 +103,7 @@ void ClientRecvTask::run()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* new client */
|
/* new client */
|
||||||
if (packet->getType() == MQTTSN_CONNECT)
|
if (packet->getType() == MQTTSN_CONNECT)
|
||||||
{
|
{
|
||||||
MQTTSNPacket_connectData data;
|
MQTTSNPacket_connectData data;
|
||||||
memset(&data, 0, sizeof(MQTTSNPacket_connectData));
|
memset(&data, 0, sizeof(MQTTSNPacket_connectData));
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ void ClientSendTask::run()
|
|||||||
|
|
||||||
if ( rc < 0 )
|
if ( rc < 0 )
|
||||||
{
|
{
|
||||||
WRITELOG("%s ClientSendTask can't send a packet to the client.\n",
|
WRITELOG("%s ClientSendTask can't send a packet to the client %s%s.\n",
|
||||||
ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), ERRMSG_FOOTER);
|
ERRMSG_HEADER, (client ? (const char*)client->getClientId() : UNKNOWNCL ), ERRMSG_FOOTER);
|
||||||
}
|
}
|
||||||
delete ev;
|
delete ev;
|
||||||
|
|||||||
@@ -234,8 +234,9 @@ void MQTTSNConnectionHandler::handleDisconnect(Client* client, MQTTSNPacket* pac
|
|||||||
|
|
||||||
MQTTSNPacket* snMsg = new MQTTSNPacket();
|
MQTTSNPacket* snMsg = new MQTTSNPacket();
|
||||||
snMsg->setDISCONNECT(0);
|
snMsg->setDISCONNECT(0);
|
||||||
ev->setClientSendEvent(client, snMsg);
|
Event* evt = new Event();
|
||||||
_gateway->getClientSendQue()->post(ev);
|
evt->setClientSendEvent(client, snMsg);
|
||||||
|
_gateway->getClientSendQue()->post(evt);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user