This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

MQTT_SIMPLE WITH GPIO AND SENSOR

Hello,

Got the MQTT_SIMPLE to work and the sensor samples from zephyr also, however, how can i mix the 2 to have the mqttsimple with some gpio and i2c sensor ? how will the overlay file be changed ?

PLEASE HELP

Thanks

  • Hello, 

    In order to combine two, you will need to combine prj.conf of each sample and ensure that you include any needed header files and its function calls in main.c of e.g. mqtt_simple.

    This means that, based on mqtt_simple combined with bme680, the prj.conf should look similar to:

    #
    # Copyright (c) 2019 Nordic Semiconductor ASA
    #
    # SPDX-License-Identifier: LicenseRef-BSD-5-Clause-Nordic
    #
    
    # Networking
    CONFIG_NETWORKING=y
    CONFIG_NET_NATIVE=n
    CONFIG_NET_SOCKETS_OFFLOAD=y
    CONFIG_NET_SOCKETS=y
    CONFIG_NET_SOCKETS_POSIX_NAMES=y
    
    # LTE link control
    CONFIG_LTE_LINK_CONTROL=y
    CONFIG_LTE_AUTO_INIT_AND_CONNECT=n
    
    # BSD library
    CONFIG_BSD_LIBRARY=y
    
    # AT Host
    CONFIG_UART_INTERRUPT_DRIVEN=y
    CONFIG_AT_HOST_LIBRARY=y
    
    # MQTT
    CONFIG_MQTT_LIB=y
    CONFIG_MQTT_LIB_TLS=n
    
    # Appliaction
    #CONFIG_MQTT_PUB_TOPIC="/my/publish/topic"
    #CONFIG_MQTT_SUB_TOPIC="/my/subscribe/topic"
    #CONFIG_MQTT_CLIENT_ID="my-client-id"
    #CONFIG_MQTT_BROKER_HOSTNAME="mqtt.eclipse.org"
    #CONFIG_MQTT_BROKER_PORT=1883
    
    # Main thread
    CONFIG_MAIN_STACK_SIZE=4096
    
    CONFIG_HEAP_MEM_POOL_SIZE=2048
    
    # From sensor application
    CONFIG_STDOUT_CONSOLE=y
    CONFIG_I2C=y
    CONFIG_SENSOR=y
    CONFIG_BME680=y
    
    # Needed for GPIO
    CONFIG_GPIO=y

    I recommend searching the Kconfig reference to ensure the CONFIG_x setting it correct.

    And main.c of mqtt_simple will need to call whatever the sensor sample calls in its main.c. 

    The board overlay file should look similar to the following, Make sure to use available pins on your board, and pay attention to shared resources

    &i2c1 {
     compatible = "nordic,nrf-twim";
     status = "okay";
     sda-pin = <30>;
     scl-pin = <31>;
    };

    Kind regards,
    Øyvind

  • Have a look at the Thingy:91 DTS file, where you can see how they do it. 

    -Øyvind

  • Thank you for your help
    Will try and let you know

    Thanks

    Regards 

Related