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: https://www.eclipse.org/paho/files/mqttdoc/MQTTClient/html/index.html

I'm stuck, trying to get my head around this C struct https://www.eclipse.org/paho/files/mqttdoc/MQTTClient/html/struct_m_q_t_t_client__connect_options.html

C lib download at https://www.eclipse.org/downloads/download.php?file=/paho/1.4/eclipse-paho-mqtt-c-win32-1.3.0.zip or https://www.eclipse.org/downloads/download.php?file=/paho/1.4/Eclipse-Paho-MQTT-C-1.3.0-Linux.tar.gz

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 
	abort(1) 
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}) 
 
	free(ptr_server_uri) 
	free(ptr_client_id) 
 
	if ret = 0 then 
		return hndl 
	else 
		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() 
display(ver) 

sorry about my bad english

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

Search



Quick Links

User menu

Not signed in.

Misc Menu