Skip to content

Commit

Permalink
Add Bluetooth classic as a sensor network #69, #195, #90
Browse files Browse the repository at this point in the history
I think the architecture of the ble sensor network, which does not use
threads per socket, can be applied to DTLS.

Known bug:
Occasionally a timeout error occurs when connecting to RFCOMM.
BLE is not supported yet. I need help to do it.



Signed-off-by: tomoaki <tomoaki@tomy-tech.com>
  • Loading branch information
ty4tw committed Jun 2, 2021
1 parent 982e6d4 commit 44afcef
Show file tree
Hide file tree
Showing 52 changed files with 1,791 additions and 963 deletions.
18 changes: 12 additions & 6 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,13 @@

<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="gnu.cpp.link.option.libs.1848275182" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" useByScannerDiscovery="false" valueType="libs">

<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="pthread"/>
<listOptionValue builtIn="false" value="pthread"/>

<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="ssl"/>
<listOptionValue builtIn="false" value="ssl"/>

<listOptionValue builtIn="false" srcPrefixMapping="" srcRootPath="" value="crypto"/>
<listOptionValue builtIn="false" value="crypto"/>

<listOptionValue builtIn="false" value="bluetooth"/>

</option>

Expand Down Expand Up @@ -133,7 +135,11 @@

<sourceEntries>

<entry excluding="MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples/ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/ClientSub|MQTTSNGateway/GatewayTester/samples/ClientPub|MQTTSNGateway/src/linux/udp6|MQTTSNGateway/src/linux/loralink|MQTTSNClient|MQTTSNGateway/src/MQTTSNGWProxy.cpp|MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/src/linux/xbee|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|MQTTSNGateway/src/tests|MQTTSNGateway/src/tests/mainTestProcessFramework.cpp|ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
<entry excluding="src/linux/ble|src/mainLogmonitor.cpp|src/linux/xbee|src/linux/udp6|src/linux/loralink|src/tests|GatewayTester|GatewayTester/samples|GatewayTester/src" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway"/>

<entry excluding="samples|src" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNGateway/GatewayTester"/>

<entry excluding="samples|test" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket"/>

</sourceEntries>

Expand Down Expand Up @@ -273,9 +279,9 @@

<sourceEntries>

<entry excluding="MQTTSNGateway/GatewayTester|MQTTSNGateway/GatewayTester/samples/ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/ClientSub|MQTTSNGateway/GatewayTester/samples/ClientPub|MQTTSNGateway/src/tests/mainTestProcess.cpp|MQTTSNGateway/src/linux|MQTTSNPacket/src|MQTTSNClient|MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|ClientPubQoS-1" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>
<entry excluding="MQTTSNGateway|MQTTSNGateway/GatewayTester|MQTTSNGateway/src|MQTTSNGateway/GatewayTester/samples/ClientPubQoS-1|MQTTSNGateway/GatewayTester/samples/ClientSub|MQTTSNGateway/GatewayTester/samples/ClientPub|MQTTSNGateway/src/tests/mainTestProcess.cpp|MQTTSNGateway/src/linux|MQTTSNPacket/src|MQTTSNClient|MQTTSNPacket/test|MQTTSNPacket/samples|MQTTSNGateway/GatewayTester/samples/mainOTA.cpp|MQTTSNGateway/src/mainLogmonitor.cpp|MQTTSNGateway/GatewayTester/samples/mainTemplate.cpp|ClientPubQoS-1" flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name=""/>

<entry excluding="udp6|xbee|loralink" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTTSNGateway/src/linux"/>
<entry excluding="linux/ble" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="MQTTSNGateway/src"/>

<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="MQTTSNPacket/src"/>

Expand Down
4 changes: 2 additions & 2 deletions .settings/language.settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>

<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-152861151764916298" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-152611677936340298" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">

<language-scope id="org.eclipse.cdt.core.gcc"/>

Expand All @@ -33,7 +33,7 @@

<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>

<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-152861151764916298" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="-152611677936340298" id="org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">

<language-scope id="org.eclipse.cdt.core.gcc"/>

Expand Down
3 changes: 2 additions & 1 deletion MQTTSNGateway/GatewayTester/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ CPPSRCS := \
$(SUBDIR)/LGwProxy.cpp \
$(SUBDIR)/LMqttsnClient.cpp \
$(SUBDIR)/LNetworkUdp.cpp \
$(SUBDIR)/LNetworkBle.cpp \
$(SUBDIR)/LPublishManager.cpp \
$(SUBDIR)/LRegisterManager.cpp \
$(SUBDIR)/LSubscribeManager.cpp \
Expand All @@ -41,7 +42,7 @@ DEFS :=
LIBS +=
LDFLAGS :=
CXXFLAGS := -Wall -O3 -std=c++11
LDADD :=
LDADD := -lbluetooth
OUTDIR := Build

PROG := $(OUTDIR)/$(PROGTEST)
Expand Down
64 changes: 39 additions & 25 deletions MQTTSNGateway/GatewayTester/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
###Gateway Test Program.
# Gateway Test Program.
**sample/mainTest.cpp** is a Test sample coading.
Each test is described as one function. test1(), test2()...
````
```
/*------------------------------------------------------
* Test functions
*
Expand All @@ -25,37 +25,51 @@ Each test is described as one function. test1(), test2()...
void test1(void)
{
char payload[300];
sprintf(payload, "ESP8266-08b133 ");
uint8_t qos = 0;
PUBLISH(topic1,(uint8_t*)payload, strlen(payload), qos);
char payload[300];
sprintf(payload, "ESP8266-08b133 ");
uint8_t qos = 0;
PUBLISH(topic1,(uint8_t*)payload, strlen(payload), qos);
}
void test2(void)
{
uint8_t qos = 1;
SUBSCRIBE(topic2, on_publish02, qos);
uint8_t qos = 1;
SUBSCRIBE(topic2, on_publish02, qos);
}
````
```
**TEST_LIST** is a test senario. Test functions are executed one by one.
````
```
/*------------------------------------------------------
* A List of Test Tasks
*------------------------------------------------------*/
TEST_LIST = {// e.g. TEST( Label, Test),
TEST("Publish topic1", test1),
TEST("Subscribe topic2", test2),
TEST("Publish topic2", test3),
TEST("Unsubscribe topic2", test4),
TEST("Publish topic2", test3),
TEST("Disconnect", test5),
END_OF_TEST_LIST
};
````

### **step1. Build **
````
TEST("Publish topic1", test1),
TEST("Subscribe topic2", test2),
TEST("Publish topic2", test3),
TEST("Unsubscribe topic2", test4),
TEST("Publish topic2", test3),
TEST("Disconnect", test5),
END_OF_TEST_LIST
};
```
## step1. Define a sensor network

**UDP** or **Bluetooth** is available as a sensor network.
Uncomment a line \#define UDP or BLE in LMqttsnClientApp.h file.
```
/*======================================
* Program mode Flag
======================================*/
//#define CLIENT_MODE
#define UDP
//#define BLE
```

## step2. Build
```
$ git clone https://github.com/eclipse/paho.mqtt-sn.embedded-c
$ cd paho.mqtt-sn.embedded-c/MQTTSNGateway/GatewayTester
$ make
Expand All @@ -65,9 +79,9 @@ $ make clean
MQTT-SNGatewayTester program is copied into ../../../ directory.


### **step2. Execute Gateway Tester.**
## **step3. Execute Gateway Tester.**

````
```
$ cd ../../..
$ ./MQTT-SNGatewayTester
Expand Down Expand Up @@ -116,4 +130,4 @@ recved 192.168.11.17 :10000 08 13 20 00 01 00 01 00
Execute Publish topic1 Test ? ( Y/N ) :
````
```
8 changes: 8 additions & 0 deletions MQTTSNGateway/GatewayTester/samples/ClientPub/mainPub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ UDPCONF = {
20010, // Local PortNo
};

/*------------------------------------------------------
* BLE Configuration (theNetcon)
*------------------------------------------------------*/
BLECONF = { "GatewayTestClient", // ClientId
{ 0x60, 0x57, 0x18, 0x06, 0x8b, 0x72 }, // GW Address
1, // Rfcomm channel
};

/*------------------------------------------------------
* Client Configuration (theMqcon)
*------------------------------------------------------*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ UDPCONF = {
20001, // Local PortNo
};

/*------------------------------------------------------
* BLE Configuration (theNetcon)
*------------------------------------------------------*/
BLECONF = { "GatewayTestClient", // ClientId
{ 0x60, 0x57, 0x18, 0x06, 0x8b, 0x72 }, // GW Address
1, // Rfcomm channel
};

/*------------------------------------------------------
* Client Configuration (theMqcon)
*------------------------------------------------------*/
Expand Down
8 changes: 8 additions & 0 deletions MQTTSNGateway/GatewayTester/samples/ClientSub/mainSub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ UDPCONF = {
20011, // Local PortNo
};

/*------------------------------------------------------
* BLE Configuration (theNetcon)
*------------------------------------------------------*/
BLECONF = { "GatewayTestClient", // ClientId
{ 0x44, 0x1C, 0xA8, 0x16, 0x94, 0x94 }, // GW Address
1, // Rfcomm channel
};

/*------------------------------------------------------
* Client Configuration (theMqcon)
*------------------------------------------------------*/
Expand Down
34 changes: 20 additions & 14 deletions MQTTSNGateway/GatewayTester/samples/mainTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,31 @@ extern LScreen* theScreen;
/*------------------------------------------------------
* UDP Configuration (theNetcon)
*------------------------------------------------------*/
UDPCONF =
{ "GatewayTestClient", // ClientId
UDPCONF = { "GatewayTestClient", // ClientId
{ 225, 1, 1, 1 }, // Multicast group IP
1883, // Multicast group Port
20020, // Local PortNo
};
1883, // Multicast group Port
20020, // Local PortNo
};

/*------------------------------------------------------
* BLE Configuration (theNetcon)
*------------------------------------------------------*/
BLECONF = { "GatewayTestClient", // ClientId
{ 0x60, 0x57, 0x18, 0x06, 0x8b, 0x72 }, // GW Address
1, // Rfcomm channel
};

/*------------------------------------------------------
* Client Configuration (theMqcon)
*------------------------------------------------------*/
MQTTSNCONF =
{ 60, //KeepAlive [seconds]
true, //Clean session
300, //Sleep duration [seconds]
"", //WillTopic
"", //WillMessage
0, //WillQos
false //WillRetain
};
MQTTSNCONF = { 60, //KeepAlive [seconds]
true, //Clean session
300, //Sleep duration [seconds]
"", //WillTopic
"", //WillMessage
0, //WillQos
false //WillRetain
};

/*------------------------------------------------------
* Define Topics
Expand Down
8 changes: 7 additions & 1 deletion MQTTSNGateway/GatewayTester/src/LGwProxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ LGwProxy::~LGwProxy()
_topicTbl.clearTopic();
}

void LGwProxy::initialize(LUdpConfig netconf, LMqttsnConfig mqconf)
void LGwProxy::initialize(SENSORNET_CONFIG_t netconf, LMqttsnConfig mqconf)
{
_network.initialize(netconf);
_clientId = netconf.clientId;
Expand All @@ -87,6 +87,12 @@ void LGwProxy::connect()
{
pos = _msg;

if (!_network.isBroadcastable() && _status == GW_LOST)
{
_status = GW_CONNECTING;
continue;
}

if (_status == GW_LOST)
{

Expand Down
3 changes: 2 additions & 1 deletion MQTTSNGateway/GatewayTester/src/LGwProxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "LMqttsnClientApp.h"
#include "LNetworkUdp.h"
#include "LNetworkBle.h"
#include "LRegisterManager.h"
#include "LTimer.h"
#include "LTopicTable.h"
Expand Down Expand Up @@ -54,7 +55,7 @@ class LGwProxy{
LGwProxy();
~LGwProxy();

void initialize(LUdpConfig netconf, LMqttsnConfig mqconf);
void initialize(SENSORNET_CONFIG_t netconf, LMqttsnConfig mqconf);
void connect(void);
void disconnect(uint16_t sec = 0);
int getMessage(void);
Expand Down
13 changes: 10 additions & 3 deletions MQTTSNGateway/GatewayTester/src/LMqttsnClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ extern TaskList theTaskList[];
extern TestList theTestList[];
extern OnPublishList theOnPublishList[];
extern MQTTSNCONF;
extern UDPCONF;
extern SENSORNET_CONFIG_t theNetcon;
extern void setup(void);

/*=====================================
Expand All @@ -50,7 +50,14 @@ int main(int argc, char** argv)
#ifndef CLIENT_MODE
char c = 0;
printf("\n%s", PAHO_COPYRIGHT4);
printf("\n%s\n", PAHO_COPYRIGHT0);
printf("\n%s", PAHO_COPYRIGHT0);
#if defined(UDP)
printf(" UDP\n");
#elif defined(BLE)
printf(" BLE\n");
#else
printf("\n");
#endif
printf("%s\n", PAHO_COPYRIGHT1);
printf("%s\n", PAHO_COPYRIGHT2);
printf(" *\n%s\n", PAHO_COPYRIGHT3);
Expand Down Expand Up @@ -108,7 +115,7 @@ LMqttsnClient::~LMqttsnClient()

}

void LMqttsnClient::initialize(LUdpConfig netconf, LMqttsnConfig mqconf)
void LMqttsnClient::initialize(SENSORNET_CONFIG_t netconf, LMqttsnConfig mqconf)
{
_gwProxy.initialize(netconf, mqconf);
setSleepDuration(mqconf.sleepDuration);
Expand Down
2 changes: 1 addition & 1 deletion MQTTSNGateway/GatewayTester/src/LMqttsnClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class LMqttsnClient{
void unsubscribe(const char* topicName);
void unsubscribe(const uint16_t topicId);
void disconnect(uint16_t sleepInSecs);
void initialize(LUdpConfig netconf, LMqttsnConfig mqconf);
void initialize(SENSORNET_CONFIG_t netconf, LMqttsnConfig mqconf);
void run(void);
void addTask(bool test);
void setSleepDuration(uint32_t duration);
Expand Down
Loading

0 comments on commit 44afcef

Please # to comment.