Hello goodnight.
Is there any way to connect MQTT
because I already tried:
* hbamqp
* paho-mqtt3c.dll
exempl:
conn_opts := "{'M', 'Q', 'T', 'C'}, 8, 60, 1, 1, NULL, NULL, NULL, 30, 0, NULL,"
conn_opts += "0, NULL, 0, {NULL, 0, 0}, {0, NULL}, -1, 0, NULL, NULL, NULL"
DllCall( hHandle, DLL_OSAPI, "MQTTClient_connect", @hHandle, Conn_Opts )
No connect
Help?
Att.
lZanardo - Brazil
MQTT xHarbour
- Antonio Linares
- Site Admin
- Posts: 42273
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: MQTT xHarbour
Dear Izanardo,
This is an example of use:
This is an example of use:
Code: Select all | Expand
#include "MQTTClient.h"
int main() {
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
conn_opts.keepAliveInterval = 20; // tiempo de keep alive en segundos
conn_opts.cleansession = 1; // limpiar sesión al conectar
int rc = MQTTClient_connect(client, "tcp://localhost:1883", &conn_opts);
if (rc!= MQTTCLIENT_SUCCESS) {
printf("Error al conectar: %d\n", rc);
return 1;
}
if (MQTTClient_isConnected(client)) {
printf("Conectado correctamente al broker MQTT\n");
} else {
printf("Error al conectar al broker MQTT\n");
return 1;
}
// Realiza operaciones MQTT aquí (publicar, suscribir, recibir mensajes, etc.)
// Cerrar la conexión cuando termines
MQTTClient_disconnect(client);
return 0;
}
- Antonio Linares
- Site Admin
- Posts: 42273
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Contact:
Re: MQTT xHarbour
Code: Select all | Expand
#pragma BEGINDUMP
#include "hbapi.h"
#include "MQTTClient.h"
HB_FUNC( MQTTCONNECT )
{
MQTTClient client;
MQTTClient_connectOptions conn_opts = MQTTClient_connectOptions_initializer;
int rc;
conn_opts.keepAliveInterval = 20; // tiempo de keep alive en segundos
conn_opts.cleansession = 1; // limpiar sesión al conectar
rc = MQTTClient_connect(client, "tcp://localhost:1883", &conn_opts);
if (rc!= MQTTCLIENT_SUCCESS)
hb_retc( "Error al conectar: " + hb_ntos( rc ) );
else
{
if (MQTTClient_isConnected(client))
hb_retc( "Conectado correctamente al broker MQTT" );
else
hb_retc( "Error al conectar al broker MQTT" );
}
}
#pragma ENDDUMP
- albeiroval
- Posts: 383
- Joined: Tue Oct 16, 2007 5:51 pm
- Location: Barquisimeto - Venezuela
Re: MQTT xHarbour
Hola IZanardo, donde encuentro los DLL para probar el MQTTlzanardo wrote:Hello goodnight.
Is there any way to connect MQTT
because I already tried:
* hbamqp
* paho-mqtt3c.dll
exempl:
conn_opts := "{'M', 'Q', 'T', 'C'}, 8, 60, 1, 1, NULL, NULL, NULL, 30, 0, NULL,"
conn_opts += "0, NULL, 0, {NULL, 0, 0}, {0, NULL}, -1, 0, NULL, NULL, NULL"
DllCall( hHandle, DLL_OSAPI, "MQTTClient_connect", @hHandle, Conn_Opts )
No connect
Help?
Att.
lZanardo - Brazil
- albeiroval
- Posts: 383
- Joined: Tue Oct 16, 2007 5:51 pm
- Location: Barquisimeto - Venezuela
Re: MQTT xHarbour
lZanardo,
Gracias por compatirlo.
Gracias por compatirlo.
Re: MQTT xHarbour
#Include "WPRAMQTT.CH"
#DEFINE MQTTLIB "paho-mqtt3c.dll"
#DEFINE DLL_OSAPI 0x0020 // __stdcall
#DEFINE NULL Nil
Static nHandle
Static ConnLost , MsgArrvd, Delivered
Function WPRA101_MQTT()
Local nResult
if !file( MQTTLIB )
Vt_Aviso("Arquivo " + MQTTLIB + " não localizado...",.T.)
Return( Nil )
Endif
nHandle := 0
cAddress := "tcp:localhost:1883"
cClientID := "teste"
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_create", @nHandle, cAddress , cClientID, MQTTCLIENT_PERSISTENCE_NONE )
if nResult != MQTTCLIENT_SUCCESS
? "MQTTClient_create:", nResult
Vt_Aviso("Erro ao criar objeto acesso",.T.) // <- Function View
Return( Nil )
Endif
ConnLost := HB_String2Pointer("fConnLost()")
MsgArrvd := Nil
Delivered:= 0
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_setCallbacks", nHandle, @ConnLost , @MsgArrvd , @Delivered )
if nResult != MQTTCLIENT_SUCCESS
? "MQTTClient_setCallbacks", nResult
Vt_Aviso("Erro ao criar modo multithread. " + lZA_Zero( nResult, 10, .F. ) ,.T.)
quit
Return( Nil )
Endif
cTopicLen := "cTopicLen"
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_receive", nHandle, cClientID, 1 , 3, 10000) //, @cBuffer,,100) //, , conn_opts, 0 )
? nResult, cClientID, ConnLost
conn_opts := "'M', 'Q', 'T', 'C'" , 0, 20, 1, 1, NULL, NULL, NULL, 30, 0, NULL,"
conn_opts += "0, NULL, 0, {NULL, 0, 0}, {0, NULL}, -1, 0, NULL, NULL, NULL"
conn_opts := HB_String2Pointer( conn_opts )
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_connect", @nHandle , conn_opts , 0)
? "nResult", nResult
Return( Nil )
Function fConnLost()
? "#### fConnLost() ####"
Return( 0 )
Function fMsgArrvd() ; Return( 1 )
Estou neste ponto poren não consigo receber dados mosquitto.exe
Skype: lfzanardo
att.
LZanardo
#DEFINE MQTTLIB "paho-mqtt3c.dll"
#DEFINE DLL_OSAPI 0x0020 // __stdcall
#DEFINE NULL Nil
Static nHandle
Static ConnLost , MsgArrvd, Delivered
Function WPRA101_MQTT()
Local nResult
if !file( MQTTLIB )
Vt_Aviso("Arquivo " + MQTTLIB + " não localizado...",.T.)
Return( Nil )
Endif
nHandle := 0
cAddress := "tcp:localhost:1883"
cClientID := "teste"
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_create", @nHandle, cAddress , cClientID, MQTTCLIENT_PERSISTENCE_NONE )
if nResult != MQTTCLIENT_SUCCESS
? "MQTTClient_create:", nResult
Vt_Aviso("Erro ao criar objeto acesso",.T.) // <- Function View
Return( Nil )
Endif
ConnLost := HB_String2Pointer("fConnLost()")
MsgArrvd := Nil
Delivered:= 0
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_setCallbacks", nHandle, @ConnLost , @MsgArrvd , @Delivered )
if nResult != MQTTCLIENT_SUCCESS
? "MQTTClient_setCallbacks", nResult
Vt_Aviso("Erro ao criar modo multithread. " + lZA_Zero( nResult, 10, .F. ) ,.T.)
quit
Return( Nil )
Endif
cTopicLen := "cTopicLen"
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_receive", nHandle, cClientID, 1 , 3, 10000) //, @cBuffer,,100) //, , conn_opts, 0 )
? nResult, cClientID, ConnLost
conn_opts := "'M', 'Q', 'T', 'C'" , 0, 20, 1, 1, NULL, NULL, NULL, 30, 0, NULL,"
conn_opts += "0, NULL, 0, {NULL, 0, 0}, {0, NULL}, -1, 0, NULL, NULL, NULL"
conn_opts := HB_String2Pointer( conn_opts )
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_connect", @nHandle , conn_opts , 0)
? "nResult", nResult
Return( Nil )
Function fConnLost()
? "#### fConnLost() ####"
Return( 0 )
Function fMsgArrvd() ; Return( 1 )
Estou neste ponto poren não consigo receber dados mosquitto.exe
Skype: lfzanardo
att.
LZanardo
Re: MQTT xHarbour
Intenta asi, no tengo completo, sin eso no és posible probar.
Regards, saludos.
Code: Select all | Expand
#include "FiveWin.ch"
#Include "WPRAMQTT.CH" // no tengo, donde tien?
// #DEFINE MQTTLIB "paho-mqtt3c.dll"
#DEFINE DLL_OSAPI 0x0020 // __stdcall
#DEFINE NULL Nil
STATIC nHandle
STATIC ConnLost, MsgArrvd, Delivered
STATIC cDll := "C:\MQTT\MQTT.DLL" // Renombre
FUNCTION Main()
LOCAL nResult, hDll
IF FILE( "C:\MQTT\MQTT.DLL" )
hDll := LoadLibrary( cDll )
ELSE
? "Que pasa con el MQTT.DLL?"
RETURN NIL
ENDIF
/*
IF !File( MQTTLIB )
Vt_Aviso( "Arquivo " + MQTTLIB + " não localizado...", .T. )
Return( NIL )
ENDIF
*/
nHandle := 0
cAddress := "tcp:localhost:1883"
cClientID := "teste"
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_create", @nHandle, cAddress, cClientID, MQTTCLIENT_PERSISTENCE_NONE )
IF nResult != MQTTCLIENT_SUCCESS
? "MQTTClient_create:", nResult
//Vt_Aviso( "Erro ao criar objeto acesso", .T. ) // <- Function View
MsgInfo( "Erro ao criar objeto acesso", "Erro ao criar objeto acesso" )
FreeLibrary( hDll )
RETURN NIL
ENDIF
ConnLost := HB_String2Pointer( "fConnLost()" )
MsgArrvd := Nil
Delivered := 0
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_setCallbacks", nHandle, @ConnLost, @MsgArrvd, @Delivered )
IF nResult != MQTTCLIENT_SUCCESS
? "MQTTClient_setCallbacks", nResult
// Vt_Aviso( "Erro ao criar modo multithread. " + lZA_Zero( nResult, 10, .F. ), .T. )
MsgInfo( "Erro ao criar modo multithread", "Erro ao criar modo multithread" )
FreeLibrary( hDll )
QUIT
RETURN NIL
ENDIF
cTopicLen := "cTopicLen"
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_receive", nHandle, cClientID, 1, 3, 10000 ) // , @cBuffer,,100) //, , conn_opts, 0 )
? nResult, cClientID, ConnLost
conn_opts := "'M', 'Q', 'T', 'C'", 0, 20, 1, 1, NULL, NULL, NULL, 30, 0, NULL, "
conn_opts += "0, NULL, 0, {NULL, 0, 0}, {0, NULL}, -1, 0, NULL, NULL, NULL"
conn_opts := HB_String2Pointer( conn_opts )
nResult := DllCall( MQTTLIB, DLL_OSAPI, "MQTTClient_connect", @nHandle, conn_opts, 0 )
? "nResult", nResult
RETURN NIL
FUNCTION fConnLost()
? "#### fConnLost() ####"
RETURN( 0 )
FUNCTION fMsgArrvd() ; Return( 1 )
// FIN / END
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341