by lzanardo » Thu May 23, 2024 12:54 pm
#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