Skip to content

MarcoGeraldi/PicoMqttExample

Repository files navigation

This is an example on how to create an IoT Device with the Raspberry PI Pico WiFi.

In order to be able to build this code, 2 modifications have to be made in order to avoid "PANIC":

  1. The LWIP_NUM_SYS_TIMEOUT has to increased by 1 as mentioned in this thread: raspberrypi/pico-sdk#1281

image

  1. The MQTT_OUTPUT_RINGBUF_SIZE has also to be increased, otherwise a memory execption will be triggered.

    image

How the Code works:

The MQTT library takes care of the basic functionality for the mqtt to work (connect, publish, subscribe, etc.)

The IoT device library gives all the function that enable the user to define and update in a easy way the different entities for home assistant.

In order to configure the Device have first a look in the "IoT_device_confih.h", from here it is possible to configure all the entities details.

image

Then move to the "IoT_device.c", here two functions are defined in order to initialize and update the status of all the entities in home assistant.

The IoT_device_config_pub_init gives the flexibility to instanciate a generic entity, given the proper configuration function as parameter.

In this example 3 voltage sensors and one output switch are being configured.

image

In order to update the status of the entities, customize the "IoT_device_state_update_pub" function, by adding all the entities status by using the functions provided by the parson library

image

In your main function just call the "IoT_device_config_pub_init(mqtt->mqtt_client_inst, mqtt);" upon connection and the "IoT_device_config_pub_init(mqtt->mqtt_client_inst, mqtt);" every time there is need to update the status of the sensors.

image

The configuration of the MQTT broker are defined in the "mqttExample.h" file

When subscribed to a topic, the callback function "mqtt_incoming_data_cb" is called. Here, all the device commands handling done inside the function "IoT_device_cb"

image

image

In this example, the callback will listen to the command topic of the Output 1 entity, and will change its status according to the command

image

The device output in home assistant will be the following

image

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published