Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for MQTT client #256

Merged
merged 44 commits into from Sep 26, 2018
Merged

Conversation

tbeu
Copy link
Collaborator

@tbeu tbeu commented Aug 29, 2018

Tested with MSVC and GCC on Linux.

TODO:

I did not spent time on setting up a local MQTT broker, thus the example works on some public test broker. This might be changed some day.

Close #130

@tbeu tbeu added this to the v1.6.0 milestone Aug 29, 2018
@tbeu
Copy link
Collaborator Author

tbeu commented Aug 30, 2018

Hm, the 32-bit test at Travis CI should display linux-generic32 as platform, but also builds/runs the 64-bit binaries: https://travis-ci.org/modelica/Modelica_DeviceDrivers/jobs/422593836#L1186 Thus, there is something wrong in general with the 32-bit configuration for Travis CI.

@tbeu tbeu force-pushed the mqtt branch 4 times, most recently from 084ae10 to 9524f72 Compare August 30, 2018 18:58
@tbeu
Copy link
Collaborator Author

tbeu commented Aug 30, 2018

32-bit CMake cross compilation does not work at Travis CI, but I have no more ideas what and how to fix.

https://travis-ci.org/modelica/Modelica_DeviceDrivers/jobs/422716533#L807

@tbeu
Copy link
Collaborator Author

tbeu commented Aug 30, 2018

I believe it is same issue as http://cmake.3232098.n2.nabble.com/CMAKE-SIZEOF-VOID-P-question-td7595355.html.

Cross-compilation will only work by use of artificial environment variable. See https://github.com/eclipse/paho.mqtt.c/blob/4b355d1fd48c13f47fc663af4001ff23aa9d3e5a/test/CMakeLists.txt#L21-L26 for an example.

@tbeu tbeu force-pushed the mqtt branch 5 times, most recently from eb72928 to 0b74706 Compare September 2, 2018 10:03
@tbeu
Copy link
Collaborator Author

tbeu commented Sep 2, 2018

4d33f14 fixes the cross-compilation issue with CMake at Travis CI in master.

tbeu and others added 11 commits September 24, 2018 18:40
Built at drone.io (https://drone.io/github.com/tbeu/paho.mqtt.c/files) with custom Makefile:

```
AR = ar -ru
RM = rm -f

CFLAGS = -O3
CPPFLAGS = -DNDEBUG
INC =

TARGETDIR = linux64

# The names of the four different libraries to be built
MQTTLIB_C = paho-mqtt3c
MQTTLIB_CS = paho-mqtt3cs
MQTTLIB_A = paho-mqtt3a
MQTTLIB_AS = paho-mqtt3as

MQTT3A_OBJS = \
	Clients.o \
	Heap.o \
	LinkedList.o \
	Log.o \
	Messages.o \
	MQTTAsync.o \
	MQTTPacket.o \
	MQTTPacketOut.o \
	MQTTPersistence.o \
	MQTTPersistenceDefault.o \
	MQTTProtocolClient.o \
	MQTTProtocolOut.o \
	Socket.o \
	SocketBuffer.o \
	StackTrace.o \
	Thread.o \
	Tree.o \
	utf-8.o

MQTT3C_OBJS = \
	Clients.o \
	Heap.o \
	LinkedList.o \
	Log.o \
	Messages.o \
	MQTTClient.o \
	MQTTPacket.o \
	MQTTPacketOut.o \
	MQTTPersistence.o \
	MQTTPersistenceDefault.o \
	MQTTProtocolClient.o \
	MQTTProtocolOut.o \
	Socket.o \
	SocketBuffer.o \
	StackTrace.o \
	Thread.o \
	Tree.o \
	utf-8.o

ALL_OBJS = $(MQTT3A_OBJS) $(MQTT3C_OBJS)

TS := $(shell /bin/date -u)

all: clean versioninfo lib$(MQTTLIB_A).a lib$(MQTTLIB_C).a

versioninfo:
	@echo "#ifndef VERSIONINFO_H" > src/VersionInfo.h
	@echo "#define VERSIONINFO_H" >> src/VersionInfo.h
	@echo "#define BUILD_TIMESTAMP \""$(TS)"\"" >> src/VersionInfo.h
	@echo "#define CLIENT_VERSION \"1.1.0\""  >> src/VersionInfo.h
	@echo "#endif /* VERSIONINFO_H */" >> src/VersionInfo.h

lib$(MQTTLIB_A).a: $(MQTT3A_OBJS)
	$(AR) $@ $(MQTT3A_OBJS)
	cp $@ Library/$(TARGETDIR)/$@

lib$(MQTTLIB_C).a: $(MQTT3C_OBJS)
	$(AR) $@ $(MQTT3C_OBJS)
	cp $@ Library/$(TARGETDIR)/$@

%.o: src/%.c
	$(CC) $(CPPFLAGS) $(CFLAGS) $(INC) -c -o $@ $<

clean:
	$(RM) $(ALL_OBJS)
	$(RM) *.a
```
…or Windows

Built with Visual Studio 2010 (/MD flag)
[ci skip]
Copy link
Collaborator

@bernhard-thiele bernhard-thiele left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It took a bit of testing and some email exchange to get an understanding of this PR. It now works fine in Windows and Linux and will be cool new feature for the next release. I will squash it and merge it.

As discussed using email, the new library dependencies should be managed in a more transparent way so that it is not too difficult to reproduce the builds. However, this can be improved later. Particularly, building the OpenSSL libraries is a bit inconvenient and I like your idea of replacing that dependency by mbedTLS in the future (if possible).

I have experimented with adapting the cmake files, so that the library dependencies can be built as external projects. This is not complete, yet. I think I should do a more general revision of the cmake build system before. That's future work.

Below is what I understand about the library dependencies. We could document this at some place in the project, e.g., below the ../Resources/Libraries folder. Finally, I hope that we/I can adapt the cmake files, so that the libraries can be built by cmake (and thus a simple reproducible build becomes possible at some point in the future).

@bernhard-thiele bernhard-thiele merged commit 057b979 into modelica-3rdparty:master Sep 26, 2018
@tbeu tbeu deleted the mqtt branch September 26, 2018 16:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

2 participants