Help me wrap PahoMQTT

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

Hi, I have some personal IOT projects, like a "smart" fridge to make homebrew beer, and decided to do an upgrade on my code, had the idea to add mqtt as the communication protocol.

I have limited knoledge of C, but decided to try to wrap pahomqtt library, documented here:

I'm stuck, trying to get my head around this C struct

C lib download at or

Can someone help me get this struct on EU code?

My wrapper so far:

include std/dll.e 
include std/machine.e 
include std/console.e 
atom paho_c_dll = open_dll("paho-mqtt3c.dll") 
if paho_c_dll <= 0 then 
end if 
atom xMQTTClient_getVersionInfo = define_c_func(paho_c_dll, "+MQTTClient_getVersionInfo",{}, C_POINTER) 
atom xMQTTClient_create = define_c_func(paho_c_dll, "+MQTTClient_create", {C_HANDLE, C_POINTER ,C_POINTER, C_INT, C_INT}, C_INT) 
atom xMQTTClient_connect = define_c_func(paho_c_dll, "+MQTTClient_connect", {C_HANDLE, C_POINTER}, C_INT) 
function MQTTClient_getVersionInfo() 
	atom ret = c_func(xMQTTClient_getVersionInfo, {}) 
	sequence ptrs = peek4u({ret,2}) 
	return {peek_string(ptrs[1]),peek_string(ptrs[2])} 
end function 
function MQTTClient_create(sequence server_uri, sequence client_id, atom 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 ,persistence_type, persistence_context}) 
	if ret = 0 then 
		return hndl 
		return ret 
	end if 
end function 
function MQTTClient_connect(atom hndl) 
	--where madness hit me 
	atom MQTTClient_connectOptions 
	MQTTClient_connectOptions = 0 
	return c_func(xMQTTClient_connect, {hndl, MQTTClient_connectOptions}) 
end function 
--versioninfo works ;) 
sequence ver =  MQTTClient_getVersionInfo() 

sorry about my bad english

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


Quick Links

User menu

Not signed in.

Misc Menu