Re: Help me wrap PahoMQTT

new topic     » goto parent     » topic index » view thread      » older message » newer message
xfox26 said...

Can someone help me get this struct on EU code?

First try using a persistent_type of MQTTCLIENT_PERSISTENCE_NONE(=1) and a persistent_context of NULL on the create. The hndl use is also wrong:

--atom xMQTTClient_create = define_c_func(paho_c_dll, "+MQTTClient_create", {C_HANDLE, C_POINTER ,C_POINTER, C_INT, C_POINTER}, C_INT) 
--(^changing the 5th arg to ptr is technically more accurate, but won't make much difference, ditto persistent_type of int below) 
function MQTTClient_create(sequence server_uri, sequence client_id) --, integer persistence_type, atom persistence_context) 
	atom hndl = allocate(4) 
	atom ptr_server_uri = allocate_string(server_uri) 
	atom ptr_client_id = allocate_string(client_id) 
	atom ret = c_func(xMQTTClient_create, {hndl, ptr_server_uri, ptr_client_id, MQTTCLIENT_PERSISTENCE_NONE, NULL}) 
        if ret = MQTTCLIENT_SUCCESS then 
           ret = peek4u(hndl) 
           ret = NULL 
        end if 
	return ret 
end function 

Now, for connect, in I find

typedef struct 
         char struct_id[4]; 
         int struct_version; 
         int keepAliveInterval; 
         int cleansession; 
         int reliable; 
         MQTTClient_willOptions* will; 
         const char* username; 
         const char* password; 
         int connectTimeout; 
         int retryInterval; 
         MQTTClient_SSLOptions* ssl; 
         int serverURIcount; 
         char* const* serverURIs; 
         int MQTTVersion; 
                 const char* serverURI;      
                 int MQTTVersion;      
                 int sessionPresent;   
         } returned; 
                 int len;            
                 const void* data;   
         } binarypwd; 
         int maxInflightMessages; 
          * MQTT V5 clean start flag.  Only clears state at the beginning of the session. 
         int cleanstart; 
 } MQTTClient_connectOptions; 
 #define MQTTClient_connectOptions_initializer { {'M', 'Q', 'T', 'C'}, 6, 60, 1, 1, NULL, NULL, NULL, 30, 0, NULL, 0, NULL, MQTTVERSION_DEFAULT, {NULL, 0, 0}, {0, NULL}, -1, 0} 
 #define MQTTClient_connectOptions_initializer5 { {'M', 'Q', 'T', 'C'}, 6, 60, 0, 1, NULL, NULL, NULL, 30, 0, NULL, 0, NULL, MQTTVERSION_5, {NULL, 0, 0}, {0, NULL}, -1, 1} 
which is what you should really be looking at. It'll be different if you're runing 64 bit, but I'm going to assume you are using 32 bit.
I count 21 4-byte fields, which you need to set as per one of the last two lines, so it goes something like this (untested!):

atom pConnectOptions = allocate(4*21) 

Good luck!

PS: using Phix's cffi might make things somewhat easier, but it would not surprise me if it baulked at the nested "returned" and "binarypwd" structs, if so I'd just delete the containers leaving just the inner fields.

new topic     » goto parent     » topic index » view thread      » older message » newer message


Quick Links

User menu

Not signed in.

Misc Menu