One of the main features of an “object” in the Internet of Things world is its ability to exchange messages, sending data or receiving commands, as effectively and efficiently as possible. There are several standard protocols for this purpose but one of my favorites is MQTT.
asynchronous : the requested operation is started asynchronously by returning control to the caller immediately and all notifications are made via callbacks (very useful in the context of software with a UI);
To build this project using Visual Studio 2013, we must use GIT to clone the corresponding repository whose URL is available in the section Downloads -> MQTT -> C / C ++ -> C (Posix / Windows).
In the “Windows Build” folder, we can find the “Paho C MQTT APIs” solution with following projects :
The solution is well structured but unfortunately it is necessary to make a lot of changes to the settings in order to compile the projects on Windows, then move on to execution on the Intel Galileo with "Windows for IoT."
The main changes are needed on test1 project for the above library, since it doesn’t compile immediately due to a number of incorrect settings.
In addition, we must add the following define in C/C++ –> Preprocessor –> Preprocessor Definitions :
At this point, the compiler is able to do its job but the Linker reports a series of "unresolved externals" errors, because it isn’t able to find the symbols relating to the WinSock and the MQTT libraries. In the case of the WinSock library, we have to add the reference to the ws2_32.lib library in Linker -> Input -> Additional Dependencies.
Regarding the MQTT library, we can directly referencing the project (because it is in the same solution) in Common Properties –> References –> Add New Reference.
With these changes the compilation goes successfully but unfortunately if we try to run the test application on our PC, we find ourselves facing a "stack corruption" error. I promptly reported the bug (you can find details here) that with the current version has not yet fixed. The solution consists of a simple change in the file MQTTClient.c (function MQTTClient_deliverMessage) moving the following line of code:
ListRemove(m->c->messageQueue, m->c->messageQueue->first->content);
after #endif and MQTTPersistence_unpersistQueueEntry function call.
1: struct Options
2: {
3: char* connection; /**< connection to system under test. */
4: char** haconnections;
5: int hacount;
6: int verbose;
7: int test_no;
8: int MQTTVersion;
9: int iterations;
10: } options =
11: {
12: "tcp://192.168.10.188:1883",
13: NULL,
14: 0,
15: 0,
16: 0,
17: MQTTVERSION_DEFAULT,
18: 1,
19: };
If everything is set up correctly, the test application will run without any problem.
MQTT on “Windows for IoT”
Upon verification that it works on the PC, we can move on to the configuration of the remote debugging to run the application on the Intel Galileo board directly from Visual Studio; needed settings are available on the official website of Windows On Devices.
Also in this case, launching the application in debug mode you should see all the messages that are exchanged with the board in the mosquitto console .
We have a MQTT client running on it !
If you are curious about the output of the test application, we can see it using a Telnet session directly from the board. After execution, it shows a report with all passed tests.
Obviously, any changes made to projects related to the synchronous library , can also be applied to projects related to asynchronous library with no differences with the guarantees to have the same result.
View this page in another language: