Accessing Tag GPIO status over MQTT

Hi, can somebody please confirm if it is possible to read and write GPIO pins on a tag using the MQTT broker on the RPi?

In other words I want to do the equivalent of the shell commands gs & gc over MQTT.

Thanks in advance for your help.

1 Like

Hi @jdel23

I got this sending user data through MQTT through topic dwm/node/<node_id>/downlink/data as you can see at @leapslabs’ comment on this topic

In the tag’s side I used dwm_gpio_cfg_output to control Led 12 = GPIO 14.

void on_dwm_evt(dwm_evt_t *p_evt)
{
	int len;
	int i;

	switch (p_evt->header.id) {
	...
	...
	case DWM_EVT_USR_DATA_READY:
		len = p_evt->header.len - sizeof(dwm_evt_hdr_t);
		if (len <= 0)
			break;

		printf("iot received, len=%d: ", len);
		for (i = 0; i < len; ++i) {
			if (p_evt->usr_data[i] == 'A')
				dwm_gpio_cfg_output(DWM_GPIO_IDX_14, false);
			else if (p_evt->usr_data[i] == 'B')
				dwm_gpio_cfg_output(DWM_GPIO_IDX_14, true);
			printf("%c", p_evt->usr_data[i]);
		}
		break;
	case ...

This code turn Led ON when you receive a char 'A' and turn it OFF when receive a char 'B'.

I used example dwm-simple project as base to this test.

I’m not sure if it’s possible control GPIO directly through MQTT topics.

BTW I wonder know if there is some doc with all MQTT topics.

Please let us know if you have any further doubt.


Ricardo

1 Like