Hi,
I want to use the MQTT Mosquitto library, which is written in C, on my FXT009.
The library has been linked and added as it should, as you can see in the output. (Ofc I’m not 100% sure it is correct as it isn’t working)
I have the lates DS on my Win7 64bit
As of now, this is my code
#include "adl_global.h"
#include "wip_net.h"
#include "wip_bearer.h"
#include <stdio.h>
#include <mosquitto.h>
#include <string.h>
/***************************************************************************/
/* prototypes */
/***************************************************************************/
void MainTask ( void );
/************************************************************************************/
/* Task table definition of tasks entry point, stack size, task name, task priority */
/************************************************************************************/
const adl_InitTasks_t adl_InitTasks [ ] = {
{ MainTask, 4096, "WipSoft", 1 },
{ 0, 0, 0, 0 }
};
wip_bearer_t myBearer = NULL;
s8 ret = 0;
void my_message_callback(struct mosquitto *mosq, void *userdata, const struct mosquitto_message *message)
{
TRACE((1,"GOT SOMETHING"));
TRACE((1, message->payload));
}
void my_connect_callback(struct mosquitto *mosq, void *userdata, int result)
{
if(!result){
/* Subscribe to broker information topics on successful connect. */
mosquitto_subscribe(mosq, NULL, "/broker/mferno/test", 0);
}else{
TRACE((1,"Connect failed\n"));
}
}
void my_subscribe_callback(struct mosquitto *mosq, void *userdata, int mid, int qos_count, const int *granted_qos)
{
int i;
TRACE((1,"Subscribed (mid: %d): %d", mid, granted_qos[0]));
for(i=1; i<qos_count; i++){
TRACE((1,", %d", granted_qos[i]));
}
}
void my_log_callback(struct mosquitto *mosq, void *userdata, int level, const char *str)
{
/* Pring all log messages regardless of level. */
TRACE((1, str));
}
void connectToBroker(){
char id[30];
char *host = "test.mosquitto.org";
int port = 1883;
int keepalive = 60;
bool clean_session = true;
struct mosquitto *mosq = NULL;
mosquitto_lib_init();
mosq = mosquitto_new(id, clean_session, NULL);
if(!mosq){
TRACE((1, "OUT OF MEMORY"));
}
mosquitto_log_callback_set(mosq, my_log_callback);
mosquitto_connect_callback_set(mosq, my_connect_callback);
mosquitto_message_callback_set(mosq, my_message_callback);
mosquitto_subscribe_callback_set(mosq, my_subscribe_callback);
if(mosquitto_connect(mosq, host, port, keepalive)){
TRACE((1,"Unable to connect"));
}
while(!mosquitto_loop(mosq, -1, 1)){
}
mosquitto_destroy(mosq);
mosquitto_lib_cleanup();
}
void bearerHandler(wip_bearer_t bearer, s8 event, void *context){
switch(event){
case WIP_BEV_IP_CONNECTED: {
TRACE (( 1, "bearerHandler: <WIP_BEV_IP_CONNECTED>"));
//Connect to broker
connectToBroker();
break;
}
case WIP_BEV_CONN_FAILED: {
TRACE (( 1, "bearerHandler: <WIP_BEV_CONN_FAILED>"));
break;
}
case WIP_BEV_STOPPED: {
TRACE (( 1, "bearerHandler: <WIP_BEV_STOPPED>"));
break;
}
default: {
TRACE (( 1, "bearerHandler: <DEFAULT>"));
break;
}
}
}
void simHandler (u8 event){
switch(event){
case ADL_SIM_EVENT_FULL_INIT:{
TRACE((1, "ADL_SIM_EVENT_FULL_INIT"));
ret = wip_bearerOpen(&myBearer, "GPRS", bearerHandler, NULL);
TRACE((1,"OPEN BEARER: %d",ret));
ret = wip_bearerSetOpts(myBearer,
WIP_BOPT_GPRS_APN, "machinetohuman.ts.m2m",
WIP_BOPT_LOGIN, "",
WIP_BOPT_PASSWORD, "",
WIP_BOPT_END);
TRACE((1,"SET OPTS: %d",ret));
ret = wip_bearerStart(myBearer);
TRACE((1, "START: %d", ret));
break;
}
default: {
TRACE((1, "IN DEFAULT"));
break;
}
}
}
void MainTask ( void ) {
TRACE((1,"IN MAIN"));
adl_simSubscribe((adl_simHdlr_f) simHandler, NULL);
wip_netInit();
}
And the output to the console is this
11:31:14 **** Incremental Build of configuration [Target]_ARM_EABI_GCC_Debug for project MosquittoClient ****
Info: Internal Builder is used for build
"C:\\Program Files (x86)\\Sierra Wireless\\Developer Studio\\tools\\armeabigcc\\4.4.1\\bin\\arm-none-eabi-g++.exe" -Wl,--script,gcc.lkopt "src\\generated.o" "src\\appli.o" -lethernet_driver -lmosquitto -Wl,-( -nostartfiles "-LC:\\workspace\\ethernet_driver\\[Target]_ARM_EABI_GCC_Debug" "-LC:\\workspace\\MosquittoClient\\mosquitto-1.1.3\\lib" -Os -O2 -fshort-enums -fdollars-in-identifiers -ggdb3 -u _siwiStubsImplementation -fomit-frame-pointer -mthumb-interwork -mthumb -march=armv5te -msoft-float -mfpu=fpa -mapcs -mno-apcs-stack-check -Wl,-nmagic -Wl,-Map,MosquittoClient.map "C:\\Program Files (x86)\\Sierra Wireless\\Embedded Software\\com.wavecom.openat.ide.spm.lib.os.model.6.51.0.201206010944_6.51.0.201206010944\\resources\\ADL\\RVDS_ADL.lib" "C:\\Program Files (x86)\\Sierra Wireless\\Embedded Software\\com.wavecom.openat.ide.spm.lib.plugin.model.WIP.5.54.0.201206011257_5.54.0.201206011257\\resources\\WIP\\RVDS_WIP.lib" "C:\\Program Files (x86)\\Sierra Wireless\\Embedded Software\\com.wavecom.openat.ide.spm.lib.plugin.model.WIP.5.54.0.201206011257_5.54.0.201206011257\\resources\\WIP\\RVDS_WIPSoftLib.lib" -Wl,-) -oMosquittoClient.axf
src\appli.o: In function `connectToBroker':
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:72: undefined reference to `mosquitto_lib_init'
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:74: undefined reference to `mosquitto_new'
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:79: undefined reference to `mosquitto_log_callback_set'
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:80: undefined reference to `mosquitto_connect_callback_set'
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:81: undefined reference to `mosquitto_message_callback_set'
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:82: undefined reference to `mosquitto_subscribe_callback_set'
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:84: undefined reference to `mosquitto_connect'
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:88: undefined reference to `mosquitto_loop'
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:91: undefined reference to `mosquitto_destroy'
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:92: undefined reference to `mosquitto_lib_cleanup'
src\appli.o: In function `my_connect_callback':
C:\workspace\MosquittoClient\[Target]_ARM_EABI_GCC_Debug/..\src/appli.c:40: undefined reference to `mosquitto_subscribe'
collect2: ld returned 1 exit status
11:31:14 Build Finished (took 284ms)
I have no idea how to go from here and am in desperate need of help.
Best regards